Advertisement
Felanpro

while-loop and if-statment

Aug 15th, 2016
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. import java.util.Scanner; //import scanner to be able to read data from user.
  2.  
  3. public class program1
  4. {
  5.  
  6. public static void main(String[] args)
  7. {
  8. Scanner obj1 = new Scanner(System.in);
  9. System.out.print("Type 45: ");
  10. int x = obj1.nextInt(); //Waiting for input. And it scans it as an int.
  11. if(x == 45)
  12. {
  13. int y = 0;
  14. while(y < 101)
  15. {
  16. System.out.println(y);
  17. ++y;
  18. }
  19. }
  20. else
  21. {
  22. System.out.println("Error");
  23. }
  24. }
  25.  
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement