为了账号安全,请及时绑定邮箱和手机立即绑定

带有方法声明的表达式的非法开头

带有方法声明的表达式的非法开头

温温酱 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 关注
  • 127 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号