Question

With a Scanner object created as follows, what method do you use to read an int...

With a Scanner object created as follows, what method do you use to read an int value?

Scanner input = new Scanner(System.in);

A.

input.int();

B.

input.nextInt();

C.

input.integer();

D.

input.nextInteger();

What is the output of the following code?

x = 0;
if (x > 0)
System.out.println("x is greater than 0");
else if (x < 0)
System.out.println("x is less than 0");
else
System.out.println("x equals 0");

A.

x is greater than 0

B.

x is less than 0

C.

x equals 0

D.

None

The following loop displays ________.

for (int i = 1; i <= 10; i++) {
System.out.print(i + " ");
i++
}

A.

1 3 5 7 9

B.

1 2 3 4 5

C.

1 2 3 4 5 6 7 8 9 10

D.

1 2 3 4 5 6 7 8 9

The main method header is written as ________.

A.

public static void Main(String[] args)

B.

public static void main(String[] args)

C.

public static void main(string[] args)

D.

public void main(String[] args)

What is y after the following switch statement is executed?

int x = 3; int y = 4;
switch(x + 3) {
case 6: y = 0;
case 7: y = 1;
default: y += 1;
}

A.

0

B.

4

C.

1

D.

2

Which of the following is the best for generating random integer 0 or 1?

A.

(int)(Math.random() + 0.5)

B.

(int)Math.random()

C.

(int)(Math.random() + 0.2)

D.

(int)Math.random() + 1

What is the printout of the following code?

double x = 5.5;
int y = (int)x;
System.out.println("x is " + x + " and y is " + y);

A.

x is 6 and y is 6

B.

x is 5.5 and y is 5.0

C.

x is 5.5 and y is 5

D.

x is 6.0 and y is 6.0

Math.pow(2, 3) returns ________.

A.

9.0

B.

8

C.

9

D.

8.0

What is the printout of the following code:

double x = 10.1;
int y = (int)x;
System.out.println("x is " + x + " and y is " + y);

A.

x is 10.1 and y is 10.0

B.

x is 10 and y is 10

C.

x is 10.1 and y is 10

D.

x is 10.0 and y is 10.0

Analyze the following code:

if (x < 100) && (x > 10)
System.out.println("x is between 10 and 100");

A.

The statement has compile errors because (x < 100) && (x > 10) must be enclosed inside parentheses.

B.

The statement has compile errors because (x < 100) && (x > 10) must be enclosed inside parentheses and the println(...) statement must be put inside a block.

C.

The statement compiles fine, but has a runtime error.

D.

The statement compiles fine.

What is the value in count after the following loop is executed?

int count = 0;
do {
System.out.println("Welcome to Java");
} while (count++ < 9);

A.

10

B.

11

C.

0

D.

9

Which of the following operators has the highest precedence?

A.

*

B.

/

C.

+

D.

casting

The not equal comparison operator in Java is ________.

A.

^=

B.

<>

C.

!=

D.

!= =

Suppose x = 1, y = -1, and z = 1. What is the printout of the following code?

if (x < 0)
if (y < 0)
System.out. println("x < 0 and y < 0");
else if (z < 0)
System.out. println("x < 0 and z < 0");

else

System.out. println("x < 0 and z > 0");

A.

x > 0 and y > 0;

B.

x < 0 and z > 0;

C.

x < 0 and z < 0;

D.

no printout.

Suppose the input for number is 9. What is the output from running the following program?

import java. util.Scanner;
public class Test {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter an integer: ");
int number = input. nextInt():
int i;
boolean isPrime = true;
for (i = 2; i < number && isPrime; i++) {
if (number % i == 0)
isPrime = false;
}
System.out. println("i is " + i);

System.out. println(number + " is" ( isPrime ? "" : " not") + " prime");
}

A.

i is 3 followed by 9 is prime

B.

i is 3 followed by 9 is not prime

C.

i is 4 followed by 9 is prime

D.

i is 4 followed by 9 is not prime

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Dear Student ,

As per the requirement submitted above , kindly find the below solution.

Question 1 :

Answer : B.input.nextInt();

Explanation :Here a new program with name "main.java" is created which contains following code

************************

Question 2 :

Answer :c.x equals 0

Explanation :Here a new program with name main.java is created which contains following code

main.java :

************************

Question 3 :

Answer :A.1 3 5 7 9

Explanation :Here value of i is incremented with for loop and in the loop body after printing value of i hence the answer.

************************

Question 4 :

Answer :B.public static void main(String[] args)

Explanation :in method name m should be small and S should be capital.Kindly refer above screens.

**************************

Question 5 :

Answer :D.2

Explanation :Here to the switch x+3 is passed hence case 6 will be executed x=0 but no break is given after each case hence case 7 and default case will execute.Hence y=2.Refer below screen

************************

Question 7 :

Answer :c.x is 5.5 and y is 5

Explanation :Here x is of double type and x is parsed into int and assigned to integer y hence y=5.Refer below screen

**************************

Question 8 :

Answer :D.8.0

Explanation :Refer below screen

******************************

Question 9 :

Answer :c.x is 10.1 and y is 10

Explanation :Here x is of double type and y is of int type.Kindly refer below screen

****************************

Question 10 :

Answer :A.The statement has compile errors because (x < 100) && (x > 10) must be enclosed inside parentheses.

Explanation :

*******************

Question 11 :

Answer :A.10

Explanation :Here a program with name "main.java" is created which contains following code

***************************

Question :

Answer :C.!=

Explanation :The not equal comparison operator in Java is !=

