一个java题 依次从键盘录入该学生信息,完成后输出该生详细信息,写了个程序但是不知道哪里错了 运用java编写一个程序,从键盘输入某门课程10个学生的成绩...
\u8981\u6c42\u7f16\u5199\u4e00\u4e2ajava\u7a0b\u5e8f\uff0c\u8f93\u5165\u5b66\u751f\u4fe1\u606f\uff0c\u5e76\u80fd\u4fdd\u5b58\u4e0e\u663e\u793a\u5b66\u751f\u4fe1\u606f\u3002import java.util.ArrayList;
import java.util.Scanner;import com.sun.org.apache.xpath.internal.Arg;
public class Student {
//\u4e24\u4e2a\u79c1\u6709\u5c5e\u6027
private int no ;
private String name ;
//\u9ed8\u8ba4\u6784\u9020\u51fd\u6570
public Student(){}
//\u5e26\u53c2\u6784\u9020\u51fd\u6570
public Student(int no,String name){
this.no=no;
this.name=name;
}
//\u6dfb\u52a0\u5b66\u751f\u4fe1\u606f
public void addStudentInfo(ArrayList list){
String flag1="yes";
do{
Student student=new Student();
Scanner in =new Scanner(System.in);
System.out.println("\u8bf7\u8f93\u5165\u5b66\u751f\u5b66\u53f7\uff1a");
student.setNo(in.nextInt());
System.out.println("\u8bf7\u8f93\u5165\u5b66\u751f\u59d3\u540d\uff1a");
student.setName(in.next());
list.add(student);
System.out.println("\u662f\u5426\u7ee7\u7eed\u6dfb\u52a0\u5b66\u751f\u4fe1\u606f(yes/no)?");
flag1=in.next();
} while(flag1.equals("yes"));
}
//\u8bfb\u53d6\u5b66\u751f\u4fe1\u606f
public void showStudentInfo(ArrayList list){
System.out.println(" \u5b66\u751fno\uff1a "+" \u5b66\u751fname: ");
for(Student student:list){
System.out.println(" "+student.getNo()+" "+student.getName());
}
}
public int getNo() {
return no;
}
public void setNo(int no) {
this.no = no;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public static void main(String arg[]) {
ArrayList studentList= new ArrayList();
Student student= new Student();
Scanner inn= new Scanner(System.in);
while(true){
System.out.println("----------------- \u6b22\u8fce\u4f7f\u7528\u5b66\u751f\u7ba1\u7406\u7cfb\u7edf------------------");
System.out.println("1.\u8f93\u5165\u5b66\u751f\u4fe1\u606f");
System.out.println("2.\u663e\u793a\u5b66\u751f\u4fe1\u606f");
System.out.println("0.\u9000\u51fa\u7cfb\u7edf");
System.out.println("\u8bf7\u9009\u62e9....");
int nn= inn.nextInt();
switch (nn) {
case 1:
student.addStudentInfo(studentList);
break;
case 2:
System.out.println("\u5b66\u751f\u4fe1\u606f\u5982\u4e0b\uff1a");
student.showStudentInfo(studentList);
break;
case 0:
System.exit(0);
System.out.println("\u7cfb\u7edf\u9000\u51fa\uff01");
break;
default:
break;
}
}
} }
public static void main(String args[]){
int i = 0;
Integer[] grades = new Integer[5];
while(i<5){
Scanner in = new Scanner(System.in);
int a = in.nextInt();
grades[i] = a;
i++;
}
int j = 1;
for(int grade : grades){
System.out.println("\u7b2c"+j+"\u5b66\u751f\u7684\u6210\u7ee9\u4e3a\uff1a"+grade);
j++;
}
}
您好,提问者:
没有导入包造成的,修改如下:
import java.io.Console;//加上这句
public class Student{
/xxx
Console好像不能在IDE里面使用.
建议使用BufferedReader:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s = br.readLine();
Console.ReadLine
R大写,还有你导包正确了没?
扩展阅读:java入门 ... java 报错 ... java学习 ... java workbook ... java poi ... java 方法 ... java 对话框 ... js中的eval详解 json ... java script菜鸟教程 ...