1). The result of Java expression 5*7>3*(5+2) &&
3*5-4<6 is ____
a. 35>35&&9<6
b. true && false
c. false
d. False
(2). You save text files containing Java language source code
using the file extension___
a. .java
b. .class
c. .txt
d. .src
(3). Which of the following is not a primitive data type in the
Java programming language?
a. boolean
b. byte
c. int
d. Point
(4). Given the Java statement int[][] vari = new int[5][7]; the
value of vari[4].length is
a. 4
b. 5
c. 6
d. 7
(5). To use any of the prewritten classes besides those in the
java.lang package, you must___
a. use the entire path with the class name
b. import the class
c. import the package of which the class you are using is a
part
d. use any of these methods
(6). Assuming x = 25, y = -1, z = 32, the expression !( x / 2 ==
12 ) || ( z*3 == 96 ); gives ___
a. False
b. true
c. false
d. True
(7). Given String str1 = “Java is useful!”; Statement
System.out.println(str1.charAt(14)); displays ___
a. 14
b. !
c. l
d. error message
(8). Given a static method public static void swap(int x, int y){
int temp = x; x = y; y = temp; }, if x=3, y=5; then the value of x
and y after the method call swap(x,y) is_____;
a. 3, 5
b. 5, 3
c. 3, 3
d. 5, 5
(9). A class header must contain___
a. an access modifier
b. the keyword class
c. the keyword static
d. the keyword public
(10). Which of the following expression refers the last element
of array arr?
a. arr[last]
b. arr[arr.length]
c. arr[arr.length – 1]
d. arr[end]
(11). Given Java statement int[] arr = new int[10]; the last
element is___
a. 10
b. arr[10]
c. arr[9]
d. arr[0]
(12). Given Java statement Random rand = new Random( ); which of
the following Java statements will
generate a random integer between 2 and 5 is
a. rand.nextInt(4)+2;
b. rand.nextInt(5) +2;
c. rand.nextInt(6) +2;
d. rand.nextInt(2,5);
(13). You can declare two variables with the same name as long
as___
a. they appear within the same block
b. they are assigned different values
c. they are of different types
d. their scopes do not overlap
(14). Given Java statement int[] arr = new int[10]; the
statement System.out.println(arr) gives__
a. 10
b. 9
c. compiler error
d. The memory location where array arr is stored.
(15). If str is a String, ______ gives the total number of
characters in the string str.
a. str.length
b. str.length()
c. str
d. str[]
ANSWER:-
1) A) 5*7>3*(5+2) && 3*5-4<6
3*7 = 35
3*(5+2) = 21
therefore, 35 > 21 = true
3*5-4 == 11
therefore, 11 < 6 = true
true && true = true
SO, ANSWER is true.
2) .java
3) Point is not a primitive data type. It is a class
4) ANSWER is 7. Because vari[4].length gives no of columns in that row.
5) c. import the package of which the class you are using is a part
6) !( x / 2 == 12 ) || ( z*3 == 96 );
Explanation:- x = 25
x/2 = 25/2 = 12
(x/2 == 12) = true
!(x/2 == 12) = false
z = 32
(96 == 96) = true
!( x / 2 == 12 ) || ( z*3 == 96 ) = false || true = true
ANSWER is true.
7) ANSWER is !. because string length is 15. and indices are in range 0 to 14. and 14th index is !.
8) 5, 3
9) b) the keyword static
10) c. arr[arr.length – 1]
11) arr[9]
12) rand.nextInt(4)+2; rand.nextInt(n) generates random numbers in range 0 to n-1
13) their scopes do not overlap
14) The memory location where array arr is stored.
15) str.length()
NOTE:- If you have any doubts,please comment below.Please give positive rating.THUMBS UP.
THANK YOU!!!!
1). The result of Java expression 5*7>3*(5+2) && 3*5-4<6 is ____ a. 35>35&&9<6 b. true &&...
Consider the following code segment. int[]arr={1, 2, 3, 4, 5, 6, 7, 8}; for(int k=3; k<arr.length-1; R++ arr[k]-arr[k+1]; What are the contents of arr as a result of executing the code segment? a. {1, 2, 3, 5, 6, 7, 8, 8) b. {2, 2, 4, 5, 6, 7, 8, 8} C. {2, 4, 6, 5, 6, 7, 8,8} d. {4, 2, 4, 4, 6, 7, 8, 8) e. {6, 6, 4, 5, 6, 7, 8, 8} int) arr={7, 2.5, 3.0,...
10. Which of the following correcthy milites elements each with value 0? super Bass to com I inttl superBass { 0, 0, 0, 0, 0 ); int(1 superBass = new int [5] inttl superBass = new int (5) for (int i = 0; i < super Bass.length superBass ) = 0; +) (A) (B) I only II only I and II only I and III only I. II, and III (D) (E) 17. Consider the following Java program public class...
Question 1 An array is NOT: A - Made up of different data types. B - Subscripted by integers. C - A consecutive group of memory chunks. D - None of the choices. Question 2 How many times is the body of the loop executed? int i=1; while(true) { cout << i; if(++i==5) break; } A - Forever B - 4 C - 5 D - 6 E - 0 Question 3 What is wrong with the following piece of...
Problems 9-35 odd numbers only(9,11,13,15 …35)
k newNum numi (int) (4.6/2)1 . Do a walk-through to find the value assigned to e. Assume that all variables are properly declared. a -31 es" (a%b) * 6; e-(a b+ d)/ 4 10. Which of the following variable declarations are correct? If'a variable declaration is not correct, give the reasoníy) and provide the correct variable declaration. n = 12; char letter int one = 5, two; //Line 3 double x, Y zi //tine...
A. What is the value of the following statement? Math.pow(6, 3) B. For the following code: String sentence; String str; sentence = "First exam is on Monday."; str = sentence.replace('s', '$'); C. What type of input does the following program require, and in what order must the input be provided? import java.util.*; public class Strange { static Scanner console = new Scanner(System.in); public static void main(String[] arg) { int x; int y; String name; x = console.nextInt(); name = console.nextLine();...
this
is java
4. (2 point each) What value will be assigned to the "answer" variable below? If the expression will not compile in Java, explain why. Write your answer on the line to the right. a. boolean answer = 6 < 2 || 7 > 3; b. boolean answer = true && false; c. boolean answer = ! (87 == 80); d. boolean answer = true > false; e. String name = "Daniel" ; boolean answer = ! (name.equals("Charles"));...
I need a java program that prints the following: 1* 2** 3*** 4**** 5***** 6****** 7******* 8******** 9********* This is what I have so far, but I cannot figure out how to fix it. public class HelloWorld{ public static void main(String []args){ System.out.println("Pattern Two"); for (int line=1; line<10; line++){ System.out.println(); for (int j=1; j System.out.print(line); for (int i=1; i System.out.print("*"); } } } } }
Consider the following method. public static ArrayList<Integer mystery(int n) ArrayList<Integer seg - new ArrayList<IntegerO; for (int k = n; k > 0; k--) seq.add(new Integer(k+3)); return seq What is the final output of the following Java statement? System.out.println(mystery(3)); a. [1,2,4,5) b. [2,3,4,5) c. [6,5,4,3] d. [7, 7, 8, 8] e. [7,8,9, 8) O Consider the following method: public static int mystery(int[] arr, int k) ifk-0) return 0; }else{ return arr[k - 1] + mystery(arr, k-1):) The code segment below is...
Provide the expected output AS IT WOULD APPEAR IN A JAVA PROGRAM as the result of a print statement. (i.e. Enter true or false (all lower case letters). If you enter TRUE, F, True, etc these will be marked wrong). Given the following declarations: int x = 25; int y = -4; int z = 17; boolean b = false; What would be the output of the following Boolean expressions? (x % 2 != 0) && b b && !b...
I need to program 3 and add to program 2 bellows: Add the merge sort and quick sort to program 2 and do the same timings, now with all 5 sorts and a 100,000 element array. Display the timing results from the sorts. DO NOT display the array. ____________________>>>>>>>>>>>>>>>>>>>>___________________________ (This is program 2 code that I did : ) ---->>>>>> code bellow from program 2 java program - Algorithms Write a program that randomly generates 100,000 integers into an array....