Error in System.out.println

前端 未结 5 1515
独厮守ぢ
独厮守ぢ 2021-01-24 14:59

Is there any error in the following code? It shows cant find symbol, symbol: class out location: class System. In the log, it show a lot of errors, including

java.lang.

5条回答
  •  一向
    一向 (楼主)
    2021-01-24 15:26

    In java does not work like this any behaviour you want to implement you must do it inside a block or a method

    It needs to be inside an executable block of code to be executed. Otherwise there's no way to know when to execute it.

    Remember that a class can only have attributes or methods.Attributes are the properties of the class and methods represent the behaviour of the class.So every implementation goes inside a method or a block.

    The only things allowed outside method and constructor declarations are declarations of fields. Since

    Scanner sc=new Scanner(System.in);
    System.out.println("Enter the value of r");
    int r=sc.nextInt();
    System.out.println("enter the value h");
    int h=sc.nextInt();
    

    is not a field declaration, it's not allowed.

提交回复
热议问题