Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class WhileLoop
- {
- public static void main (String args[]){
- int total=100;
- int userNumber;
- while (total > 0){
- System.out.println("Enter a number");
- Scanner userInput = new Scanner(System.in);
- userNumber=userInput.nextInt();
- total -= userNumber;
- if (total<0){
- total +=userNumber;
- System.out.println("Your total cannot be smaller than 0");
- }
- System.out.println("Current total is "+total);
- }
- System.out.println("The final total is "+total);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement