Accenture Primer
Accenture DumpmediumAccenture PrimerAccenture-Primer-Dump

Accenture Accenture Primer Practice Question

Predict the output What will be the output for the given code snippet startprogram Public class Main{ public static void main(String args[]) int a =10; for(int i=3;1>=0;1++) try{ System.out.println(a / i); System.out.println(“End of try”); } catch(ArithmaticException e) { System.out.println(e); } } } endprogram

Answer options

A
3 5 10 Java.lang.ArithmeticException: / by zero
B
3 End of try 5 End of try 10 End of try Java.lang.ArithmeticException: / by zero
C
Compiletimeerror
D
runtimeerror

Correct answer: 3 End of try 5 End of try 10 End of try Java.lang.ArithmeticException: / by zero

Explanation

Loop runs from i=3 down to i=0 (i>=0, i--). For i=3: 10/3=3, 'End of try'; i=2: 10/2=5, 'End of try'; i=1: 10/1=10, 'End of try'; i=0: ArithmeticException caught and printed.

Related Accenture Accenture Primer questions

Practice more Accenture Accenture Primer questions

PrimerDumps has 1400+ primer questions, 2026 mocks and coding hands-on — all free.