Question: Review for my final somebody help me 1) Convert 258 from decimal to binary. 100000010 2) Convert 258 from decimal to hexadecimal. 102 3) Convert

Review for my final somebody help me

1) Convert 258 from decimal to binary. 100000010

2) Convert 258 from decimal to hexadecimal. 102

3) Convert 1AB from hexadecimal to binary. 110101011

4) Convert 1AB from hexadecinal to decimal 427

5) What gets printed?

int x = 0, y = 0;

while (x < 2) {

y += x++;

}

System.out.println(y);

1

6) The RGB format is used to specify colors for electronic systems, by specifying the amount of red, green and blue in a color. The amounts for each color range from 0 to 255. Specify in hex, the RGB value for RGB(254, 99, 18) RGB(FE, 63, 12);

7) What is the smallest value that can be stored in a variable of type long?

a. 0

b. -264

c. (264 - 1)

d. -263

e. (263 - 1)

f. -232

g. (232 - 1)

h. -231

i. (231 - 1)

longs has 64 bits, so there are 264 possible values, half for <0 263 and half for>= 0 263, so the largest is 263 -1

8) // What gets printed?

int x = 0, y = 0;

do {

y += x++;

} while (x < 2);

System.out.println(y);

1

9) How many bits are used to store a double value in Java?

64

10) Which of the following lines are comments?

1 // x = x++;

2 x = x++;

3 /* x = x++;

4 x = x++;

5 x = x++; */

6 x = x++;

1) ________ double TAX_RATE = 8.75;

which is required to make TAX_RATE a constant?

a. const

b. CONST

c. constant

d. CONSTANT

e. final

f. FINAL

2) Which of the following is valid?

a. boolean b = true;

b. boolean b = True;

c. boolean b = 1;

d. Boolean b = true;

e. Boolean b = True;

f. Boolean b = 1;

Note case

3) What value will x have?

int x = 4 * 3 % 2;

0

4) What value will x have?

double x = 2 + 8 / 7 % 3 / 2; 2.0

note integer arithmetic

5) What value will x have?

double x = 2 + 8 / 7 % 3 / 2d; 2.5

6) What is the value of z?

int x = 5, y =2;

float z

z = x / y; 2.0

7) What is the value of x?

int x = 5, y =2;

float z

z = x / (float) y; 2.5

What is the value of x?

int x = 5, y =2;

float z

z = x / (float) y; compiler error: cant put double in float

8) What is the value of x?

int x = 5;

x %= 2; 1

Consider the following start of a method definition:

public static void main (String args[]) {

9) How many arguments does this method take?

a. 0 b. 1 c. 2 d. 3 e.4

10) What is the return type of this method?

a. public

b. int

c. static

d. main

e. String

f. It does not return any value

11) What type of method is it?

a. Instance

b. Class

c. Constant

d. Accessor

e. Mutator

12) What is the name of the method?

a. public

b. int

c. static

d. main

e. String

f. It does not have a name

13) What is the access modifier of this method?

a. public

b. int

c. static

d. main

e. String

f. It does not return any value

14) Create an instance of the Complex Class. new

Complex complex = ___________ Complex (3, 4);

15) An instance method called square, takes no arguments and returns the complex number squared. Call the method here.

Use the instance of the Complex created in the previous question. complex.square();

Complex complexSquared = ______________;

16) What is the name of the package in the following statement? java.util

import java.util.Scanner;

17) What is the name of the package in the following statement?

import java.util.Scanner;

18) Consider the method declaration:

Fraction static Fraction max (Fraction x, Fraction y) {

Which of the following have the same signature? (Select all correct answers)

a. static fraction max (Fraction x, Fraction y) {

b. static Fraction max (Fraction x, Fraction y) {

c. static Fraction max (fraction x, fraction y) {

d. static double max (Fraction x, Fraction z) {

e. static Fraction max (Fraction x, Fraction y, Fraction z) {

f. static Fraction max (Fraction x, double y) {

g. static Franction max (fraction x, fraction y) {

h. static Fraction max (Fraction a, Fraction b) {

The signature of a method is determined by the name of the method and the types, number and order of the parameters.

so the signature in this example is (max, Fraction, Fraction)

watch out for case

19) Given:

Random rand = new Random();int x = (rand.nextInt(7) + 1)/2;

What are the possible values of x? (select all possible answers)

a. -1

b. 0

c. 1

d. 2

e. 3

f. 4

rand.nextInt(n) returns 0 to n-1, note integer arithmetic

20) What gets printed?

System.out.println ("Python \\\"\' \\\\ Java");

Python \"'

\\ Java

\\ prints as \

\ prints as

\prints as

means a new line

21) What is the value of c?

String s = "abcdefgh";

char c = s.charAt(s.length() - s.indexOf("b") );

h

s.length() is 8, s.indexOf(b) is 1 start counting at 0

22) String s = abcdefgh;

int x = s.indexOf(F);

what is the value of x?

-1

Note case, -1 means not found

23) String s = abcdefgh;

String t = s.substring(2,4);

What is the value of t?

cd

substring(x,y) returns the string starting at position x and going up to, but not including position y

24) String s = abcdefgh;

String t = s.substring(2);What is the value of t?

cdefgh

substring(x) returns the string starting at position x, and continuing till the end of the string

25) int x = 17;

char result = 'a';

if (x > 10)

if (x > 20) result = 'b';

else

if (x > 30) result = 'c';

else result = 'd';

what value will result have?

d

note that each else matches the closest un-matched if, preceding it

26) a || b && c && !(b && !c)

for which values does the above expression evaluate to true?

a. a = false, b = false, c = false

b. a = false, b = false, c = true

c. a = false, b = true, c = false

d. a = false, b = true, c = true

e. a = true, b = false, c = false

f. a = true, b = false, c = true

g. a = true, b = true, c = false

h. a = true, b = true, c = true

27) !(!a || b && c) || a && !b

for which values does the above expression evaluate to true?

a. a = false, b = false, c = false

b. a = false, b = false, c = true

c. a = false, b = true, c = false

d. a = false, b = true, c = true

e. a = true, b = false, c = false

f. a = true, b = false, c = true

g. a = true, b = true, c = false

h. a = true, b = true, c = true

28) int x = 1, z = 2;

int y = (x == 0) ? (z > 0 ? 1 : 2) : (z > 0 ? 3 : z < 0 ? 4 : 5);

what value will y have?

3

The conditional operator takes the form (condition) ? true-part : false-part

it will return the true-part if the condition is true, and the false-part if the condition is false.

true-part or false-part can be replaced by another conditional operator, which facilitates nesting of conditional operators

29) int x = 2, z = 0;

int y = (x == 0) ? (z > 0 ? 1 : 2) : (z > 0 ? 3 : z < 0 ? 4 : 5);

what value will y have?

5

30) int x = 2;

switch (x) {

case 1: System.out.print("1");

case 2: System.out.print("2");

case 3: System.out.print("3");

case 4: System.out.print("4");

default: System.out.print("5");

}

2345

note that the switch statement starts at the first matching case, and stops at the next break, or until the end of the switch statement

31) int x = 1;

for (int i = 1 ; i <= 5; i+=2) { x *= i; }

what is the value of x? 15

32) int x = 0;

for (int i = 0; i <= 4; i++)

for (int j = 0; j <= 3; j++)

x++;

what value will x have? 20

The outter loop iterates 5 times. For each of these iterations, the inner loop iterates 4 times. 5*4 = 20

33) int x = 0;

for (int i = 0; i < 4; ++i)

for (int j = 0; j < 3; ++j)

x++;

what value will x have? 12

The outter loop iterates 4 times. For each of these iterations, the inner loop iterates 3 times. 4*3 = 12

private double digit;

private long exponent;

public Scientific (double digit, long exponent) {

this.digit = digit;

this.exponent = exponent;

normalize();

}

public void normalize() {

while (Math.abs(digit) >= 10) {

exponent++;

digit /= 10;

}

while (Math.abs(digit) < 1) {

exponent--;

digit *= 10;

}

}

34) The code above is inside the Scientific class, what will the value of exponent be in s1 after the following statement?

Scientific s1 = new Scientific(20, 2); 3

The first loop in normalize(), executes once, reducing digit from 20 to 2 and increasing exponent from 2 to 3

35) Which keyword allows the method normalize() to be accessed outside of the class? public

36) Which keyword specifies that a method has no return value? void

37) System.out.println(s1 + " \u00f7 " + s2 + " = " + s1.divide(s2));

what is the purpose of " \u00f7 "?

a. Display the hexadecimal number f7 as decimal

b. Display the hexadecimal number f7 as binary

c. Specify the precision of s1

d. Specify the precision of s2

e. Display

Unicode characters can be specified in strings using the format \unnnn, where nnnn is the

4-digit hex value of the uniccode character

public class MinMax {

private int min, max;

private String name;

public float middle() { return ((float)min+max)/2; }

private static int Min = Integer.MAX_VALUE, Max = Integer.MIN_VALUE;

public static float classMiddle() { return ((float)Min+Max)/2; }

public MinMax(int min, int max, String name) {

this.min = min;

this.max = max;

this.name = name;

Min = (min < Min) ? min : Min;

Max = (max > Max) ? max : Max;

}

public static MinMax createMinMax(String prompt) {

1) Which if the following might be a valid syntax?

a. MinMax mm = new MinMax( 3, 3, first);

b. MinMax mm = new MinMax( 3, 3);

c. MinMax mm = new MinMax( 3.1, 3, first);

d. MinMax mm = new MinMax( );

e. MinMax mm = MinMax( 3, 3, first);

f. MinMax mm = MinMax( 3, 3);

g. MinMax mm = MinMax( 3.1, 3, first);

MinMax is a constructor (same name as the class) so it requires the new keyword. The constructor has the argument list (int, int, String). The default constructor takes no arguments, but is hidden as soon as we write any constructor

1) After statement (39) is executed, which of the following might be valid syntax?

a. MinMax mm2 = mm.createMinMax(second);

b. MinMax mm2 = mm.createMinMax();

c. MinMax mm2 = new mm.createMinMax(second);

d. MinMax mm2 = new mm.createMinMax();

e. MinMax mm2 = MinMax.createMinMax();

f. MinMax mm2 = MinMax.createMinMax(second);

createMinMax is a class method because it is preceded by the keyword static, class methods are generally called using the class name, in this case MinMax, but can also less commonly be preceded by an object reference, in this case mm,

1) Which variable of the MinMax class belongs to the entire class and not an individual instance?

a. int

b. String

c. Min

d. Float

e. Middle

Min is preceded by the keyword static, making it a class method. Class methods belong to the entire class and not individual instances of the class.

1) JavaFX is meant to replace which technology?

a. Applets

b. AWT

c. Swing

d. Java Beans

e. Bytecode

Swing replaced AWT

52) int[] x = {2, 4, 6, 8, 10};

int y = x[x.length - 2];

what is the value of x? 8

x.length is 5 y is assigned x[3]. Arrays start at 0

53) int[] x = new int[x];

what is the value of x?

0

the default value for numerics is 0, for Strings and other objects it is null, for boolean it is false, for char it is \u0000

54) public static void f1 (int a, int b)

{

int temp = a;

b = a;

a = temp;

}

int x = 1, y = 2;

f1(x, y);

What is the value of x after this code?1

values are copied when the method call is made, so no changes are made to them.

55) int[] arr = {1, 2, 3, 4};

f1(arr[1], arr[3]);

// what is the value of arr[1] after this code?

2

values are copied when the method call is made, so no changes are made to them.

56) public static void f2 (int arr[])

{

if (arr.length > 3)

{

int temp = arr[1];

arr[1] = arr[3];

arr[3] = temp;

}

}

int[] arr = {1, 2, 3, 4};

f2(arr);

what is the value of arr[1] after this code?

4

The method swaps the values of a[1] and a[3]. Because the contents of the array are not copied when calling the method, just the reference to the array is

57)public static void f3 (int arr1[], int arr2[])

{

int[] arr3 = new int[arr1.length];

arr3 = arr1;

arr1 = arr2;

arr2 = arr3;

}

int[] x = {1, 2, 3, 4};

Int[] y = {5, 6, 7, 8};

f3(x, y);

// what is the value of x[1] after this code?

2

The method is swapping the arrays, not their contents

58) What is the value of the boolean expression?

int[] y = {5, 6, 7, 8};

int[] z = {5, 6, 7, 8};

(y == z)

false

while the contents of the arrays are the same, their references x and y, point to different locations. They are 2 separate arrays, which just happen to have the same contents. == compares the two values to see if they point to the same array (same applies to object references)

59) Consider

public enum Days {Sun, Mon, Tue, Wed, Thur, Fri, Sat};

System.out.println(Days.Fri);

// what gets printed?

Fri

60) What is the the value of Days.Tue.ordinal() ? 2

Sun = 0, Mon = 1 etc.

61) Which code is required to print the integer value?

System.out.println(Days.valueOf("Fri").ordinal());

Days.valueOf("Fri") returns Days.Fri

62) try {

int year = Integer.parseInt(scan.nextLine());

}

catch (Exception e)

{

System.out.println(Please enter an integer);

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!