亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

需要創建一個person類,請問該如何調用上面的方法?麻煩各位大神出手相救!

需要創建一個person類,請問該如何調用上面的方法?麻煩各位大神出手相救!

MMMHUHU 2021-07-20 17:15:57
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方法內的那兩句話, 但是我不知道該怎么樣調用上面的方法,程序運行到 輸入三個屬性之后就不繼續下去了。麻煩各位大神出手相救!
查看完整描述

3 回答

?
LEATH

TA貢獻1936條經驗 獲得超7個贊

不是Person.greeting()。 應該是 TestPerson.greeting();再就是你既然從鍵盤接收了這些值,景應該調用構造方法的時候傳進去。

查看完整回答
反對 回復 2021-07-25
?
滄海一幻覺

TA貢獻1824條經驗 獲得超5個贊

Person TestPerson=new Person(); 這個是你new出來的對象,調用時用TestPerson.greeting();還有個小建議,變量名一般小寫開頭。

查看完整回答
反對 回復 2021-07-25
  • 3 回答
  • 0 關注
  • 431 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號