Discussion
What will be the output of the program?
public class Case78
{
public static void main(String[] args) throws Exception
{
int octal = 070;
int hex = 0x1A;
int plain = 70;
System.out.println(octal + ", " + hex + ", " + plain);
}
}
Answer: B
A leading zero marks an octal literal, so 070 is 7 times 8, which is 56, not 70. The 0x prefix marks hexadecimal, so 1A is 26. Without a prefix, 70 is just seventy, which is what makes the padded form so easy to misread. Accidental octal is a classic source of quiet arithmetic bugs.
No comment is present. Be the first to comment.
Loading…
Post your comment
Please log in or register to post a comment.
Examination Categories
- SSC Exams
- Banking Exams
- Teaching Exams
- Civil Services Exams
- Railways Exams
- Engineering Recruitment Exams
- Defence Exams
- State Government Exams
- Police Exams
- Insurance Exams
- Nursing Exams
- Other Government Exams
- NRA CET
- PG Entrance Exams
- Campus Placement
- MBA Entrance Exams
- CUET and UG Entrance
- Judiciary Exams
- Regulatory Body Exams
- Software Development