Crenox

Prompt Integer Program

Feb 20th, 2014
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. //By: Sammy Samkough
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class prompt_integer
  6. {
  7. public static void main(String[] args)
  8. {
  9. Scanner sc = new Scanner(System.in);
  10. int num;
  11.  
  12. // I made this a do/while loop or it wouldn't be able to compile
  13. do
  14. {
  15. System.out.println("Give me an integer."); // prompt the user
  16. num = sc.nextInt();
  17. System.out.println("The squared number of your number is: " + Math.pow(num, 2) + ".\n");
  18. // I made an if to tell the user that the loop shall be terminated
  19. if(num == 0)
  20. {
  21. System.out.println("You have entered 0 so this loop shall be terminated.");
  22. }
  23. }while(num != 0);
  24. }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment