all the numbers between 2 and 100 (inclusive) which are co-prime with respect to the user-input number.
Construct a program that:
1. prompts user to enter a single integer number using the JOptionPane input dialog API
2. loops for all numbers between 2 and 100 (inclusive) and prints only those numbers which are co-prime
with the user-input number (using System.out"
this is what I have so far:
import javax.swing.JOptionPane;
public class loops {
public static void main(String[] args) {
String input = JOptionPane.showInputDialog( "Enter a single integer:" );//asks user to input the variable
int userInt = Integer.parseInt( input );//parses user's input into integer form
for (int coprime = 2; coprime <= 100; coprime = coprime+1){
for (int divisor = 2; divisor <= userInt/2; divisor = divisor+1){
if ((userInt % divisor == 0)&&(coprime % divisor == 0)) continue;
else System.out.println(coprime);
}
}
}
}
I honestly have no clue what I'm doing. The code compiles but it definitely does not give me the correct output.

New Topic/Question
Reply



MultiQuote






|