Advertisement
476179

DOWhile

Nov 19th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. package lessons;
  2. import java.util.Scanner;
  3. public class DoWhile
  4. {
  5. // prgm asks for 3 test cores, cals avg, use do while, asks if they want to enter another test score
  6. public static void main(String[] args)
  7. {
  8. Scanner k = new Scanner(System.in);
  9.  
  10. //do while loop is post test loop
  11. //when using do while you will always get one iteration
  12. //after trh iteration then itll test the condition, if true do again, if not it wont
  13. String in;
  14. System.out.println("this prgm calcs avg of 3 test scores");
  15.  
  16.  
  17. do {
  18. double tst1, tst2, tst3, avg;
  19.  
  20. System.out.print("enter first score: ");
  21. tst1 = k.nextDouble();
  22. System.out.print("enter second score: ");
  23. tst2 = k.nextDouble();
  24. System.out.print("enter third score: ");
  25. tst3 = k.nextDouble();
  26. avg = (tst1 + tst2 + tst3)/(double)3;
  27. System.out.println("The average is : "+ avg);
  28. k.nextLine();
  29. System.out.print("do you want to enter more scores, type Y for yes and N for no");
  30. in = k.nextLine();
  31. } while (in.equalsIgnoreCase("y"));
  32. //here is only time to [put semicolon on while
  33.  
  34.  
  35. System.out.println("die");
  36.  
  37. k.close();
  38.  
  39.  
  40.  
  41. }
  42.  
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement