# loop.pptx - Tutorial 6 Sentinel flag loop do while loop Q1...

• No School
• AA 1
• 8

This preview shows page 1 - 6 out of 8 pages.

Tutorial 6 Sentinel & flag loop , do while loop

Subscribe to view the full document.

Q1: Trace the following codes and then find the output: (A) int i=0; int sum=0; while (i<5) {sum=sum+i; i++; } while (i<5) {sum=sum+i+i%2; i++;} System.out.println( "sum= " +sum); System.out.println( "counter i= " +i); i sum Output: sum= 10 counter i= 5 1 0 0 0 2 1 3 3 4 6 5 10
Q1: Trace the following codes and then find the output: (B) int num=14; while (num%2!=0){ System.out.println(num++); if (num<=25) num++; } // end of while No Output False (14%2 = 0)

Subscribe to view the full document.

Q1: Trace the following codes and then find the output: (C) int n = 123456789; int m = 0; while (n != 0) { m = (10 * m) + (n % 10); n = n / 10; } n M No Output 12345678 9 123456789 0 1234567 98 123456 987 12345 9876 1234 98765 123 987654 12 9876543 1 98765432 0 987654321
Q2: Coding Jarir bookstore sells five products online with the following prices: Write a program that calculates the total amount due per customer. Also the program should calculate the total amount earned by Jarir for all customers *Your program should use a switch statement. *All input data should be read by the user. *Use a sentinel to stop your program.

Subscribe to view the full document.

• Fall '19
• Jarir

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern

Ask Expert Tutors You can ask 0 bonus questions You can ask 0 questions (0 expire soon) You can ask 0 questions (will expire )
Answers in as fast as 15 minutes