Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package lessons;
- import java.util.Scanner;
- public class DoWhile
- {
- // prgm asks for 3 test cores, cals avg, use do while, asks if they want to enter another test score
- public static void main(String[] args)
- {
- Scanner k = new Scanner(System.in);
- //do while loop is post test loop
- //when using do while you will always get one iteration
- //after trh iteration then itll test the condition, if true do again, if not it wont
- String in;
- System.out.println("this prgm calcs avg of 3 test scores");
- do {
- double tst1, tst2, tst3, avg;
- System.out.print("enter first score: ");
- tst1 = k.nextDouble();
- System.out.print("enter second score: ");
- tst2 = k.nextDouble();
- System.out.print("enter third score: ");
- tst3 = k.nextDouble();
- avg = (tst1 + tst2 + tst3)/(double)3;
- System.out.println("The average is : "+ avg);
- k.nextLine();
- System.out.print("do you want to enter more scores, type Y for yes and N for no");
- in = k.nextLine();
- } while (in.equalsIgnoreCase("y"));
- //here is only time to [put semicolon on while
- System.out.println("die");
- k.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement