Hi Im new to this forum and also new to java, I need some help for my intro to java homework. Ive done most of the logic. The problem is to write a program that displays all the numbers from 100 to 1000, ten per line, that are divisible by 5 and 6. Numbers are separated by exactly one space. My professor wants it to be done in a Joptionpane window. When I try to do that, only one answer pops up in a window. How do I make my answers appear ten in a line, separated by exactly one space in only one window?
public class FindFactors {
public static void main(String[] args) {
final int NumbersPerLine = 10; // Display 10 numbers per line
int count = 0; // Count the number of numbers divisible by 5 and 6
// Test all numbers from 100 to 1,000
for (int i = 100; i <= 1000; i++) {
// Test if number is divisible by 5 and 6
if (i % 5 == 0 && i % 6 == 0) {
count++; // increment count
// Test if numbers per line is 10
if (count % NUMBERS_PER_LINE == 0)
JOptionPane.showMessageDialog( null, i);
else
JOptionPane.showMessageDialog( null,(i + " "));
}
}
}
}