高手帮我看下importjavax.swing.JOptionPane;publicclassGreatestCommonDivisor{/**mainmethod*/publicstaticvoidmain(String[]args){//prompttheusertoentertwointegersStrings1=JOp...
高手帮我看下
import javax.swing.JOptionPane;
public class GreatestCommonDivisor {
/** main method */
public static void main(String[] args) {
//prompt the user to enter two integers
String s1 = JOptionPane.showInputDialog(null,"please input a integer","p79",JOptionPane.QUESTION_MESSAGE);
String s2 = JOptionPane.showInputDialog(null,"please input another integer","p79",JOptionPane.QUESTION_MESSAGE);
int m1 = Integer.parseInt(s1);
int m2 = Integer.parseInt(s2);
int n1 = m1>m2 ? m1:m2;
int n2 = m1+m2-n1;
do {
int r = n1/n2;
n1 = n2;
n2 = r;
} while (r!=0);
JOptionPane.showMessageDialog(null,"the great divisior is:" +n2,"p79",JOptionPane.INFORMATION_MESSAGE);
}
}
这里do...while中的括号r!=0为什么“r cant be rosolved"呢?
应该怎么改程序才好运行呢!!
展开