package sunday;
import java.util.Scanner;
class Person{
String name;
int age;
String work;
static String nation="中国";
public Person(String name,int age,String work,String nation){
this.name=name;
this.age=age;
this.work=work;
}
public void Display(){
System.out.println(" 姓名:"+name+"------"+"年龄:"+age+"------"+"职业:"+work+"------"+"国籍:"+nation);
}
}
public class test1 {
public static void main(String[] args) {
int i=1;
while (i<= 2){
Scanner sc=new Scanner(System.in);
String name=sc.next();
int age=sc.nextInt();
String work=sc.next();
String nation=sc.next();
}
Person p1=new Person(name,age,work,nation);
p1.Display();
}
}
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
name cannot be resolved to a variable
age cannot be resolved to a variable
work cannot be resolved to a variable
nation cannot be resolved to a variable
把Person p1=new Person(name,age,work,nation);,放上面大括号上面,望采纳