1.a) In the code you just compiled and ran, i) what output was given for : (2 pt
ID: 3878528 • Letter: 1
Question
1.a) In the code you just compiled and ran,
i) what output was given for : (2 pts)
System.out.println(("67 - 55");
ii) and what output was given for : (2 pts)
System.out.println(67 - 55);
iii) What is different about the two lines of code that might have caused the difference in the two outputs? (5 pts)
1.b) Now, go back to the main function in Lab1Part1 and add the following code below the code you wrote already:
System.out.println("Testing more arithmetic and output");
System.out.println("55 * 67 = ");
System.out.println(55 * 67);
System.out.print("55.0 * 67.0 = ");
System.out.println(55.0 * 67.0);
System.out.print("55 * 67 =");
System.out.print(55 * 67);
System.out.println(55.0 * 67.0);
System.out.println("");
System.out.println("55 * 67 = " + (55 * 67) + " or "+ (55.0 * 67.0));
i) If you make these changes to the program and run the program what lines of output are produced? (3 pts)
ii) In the output line ‘55 * 67 = 3685 or 3685.0’ why do you think the two last numbers (‘3685’ & ‘3685.0’) are printed differently? (3 pts)
iii) In the output line ‘55 * 67 =36853685.0’ why do you think the final output number is 36853685.0 ? (3 pts)
iv) What is the difference between the two lines below and how does it affect their output:
System.out.println(55 * 67); // and (3 pts)
System.out.print(55 * 67);
v) In the statement:
System.out.println("55 * 67 = " + (55 * 67) + " or "+ (55.0 * 67.0));
what do the plus signs (‘+’) seem to be doing? (4 pts)
Explanation / Answer
1.a i)
System.out.println(("67 - 55")
Output: 67 - 55
Reason: Because it is a string and whatever is there in string, it prints as is
1.a ii)
System.out.println(67 - 55);
Output: 12
Reason: 67 and 55 are numbers on which - operation can be performed. So, it calculates 67-55 and outputs answer which is 12
1.a iii)
First one is string which prints as is
Second one contains numbers on which operation is performed
1.b i)
Output:
Testing more arithmetic and output
55 * 67 =
3685
55.0 * 67.0 = 3685.0
55 * 67 =36853685.0
55 * 67 = 3685 or 3685.0
Reason: As told in the 1.a i) and ii) Whichever is in quotes will be printed as string and whichever is in numbers format will get calculated.
Note: One complete question or first 4 sub parts will be answered at a time .
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.