Advertisement
Guest User

Untitled

a guest
Jan 29th, 2015
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. //i have been slowly learning Java so this is the language that I chose to do it in.
  2.  
  3. import java.util.Scanner;
  4.  
  5.  
  6. public class PingPong {
  7.  
  8. static Scanner userInput = new Scanner(System.in);
  9.  
  10. public static void main(String[] args) {
  11.  
  12. if (userInput.hasNextInt())
  13. {
  14. int numberEntered = userInput.nextInt();
  15. //System.out.println(numberEntered);
  16. int i;
  17. for (i = 0; i <= numberEntered; i++)
  18. {
  19.  
  20. if (i == 0)
  21. System.out.println("0");
  22. else if (i % 5 == 0)
  23. if (i % 3 == 0) System.out.println("Ping-Pong");
  24. else
  25. System.out.println("Pong");
  26. else if (i % 3 == 0)
  27. System.out.println("Ping");
  28. else
  29. System.out.println(i);
  30. }
  31.  
  32. }
  33.  
  34. else
  35. {
  36. System.out.println("You have not entered a number");
  37. }
  38.  
  39. }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement