COP2258 QUIZ 4

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

Given char ch; int num; double pay; Which of the following assignment statements are valid? (i) ch = '*'; (ii) pay = num * pay; (iii) rate * 40 = pay;

(i) and (ii) are valid

What is i printed? public class Test { public static void main(String[] args) { int j = 1; int i = ++j + j * 5; System.out.println("What is i? " + i); } }

12

What is x after the following code? public class Test { public static void main(String[] args) { int x = 3; x *= x + 5; System.out.println("x is " + x); } }

24

The value of the expression 5 + 10 % 4 - 3 is ____.

4

What is y displayed in the following code? public class Test { public static void main(String[] args) { int x = 3; int y = x++ + x; System.out.println("y is " + y); } }

7

Suppose x = 4 and y = 2. If the statement x *= y; is executed once, what is the value of x?

8

The expression (double)(5 + 4) evaluates to ____.

9.0

Consider the following program. // Insertion Point 1 public class CircleArea { // Insertion Point 2 static final float PI = 3.14 public static void main(String[]args) { //Insertion Point 3 float r = 2.0; float area; area = PI * r * r; System.out.println("Area = " + area); } // Insertion Point 4 } In the above code, where do the import statements belong?

Insertion point 1

Are the following four statements equivalent? number += 1; number = number +1; number++; ++number;

True

Suppose that alpha and beta are int variables. The statement alpha = --beta; is equivalent to the statement(s) ____.

beta = beta - 1; alpha = beta;

An identifier can be any sequence of characters and integers.

false

If ++x is used in an expression, first the expression is evaluated, and then the value of x is incremented by 1.

false

Consider the following program. public class CircleArea { static Scanner console = new Scanner(System.in); static final float PI = 3.14; public static void main(String[]args) { float r; float area; r = console.nextDouble(); area = PI * r * r; System.out.println("Area = " + area); } } To successfully compile this program, which of the following import statement is required?

import java.util;

Suppose x = 18.6. The output of the statement System.out.println((int)(x) / 3); is 6.

true


Kaugnay na mga set ng pag-aaral

Melissa Flemming video how to help refugees rebuild their world

View Set

N3511 Extra Questions Substance Abuse, Eating disorders and Impulse control disorders

View Set

Chapter 4: Reactions in Aqueous Solutions

View Set

Chapter 43: Loss, Grief, and Dying

View Set