Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Trace the following Java code snippets: Assume the user will enter: 12 10 2015 3

ID: 3837673 • Letter: T

Question

Trace the following Java code snippets: Assume the user will enter: 12 10 2015 3 Scanner input = new Scanner (System in); String str =''; System.out.println ("Enter a day"); int day = input. next Int(); str = str + day+ ":"; System.out.println ("Enter a month"); int month = input. nextInt(); str = str + month + ":"; system. out.println ("Enter a year"); int year = input. nextInt (); str = str + year; System.out.println ("Enter the format"); int f = input.next Int(); f = f%3; if (f == 1){ str = str.replace (':', '/'); } else if (f == 2){ str = str.replace (':', '-'); } System.out.println ("Your date is " + str);

Explanation / Answer

line 5 , str = "12:"

line 8, str ="12:10:",

line 11 , str = "12:10:2015"

line 13( format value ) , f = 3

line 14, f = 3%3 = 0,

so f is not 1 or f is not 2, so line 15 and 17 won't be executed,

the final output is " Your date is 12:10:2015"

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote