今天课程涉及到了判断语句if()、switch(),运算符及运算符的优先级,最后是循环,其他的还好,循环理解不够深刻,所以今天的主题我就以循环命名,下面做个今天学过的例子:
输入10个数,输出最大的数
class Xh{
public static void main(String[] args){
int i=1;
int max=0;
while(i<=10){
String s=JOptionPane.showInputDialog(null,"请输入第"+i+"个数");
int a=Integer.parseInt(s);
if(max<a){
max=a;
}
i++;
}
JOptionPane.showMessageDialog(null,"最大的数为"+max);
}
}