JAVA程序求注释

来源:百度知道 编辑:UC知道 时间:2024/06/22 05:02:03
import java.util.Scanner;

public class perfectnumber {

public static void main(String[] args) {
System.out.println("请输入数字:");
String s=new String();
Scanner c=new Scanner(System.in);
s=c.next();
int a = 0;
try {
a = Integer.parseInt(s);
int sum = 0;
for(int i=1;i<=a/2;i++){
if(a%i == 0) {
sum += i;
}
}

if(a==sum) {
System.out.print("a+是完全数");
} else {
System.out.print("a+不是完全数");
}
} catch(NumberFormatException e) {
e.printStackTrace();
}

}

}

要求注释的语句
System.out.println("请输入数字:");
String s=new String();
Scanner c=new Scanner(System.in);
s=c.next();

a = Integer.parseInt(s);

e.printStackTrace();

如果程序有问题的话请提出,谢谢

System.out.println("请输入数字:");//打印提示字符
String s=new String();//定义字符串对象S
Scanner c=new Scanner(System.in);//定义键盘输入流对象c
s=c.next();//通过键盘输入获取字符串,并存入S

a = Integer.parseInt(s);//将字符串S解析为有符号的整数

e.printStackTrace();//出错提示,打印出抛出异常时当前位置的调用层次关系