I'm in an intro to java programming class. We have to make a program that "Finds 20 three-digit whole numbers that are divisible by the product of their digits. The program must also contain 3 nested FOR loops"
import cs1.Keyboard;
public class threedig
{
public static void main()
{
System.out.println("The following numbers are divisible by the products of their digits:");
int hun=0;
int ten=0;
int one=0;
double num;
double b;
double c;
for(int x=0;x<100;x++)
{
hun++;
for(int y=0;y<100;y++)
{
ten++;
for(int z=0;z<100;z++)
{
one++;
num=(hun*100)+(ten*10)+(one);
b=num%(hun*ten*one);
if(b==0)
{
c=num/(hun*ten*one);
System.out.println(c);
}
}
}
}
System.out.println("End of Digits");
}
}
Thats what I wrote and the outcome comes out as:
The following numbers are divisible by the products of their digits:
111.0
56.0
23.0
12.0
11.0
6.0
3.0
1.0
End of Digits
Is there something I'm missing... also how could I weed out the 2 and 1 digit numbers?