Advertisement
wadkat

java h/t

Nov 15th, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. package q1;
  2. import java.util.Scanner;
  3. public class q6 {
  4. public static void main(String[]args){
  5. Scanner keyboard = new Scanner(System.in);
  6.  
  7. int count=1,head=0,tail=0;
  8. char toss = 0;
  9.  
  10.  
  11. while(count<=8){
  12. System.out.print("h/t ");
  13. toss = keyboard.next().charAt(0);
  14. switch(toss)
  15. {
  16. case'h':
  17. case'H':
  18. head++;
  19. count++;
  20. break;
  21. case't':
  22. case'T':
  23. tail++;
  24. count++;
  25. break;
  26. default:
  27. System.out.println("invalid");
  28. }
  29.  
  30. }
  31. System.out.println("Heads x "+head);
  32. System.out.println("Tails x "+tail);
  33. System.out.println("Heads percent "+(head*100)/8.0);
  34. System.out.println("Tails percent "+(tail*100)/8.0);
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement