import java.util.Scanner;class Person{static String name;static int age;static double height;static String your_name;void Person(String name,String your_name,int age,double height){this.name=name;this.age=age;this.height=height;this.your_name=your_name;}public void greeting(){System.out.println("Hello,my name is"+name+",I am"+age+",and I am"+height+"meters tall."); }public void greeting2(String yourName){System.out.println("hello"+your_name+",my name is"+name+",I am"+age+",and I am"+height);}}public class TestPerson{public static void main(String[] args){Person TestPerson=new Person();Scanner in=new Scanner(System.in);System.out.println("There are three attributes defined for a person:name-String, age=integer, and height-cm.");System.out.println("Enter the first person's attributes<on the same line separated by a space>");String name1=in.next();int age1=in.nextInt();double height1=in.nextDouble();System.out.println("Enter the Second person's attributes<on the same line separated by a space>");String name2=in.next();int age2=in.nextInt();double height2=in.nextDouble();String your_name=name1;Person.greeting();//这里开始是错的}}这是我的程序,题意是 要调用greeting的方法,输出 greeting方法内的那两句话, 但是我不知道该怎么样调用上面的方法,程序运行到 输入三个属性之后就不继续下去了。麻烦各位大神出手相救!
添加回答
举报
0/150
提交
取消