Please justfiy this code\'s output. Output = 30 122.5 true 45.56 public class Or
ID: 3745374 • Letter: P
Question
Please justfiy this code's output. Output = 30 122.5 true 45.56
public class OrderOfOperations {
public static void main(String[] args) {
int numberOne = -2 + 5 * 7 - 7 / 2 % 5;
double numberTwo = 2.5f + 1.2e+2;
boolean bolleanOne = true||false&&true|false;
String stringOne = String.format("%10.2f", 45.556);
System.out.println(numberOne);
System.out.println(numberTwo);
System.out.println(bolleanOne);
System.out.println(stringOne);
}
}
No need to explain int numberOne.
Explanation / Answer
public class OrderOfOperations { public static void main(String[] args) { int numberOne = -2 + 5 * 7 - 7 / 2 % 5; // -2 + 5 * 7 - 7 / 2 % 5 // -2 + (5 * 7) - (7 / 2) % 5 // -2 + 35 - (3 % 5) // -2 + 35 - 3 // 33 - 3 // 30 // so, numberOne has a value of 30 double numberTwo = 2.5f + 1.2e+2; // 1.2e+2 is 1.2*100 = 120 // 2.5f + 1.2e+2 is 2.5 + 120 = 122.5 // so, numberTwo has a value of 122.5 boolean bolleanOne = true||false&&true|false; // true||false&&(true|false) // (true||false)&&true // true && true // true // so, bolleanOne has a value of true String stringOne = String.format("%10.2f", 45.556); // creates a 10 character string using 45.556. uses only 2 digits after decimal point. and adds whitespaces before the number to count length upto 10. // so, stringOne is " 45.56" System.out.println(numberOne); System.out.println(numberTwo); System.out.println(bolleanOne); System.out.println(stringOne); } }