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

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

帶有方法聲明的表達式的非法開頭

帶有方法聲明的表達式的非法開頭

溫溫醬 2023-03-02 10:20:39
使用 javac 編譯這個簡單的代碼,它給了我以下錯誤Test3.java:38: 錯誤:表達式的非法開始public static int minFun (int a, int b) {我嘗試在 main 之外聲明變量(即 public static int a、b、c),但沒有任何改變。這讓我感到困惑,因為我在學習本教程時使用了一個非常相似的示例代碼。在此先感謝您的幫助。  // Program to output the minimum of two integer numbers  import java.io.*;  public class Test3 {  public static void main (String args[]) {          int a, b, c;          String rA, rB;          InputStreamReader input = new InputStreamReader (System.in);          BufferedReader keyboard = new BufferedReader (input);          System.out.println ("Please, enter two integer numbers.");          try {                  rA = keyboard.readLine ();                  a = Integer.parseInt (rA);                  rB = keyboard.readLine ();                  b = Integer.parseInt (rB);          }          catch (IOException e) {                  System.err.println ("Not a proper integer number.");          }          catch (NumberFormatException e) {                  System.err.println ("Not a proper integer number.");          }          c = minFun (a, b);          if (a != b) {                  System.out.println ("The smaller number is " + c);          }          else {                  System.out.println ("The two numbers are equals.");  }  public static int minFun (int a, int b) {          int min;          if (a < b) {                  min = a;          }          else {                  min = b;          }          return min;  }  }
查看完整描述

1 回答

?
PIPIONE

TA貢獻1829條經驗 獲得超9個贊

     if (a != b) {

              System.out.println ("The smaller number is " + c);

      }

      else {

              System.out.println ("The two numbers are equals.");

      } // <----- was not present

這里的這一行缺少花括號。


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

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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