**************************

Question :

Answer :D.i is 4 followed by 9 is not prime

Explanation :

NOTE : PLEASE FEEL FREE TO PROVIDE FEEDBACK ABOUT THE SOLUTION

Add a comment
Know the answer?
Add Answer to:
With a Scanner object created as follows, what method do you use to read an int...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • what is output public static void main(String args) Scanner keyboard new Scanner(System.in); int u 14; int...

    what is output public static void main(String args) Scanner keyboard new Scanner(System.in); int u 14; int w 0; int x; int y 5; float z = 6.1 System.out.print("Enter y: "); x keyboard.nextint); System.out.println('y'); System.out.println(x); System.out.println(w*3); x- x+(int)z; System.out.println(x); 0 System.out.println(u); System.out.,println(u); System.out.println"x In" + y); System.out.print(y + z); ) liclosing main method 1 liclosing class header

  • Which of the following are valid array declarations? a. int[] array- new int[10]; b. double [array...

    Which of the following are valid array declarations? a. int[] array- new int[10]; b. double [array double[10]; c. charl charArray "Computer Science"; None of the above Analyze the following code: class Test public static void main(Stringl] args) System.out.println(xMethod(10); public static int xMethod(int n) System.out.println("int"); return n; public static long xMethod(long n) System.out.,println("long"); return n The program displays int followed by 10 The program displays long followed by 10. The program does not compile. None of the above. tions 3-4 are...

  • (a)How many times does the code snippet given below display "Hello"? int x = 1; while...

    (a)How many times does the code snippet given below display "Hello"? int x = 1; while (x != 15) {    System.out.println ("Hello");    x++; } (b)What is the output of the following code fragment? int i = 1; int sum = 0; while (i <= 5) {    sum = sum + i;    i++; } System.out.println("The value of sum is " + sum); Quie 2 What is the output of the following snipped code? public class Test {...

  • 2. Write a counter controlled loop to solve the following problems. Each one will involve an...

    2. Write a counter controlled loop to solve the following problems. Each one will involve an array (MinMax.java) Read in 25 ints from the keyboard, and store them in an array. Then, find the maximum and minimum values in such an array, and display them on the screen. public class Array-Assignment { public static void main(String [] args) {     int [] x = new int[3];     int [] y = {3, 5, 9, 2};     x[2] = y[3];    ...

  • import java.util.Scanner; public class SCAN { public static void main(String[ ] args) { int x, y,...

    import java.util.Scanner; public class SCAN { public static void main(String[ ] args) { int x, y, z; double average; Scanner scan = new Scanner(System.in); System.out.println("Enter an integer value"); x = scan.nextInt( ); System.out.println("Enter another integer value"); y = scan.nextInt( ); System.out.println("Enter a third integer value"); z = scan.nextInt( ); average = (x + y + z) / 3; System.out.println("The result of my calculation is " + average); } } What is output if x = 0, y = 1 and...

  • please evaluate the following code. this is JAVA a. class Car { public int i =...

    please evaluate the following code. this is JAVA a. class Car { public int i = 3; public Car(int i) { this.i = i; } } ... Car x = new Car(7), y = new Car(5); x = y; y.i = 9; System.out.println(x.i); b. class Driver { public static void main(String[] args) { int[] x = {5, 2, 3, 6, 5}; int n = x.length; for (int j = n-2; j > 0; j--) x[j] = x[j-1]; for (int j...

  • 5. Write a static method "f(n)" in the space provide, that returns O if n is...

    5. Write a static method "f(n)" in the space provide, that returns O if n is even, and if n is odd, returns 1 or -1 according as n is greater than or less than 0. importjava.util.Scanner; public class Q_05 Your "f(n)" method: public static void main(String args[]) mana int n; Scanner input = new Scanner(System.in); System.out.print("Please enetrn: "); n=input.nextInt(); System.out.println(f(n)); "Method f(n)" 7. Write a static method "max" in the space provide, that returns the maximum value from 3...

  • Create a method based program to find if a number is prime and then print all...

    Create a method based program to find if a number is prime and then print all the prime numbers from 1 through 500 Method Name: isPrime(int num) and returns a boolean Use for loop to capture all the prime numbers (1 through 500) Create a file to add the list of prime numbers Working Files: public class IsPrimeMethod {    public static void main(String[] args)    {       String input;        // To hold keyboard input       String message;      // Message...

  • public static void main(String[] args) {         System.out.println("Welcome to the Future Value Calculator\n");         Scanner sc...

    public static void main(String[] args) {         System.out.println("Welcome to the Future Value Calculator\n");         Scanner sc = new Scanner(System.in);         String choice = "y";         while (choice.equalsIgnoreCase("y")) {             // get the input from the user             System.out.println("DATA ENTRY");             double monthlyInvestment = getDoubleWithinRange(sc,                     "Enter monthly investment: ", 0, 1000);             double interestRate = getDoubleWithinRange(sc,                     "Enter yearly interest rate: ", 0, 30);             int years = getIntWithinRange(sc,                     "Enter number of years: ", 0, 100);             System.out.println();            ...

  • What is the output of following program: public class Test{ public static void main(String[] args) {...

    What is the output of following program: public class Test{ public static void main(String[] args) { A a = new A(): a method B(): } } class A{ public A(){ System out println("A's constructor is executed"): } public void method(){ System out printin ("methodA is executed"): } public void methodAB(){ System out printin ("As methodAB is executed"): } } class B extends A { private int num = 0: public B (){ super(): System out printin ("B's constructor is executed"):...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT