import java.util.Scanner;
public class test {
/**
* @param args
*/
public static void main(String[] args) {
//定义一个获取键盘扫描的对象
Scanner scanner=new Scanner(System.in);
System.out.println("请输入您的名字:");
//获取输入的名字
String name=scanner.next();
System.out.println("请输入您的年龄:");
//获取输入的年龄,这里把他转换成数值型
int age=Integer.valueOf(scanner.next());
System.out.println("请输入您的身高:");
//获取输入的身高,这里把他转换成数值型
int hight=Integer.valueOf(scanner.next());
Student student=new Student(name, age, hight);
System.out.println(student);
}
//顶一个学生信息的类
static class Student{
private String name;
private int age;
private int sex;
public Student(String name, int age, int sex) {
super();
this.name = name;
this.age = age;
this.sex = sex;
}
@Override
public String toString() {
return "Student [name=" + name + ", age=" + age + ", sex=" + sex
+ "]";
}
}
}
希望这可以帮到你
|