Advertisement
mrScarlett

Untitled

Nov 24th, 2016
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.70 KB | None | 0 0
  1. import java.util.*;
  2. public class WhileLoop
  3. {
  4.     public static void main (String args[]){
  5.         int total=100;
  6.         int userNumber;
  7.         while (total > 0){
  8.            
  9.                
  10.             System.out.println("Enter a number");
  11.             Scanner userInput = new Scanner(System.in);
  12.             userNumber=userInput.nextInt();
  13.             total -= userNumber;
  14.             if (total<0){
  15.                 total +=userNumber;
  16.                 System.out.println("Your total cannot be smaller than 0");
  17.             }
  18.            
  19.                
  20.             System.out.println("Current total is "+total);
  21.         }
  22.         System.out.println("The final total is "+total);
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement