像这种问题应该好好看看,自己也能解决的,下面是我的代码- package com.test;
- import java.util.*;
- public class Test
- {
- public static void main(String[] args)
- {
- for(int i=0;i<3;i++)
- {
- Scanner sc=new Scanner(System.in);
- System.out.print("请输入姓名");
- String name=sc.nextLine();
- System.out.print("请输入性别");
- String sex=sc.nextLine();
- System.out.print("请输入年龄");
- int age=sc.nextInt();
- Person p=new Person(name,sex,age);
- }
-
-
-
- }
- }
- class Person
- {
- private String name;
- private String sex;
- private int age;
- public Person(String name,String sex,int age) {
- this.name=name;
- this.sex=sex;
- this.age=age;
- System.out.println(name+" "+sex+" "+age);
- }
-
- }
复制代码 |