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

E) none of the above, a run-time crror aises because z is a float and 5 7 1o is

ID: 3590081 • Letter: E

Question


E) none of the above, a run-time crror aises because z is a float and 5 7 1o is an in 15) What is output with the statement System.out.printinxty); if x and y are int values where x-10 and y-5? A) 15 B) 105 C) 105 D)xty E) An error since neither x nor y is a String 16) If you want to store into the String name the value "George Bush", you would do which statement? C)Stnng name= "George,+ sir +"Bushin na Strin new strin ewitngeBuone" +" " + sh": Any of the above would work 17) Provide three examples of code using assignment statements where one assignment a syntax error, one would result in a logical error, and one would result in a run-time error. in 18) Write a Java program that will display the following three lines when it is run public static void main(String[ ] args)

Explanation / Answer

15. System.out.println("" + x + y);   //This is an empty string concatenated with the value of x, concatenated with the value of y.
   So, the answer is: B) 105
16. A. String name = "George Bush";   //Creates a variable name, and is assigned a String literal.
   B. String name = new String("George Bush");   //Creates an object of type String, and is initialized with specified String.
   C. String name = "George" + " " + "Bush";    //Creates a variable name, and is assigned the concatenation of 3 strings.
   D. String name = new String("George" + " " + Bush");   //Creates an object of type String, and is initialized with concatenation of 3 string literals.
   Everything works fine.
   So, the answer is E. Any of the above would work.
17. Assignment statement, assume like:
   int a = 10;   //This works perfectly fine.
   int a = 10   //This leads to a syntax error, as we missed the semicolon.
   short a = (short)1000000; //This leads to a logical error. Everything works fine, but produces unexpected output.
18.
   public static void main(String[] args)
   {
      //To keep it simple I prefer directly writing 3 print statements.
      System.out.println("*");
      System.out.println("* * *");
      System.out.println("* * * * *");
   }