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();//這里開始是錯(cuò)的}}這是我的程序,題意是 要調(diào)用greeting的方法,輸出 greeting方法內(nèi)的那兩句話, 但是我不知道該怎么樣調(diào)用上面的方法,程序運(yùn)行到 輸入三個(gè)屬性之后就不繼續(xù)下去了。麻煩各位大神出手相救!
3 回答

LEATH
TA貢獻(xiàn)1936條經(jīng)驗(yàn) 獲得超7個(gè)贊
不是Person.greeting()。 應(yīng)該是 TestPerson.greeting();再就是你既然從鍵盤接收了這些值,景應(yīng)該調(diào)用構(gòu)造方法的時(shí)候傳進(jìn)去。

滄海一幻覺
TA貢獻(xiàn)1824條經(jīng)驗(yàn) 獲得超5個(gè)贊
Person TestPerson=new Person(); 這個(gè)是你new出來的對(duì)象,調(diào)用時(shí)用TestPerson.greeting();還有個(gè)小建議,變量名一般小寫開頭。
添加回答
舉報(bào)
0/150
提交
取消