package liu0917; public class Student { int stuNO; String name; int age; void outPut() { System.out.println("学号是:"+stuNO); System.out.println("名字是:"+name); System.out.println("年龄是:"+age); } }
package liu0917; import java.util.Scanner; public class TestClass { public static void main(String[] args) { Student stu = new Student(); Scanner sc = new Scanner(System.in); Scanner sc1 = new Scanner(System.in); System.out.println("请输入学号:"); stu.stuNO=sc.nextInt(); System.out.println("请输入姓名:"); stu.name=sc1.nextLine(); System.out.println("请输入年龄:"); stu.age=sc.nextInt(); stu.outPut(); } }
原文:http://www.cnblogs.com/liuyanzeng/p/5878909.html