java求解:下面的程序是课本的例子,但是运行有错误,不知道是什么原因,请高手帮忙,谢谢!
classStudent1{Stringname;intage;Student1(Stringn,inta){name=n;age=a;}StringgetName(){...
class Student1
{
String name;
int age;
Student1(String n,int a)
{
name=n;
age=a;
}
String getName()
{
return name;
}
void setName(String n)
{
name=n;
}
int getAge()
{
return age;
}
void setAge(int a)
{
age=a;
}
}
import java.util.Scanner;
public class StudentManager
{
public static void main(String[]args)
{
Student1 s=new Student1("张三",19);
System.out.println("age初始值为:"+s.getAge());
System.out.println("name初始值为:"+s.getName());
Scanner in=new Scanner(System.in);
System.out.println("请输入学生姓名:");
String name=in.next();
s.setName(name);
System.out.println("请输入学生年龄:");
s.setAge(in.nextInt());
System.out.println("age现在为:"+s.getAge());
System.out.println("name现在为:"+s.getName());
}
} 展开
{
String name;
int age;
Student1(String n,int a)
{
name=n;
age=a;
}
String getName()
{
return name;
}
void setName(String n)
{
name=n;
}
int getAge()
{
return age;
}
void setAge(int a)
{
age=a;
}
}
import java.util.Scanner;
public class StudentManager
{
public static void main(String[]args)
{
Student1 s=new Student1("张三",19);
System.out.println("age初始值为:"+s.getAge());
System.out.println("name初始值为:"+s.getName());
Scanner in=new Scanner(System.in);
System.out.println("请输入学生姓名:");
String name=in.next();
s.setName(name);
System.out.println("请输入学生年龄:");
s.setAge(in.nextInt());
System.out.println("age现在为:"+s.getAge());
System.out.println("name现在为:"+s.getName());
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询