Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Assuming that the user enters 45 and 62 as inputs for n1 and n2, respectively, w

ID: 3704254 • Letter: A

Question

Assuming that the user enters 45 and 62 as inputs for n1 and n2, respectively, what is the output of the following code snippet?

System.out.print ("Enter a number: ");
Scanner in = new Scanner (System.in);
String n1 = in.next ();
System.out.print ("Enter another number: ");
String n2 = in.next ();
String result = n1 + n2;
System.out.print (result);

?????

?? 21 ?

Which of the following conditions is true only when the integer variables a, b, and c contain three different values?

?????

?? 31 ?

Assuming that a user enters 25 as the value for x, what is the output of the following code snippet?

int x;
Scanner in = new Scanner(System.in);
System.out.print("Enter a number: ");
x = in.nextInt();

if (x < 100)
     x = x + 5;
if (x < 500)
     x = x - 2;
if (x > 10)
     x++;
else
     x--;
System.out.println(x);

?????

?? 41 ?

What is the output of the code snippet given below?

for (int i = 0; i != 9; )
{
      System.out.print (" " + i);
      i = i + 2;
}

?????

?? 51 ?

How many times does the following code snippet display "Loop Execution"?

for (int i = 0; i < 10; i++) ;
{
     System.out.println("Loop Execution") ;
}

?????

?? 61 ?

What does the output show when this loop executes and finally terminates?

for ( int i = 20 ; i >= 2 ; i = i - 6 )
{
      System.out.print ( i + ", " );
}

?????

?? 71 ?

Which of the following for loops is not valid?

?????

?? 81 ?

Given the following code snippet, what should we change to have all 26 alphabetic characters in the string str?

String str = "";
for ( char c = 'A' ; c < 'Z' ; c++ )
{
      str = str + c;
}

?????

?? 91 ?

Insert a statement that will correctly terminate this loop when the end of input is reached.

boolean done = false;
while (!done)
{
      String input = in.next();
      if (input.equalsIgnoreCase("Q"))
      {
          __________
      }
      else
      {
           double x = Double.parseDouble(input);
           data.add(x);
       }
}

?????

?? 101 ?

How many times will the output line be printed in the following code snippet?

for (int num2 = 1; num2 <= 3; num2++)
{
       for (int num1 = 0; num1 <= 2; num1++)
           {
                 System.out.println ( "" + num2 + " " + num1 );
           }
}

?????

?? 111 ?

Consider the following line of code for calling a method named methodX where data is an integer and varData is an double variable.

   methodX (data, varData );

Which one of the following method headers is valid for methodX?

?????

?? 121 ?

The non-static methods of a class are called the ____ methods of the class.

?????

?? 131 ?

Which of the following is an example of a local identifier in the following code?

01: public class scopeRule
02: {
03: static double intRate = 0.055;
04:      static String name;
05:      static int t;

06:    public static int main(String[] args)
07:      {
08:          int first;
09:          double u, t;
10: String str;
11: //. . .
12:      }

13:    public static int first(int x, int y)
14: {
15:          int t;
16: }

17:    public static double salary;
18: }

?????

?? 141 ?

Which of the following identifiers in the following code are usable in method first?

01: public class scopeRule
02: {
03: private double intRate = 0.055;
04: private static String name;
05: private int t;

06:    public static int main(String[] args)
07:      {
08:          int first;
09:          double u, t;
10: String str;
11: //. . .
12:      }

13:    public static int first(int x, int y)
14: {
15:          int t;
16: }

17: public double salary;
18: }

?????

?? 151 ?

Which of the following identifiers in the following code are usable in another class?

01: public class scopeRule
02: {
03: private double intRate = 0.055;
04: private static String name;
05: private int t;

06:    public static int main(String[] args)
07:      {
08:          int first;
09:          double u, t;
10: String str;
11: //. . .
12:      }

13:    public static int first(int x, int y)
14: {
15:          int t;
16: }

17: public double salary;
18: }

?????

?? 161 ?

In the method first, the programmer wishes to update the value stored in the variable intRate (Line 3). Which of the following is correct?

01: public class scopeRule
02: {
03: private double intRate = 0.055;
04: private String name;
05: private static int t;

06:    public static int main(String[] args)
07:      {
08:          int first;
09:          double u, t;
10: String str;
11: //. . .
12:      }

13:    public static int first(int x, int y)
14: {
15: double intRate;
16: intRate = x * y;
17: }

18: public double salary;
19: }

?????

?? 171 ?

Consider the following class definition.

public class Cylinder extends Object {
   private double height;

   public Cylinder (double radius, double h) {
super(radius);
       height = h;
   }

public double getRadius() {
return super.getRadius();
}

   public String toString() {
       return (getRadius() + " " + height);
   }

   public double surfaceArea() {
return 2 * 3.14 * getRadius() * height;
   }

   public double volume() {
       return 3.14 * getRadius() * getRadius() * height;
}
}

Suppose that you have the following declaration.

Cylinder cyl = new Cylinder(1.5, 10);

Which of the following statements are valid in Java?

107

Explanation / Answer

As per Chegg policy, I am answering only first question. In order to get the solution of remaining questions, please upload them again.

Option b is the correct option as n1+n2 results in concatenation of string not the addition of numbers.So it will result in 4562.