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

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

如何調用total的值,并輸出

如何調用total的值,并輸出

菜鳥555 2016-03-26 11:07:24
import javax.swing.JOptionPane;public class Student { String xh,name; int yy,math,yw,total; Student(String xh1,String name1){ xh=xh1; name=name1; } Student(String xh1,String name1,int yy1,int math1,int yw1){ xh=xh1; name=name1; yy=yy1; math=math1; yw=yw1; } public void display(){ String str=JOptionPane.showInputDialog("請輸入英語成績:"); yy=Integer.parseInt(str); str=JOptionPane.showInputDialog("請輸入數學成績:"); math=Integer.parseInt(str); str=JOptionPane.showInputDialog("請輸入語文成績:"); yw=Integer.parseInt(str); JOptionPane.showMessageDialog(null,"學號:"+xh+"\n姓名:"+name+"\n數學:"+math+"\n英語:"+yy+"\n語文:"+yw+"\n總成績"+total); } public void sum(){ total=yy+yw+math; } public static void main(String[] args) { Student t1=new Student("xxx", "xxx"); t1.display(); } }
查看完整描述

1 回答

?
littleOStar

TA貢獻28條經驗 獲得超4個贊

看圖

http://img1.sycdn.imooc.com//5726d2ac00016bea07660427.jpg


你只是聲明了全局變量, 但沒有調用

查看完整回答
反對 回復 2016-05-02
  • 1 回答
  • 0 關注
  • 1332 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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