The Riddler is planning his next caper somewhere on Pennsylvania Avenue. In his
ID: 3566274 • Letter: T
Question
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
Write a program that uses a loop (or loops) to find the address where the Riddler plans to strike.
Best answer will be awarded 1,050 points! Thanks in advance.
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++){
if(i != j && j!=k && k!= l && l!= i){
if(i == 3*k){
if(l%2 != 0){
if((i+j+k+l) == 27){
System.out.println("The address where the Riddler plans to strike is " + i + j + k + l);
}
}
}
}
}
}
}
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.