This a java program. The Riddler is planning his next caper somewhere on Pennsyl
ID: 3740161 • Letter: T
Question
This a java program.
The Riddler is planning his next caper somewhere on Pennsylvania Avenue. In his usual sporting fashion, he has left the address in the form of a puzzle. The address on Pennsylvania is a four digit number where: -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 the digits is 27 This is a java program Write a program that uses a loop (or loops) to find the address where the Riddler plans to strike.
Explanation / Answer
class Riddler{
public static void main(String [] args){
int i,j=0,k=0,l=0;
int flag = 0;
for(i=1 ;i<10; i++){
for(j=1 ;j<10; j++){
for(k=1 ;k<10; k++){
for(l=1 ;l<10; l++){
// In this 4 if loops we will be checking for the 4 conditions given to find the
// Address of the riddler
if(i != j && j!=k && k!= l && l!= i){ // Check that the 4 digits are different
if(i == 3*k){ // Check the digit at thouisand place is 3 times the digit at tens place
if(l%2 != 0){ // Check the number is odd
if((i+j+k+l) == 27){ // Check the sum is equal to 27
System.out.println("The address where the Riddler plans to strike is " + i + j + k + l);
}
}
}
}
}
}
}
}
}
}
Thanks, let me know if there is any concern.