Exe Gamer
Exe Gamer

Reputation: 21

How to check if a number is past 100 and return by how much it is?

Hey how i can check if my input is past 100 and return by how much it is? For example My current is 50 and i wan't to add 60 more, i want to return 10. I tried something like this:

    public static void addPoints(int current, int amount) { 
    int left = 0,  total = 0;
    if(current + amount > 100) {
        left = amount - current  ;
        total = amount + current;
    }
    System.out.println("You got " + total  +" and " + left + " over 100.");
}

Upvotes: 1

Views: 52

Answers (1)

hamlet
hamlet

Reputation: 127

Try this:

public static void addPoints(int current, int amount) {
    int total = amount + current;
    System.out.println("You got " + total  +" and " + (total-100) + " over 100.");
}

Upvotes: 3

Related Questions