Question

1 Riddler (10pts) The agent #7 “J. B.” of the international spy agency “All Ears, all...

1 Riddler (10pts)

The agent #7 “J. B.” of the international spy agency “All Ears, all Eyes” needs to transmit a secret 5 digit code back to her headquarters. She transmits the following 8 indications:

  • The sum of the 5 digits is 27.

  • The code is an even number.

  • The sum of the first and the last digit is equal to the digit in the middle.

  • The difference of the second digit and the fourth digit is one; the second digit is greater than the fourth digit.

  • The sum of the second digit and the fourth digit is equal to the third digit.

  • No digit repeats in the code.

  • None of the digits is zero.

  • The code is the smallest 5 digit number satisfying the 7 other conditions.

    Write a Java program Riddler.java that helps the decoding master “Q” at “All Ears, all Eyes” head- quarters to decypher the code.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Coding

class Riddler{
public static void main(String args[]){
int secretCode,sumof_digit=0,Reminder,temp,f_digit=0,s_digit=0,t_digit=0,four_digit=0,fifth_digit=0;//initilize use full variable
   for(int i=10000;i<=99999;i++)
   {
   sumof_digit=0;
   temp=i;
   int j=0;
   while(temp > 0) {
           Reminder = temp % 10;
           sumof_digit = sumof_digit+ Reminder;//calculate sum of digit
           temp = temp / 10;
           j++;
           if(j==1)
           fifth_digit=Reminder;//initilize digit number
           else if(j==2)
           four_digit=Reminder;//initilize digit number
           else if(j==3)
           t_digit=Reminder;//initilize digit number
           else if(j==4)
           s_digit=Reminder;//initilize digit number
           else if(j==5)
           f_digit=Reminder;//initilize digit number
          
       }
      
       if(sumof_digit==27 && i%2==0 && f_digit+fifth_digit==t_digit && s_digit>four_digit && s_digit-four_digit==1 && s_digit+four_digit==t_digit)//here is the all condition that must be satisfiying if we want to find secret number
       {
               if(f_digit!=s_digit || f_digit!=s_digit || f_digit!=t_digit || f_digit!=four_digit || f_digit!=fifth_digit || s_digit!=t_digit || s_digit!=four_digit || s_digit!=fifth_digit || t_digit!=four_digit || four_digit!=fifth_digit ||f_digit!=0||s_digit!=0|| t_digit!=0||four_digit!=0|| fifth_digit!=0) //number should not be same repeat and not is 0
               {
                   System.out.println("Secret Number is "+i);
           break;
               }
       }
   }     
}
}

output:

if you still have any Problem regarding this question please comment and if you like my code please appreciate me by thumbs up thank you.........

Add a comment
Know the answer?
Add Answer to:
1 Riddler (10pts) The agent #7 “J. B.” of the international spy agency “All Ears, all...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT