Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Holy digits Batman! The Riddler is planning his next caper somewhere on Pennsylv

ID: 3841070 • Letter: H

Question

Holy digits Batman! The Riddler is planning his next caper somewhere on Pennsylvania Avenue. In his usual sporting fashion, the Riddler has left the address in the form of a puzzle. The address on Pennsylvania is a four-digit number where all the following criteria are true:

All four digits are different

The digit in the thousands place is three times the digit in the tens place

The number is odd

The sum of all four digits == 27

Write a Java console application that uses a single loop to figure out the address (4-digit number) where the Riddler intends to strike. Display the address as "The Riddler intends to strike #### Pennsylvania Avenue."

Explanation / Answer

RiddlerStrike.java :
_________________

public class RiddlerStrike {
   public static void main(String[] args) {
       int digits[] = {0,1,2,3,4,5,6,7,8,9};
       int four[] = {3,7,8,9};//we need to have a four digits sum =27,so these four only give sum 27
       StringBuffer sb = new StringBuffer();
       sb.append(9); // thousands place is three times the digit in tens place
       sb.append(four[2]);
       sb.append(3);//tens place
       sb.append(four[1]);// sum needs to be odd
       //Here the checking
       int sum = 0;
       for(int i=0;i<sb.length();i++){
           sum += Character.getNumericValue(sb.charAt(i));
       }
       int num = Integer.parseInt(sb.toString());
       if(sum == 27 && num%2!=0)
           System.out.println("The Riddler intends to strike "+ num +" Pennsylvania Avenue");
   }
}

Sample Input and Output:
______________________

The Riddler intends to strike 9837 Pennsylvania Avenue

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote