Answer to Question #259148 in Java | JSP | JSF for joy

Question #259148

4. Jackpot!



by CodeChum Admin




Did you know that in lotteries, a 3-digit number with the same numbers in all digits like 777 will hit the jackpot in a casino? In the same manner, let's make a program that will test if a certain 3-digit number hits a jackpot or not by identifying if all the digits of a given number is the same as the second inputted number. If it is, print "Jackpot!"; else, print "Nah".




Let's try this out now!




Input




A line containing two integers separated by a space.




777·7



Output




A line containing a string.




Jackpot!

1
Expert's answer
2021-11-01T18:47:43-0400


package jackpock;


import java.util.Scanner;




public class Jackpot {


    
    public static void main(String[] args) {
         Scanner sc = new Scanner(System.in);
        
        int number1 = sc.nextInt();
        int number2 = sc.nextInt();


        boolean jackpot = true;


        while(number1 > 0) {
            int digit = number1%10;
            
            if(digit != number2) {
                jackpot = false;
            }
            number1 = number1/10;
        }
        if(jackpot) {
            System.out.println("Jackpot!");
        }
        else {
            System.out.println("Nah");
        }
    }
    
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS