What is the output of: int a = 7; int b = 2; System.out.println(a / b); System.out.println((double) a / b);
Values and Data Types
Original Khojo Papers practice question — not from a past board paper.
Implicit conversion, or widening, is done automatically by the compiler when a smaller type is assigned to a larger one, as in "double d = 5;". Explicit conversion, or casting, must be written by the programmer when a larger type is assigned to a smaller one and data may be lost, as in "int n = (int) 5.75;", which stores 5.
No citable source has been recorded for this record. Treat it as practice material, not as fact.
Casting a double to an int truncates rather than rounds.
From the same topic and chapter, at a similar level.
What is the output of: int a = 7; int b = 2; System.out.println(a / b); System.out.println((double) a / b);
Values and Data Types
Distinguish between a primitive type and a reference type in Java, with two examples of each.
Values and Data Types
What is the output of: System.out.println(10 / 3); System.out.println(10 % 3); System.out.println(10.0 / 3);
Values and Data Types
Name the eight primitive data types of Java and state the size of each.
Values and Data Types
Explain the ternary operator in Java and rewrite "if (a > b) max = a; else max = b;" using it.
Operators and Expressions in Java
What is the output of: String s = "Examination"; System.out.println(s.length() + " " + s.substring(0, 4) + " " + s.toUpperCase().charAt(2));
String Handling