该语句
System.out.println("");应写在某些块中。不能直接在课堂上写。public class ClassName { System.out.println("this statement gives error"); // Error!! }它应该放在大括号内,
{...}例如:{ System.out.println("this works fine"); }这种方式是一个初始化程序块。
或应使用类似以下的方法编写:
public void methodName(){ System.out.println("inside a method, prints fine");}您的完整程序 应类似于:
public class Area {double pi = 3.14;int r;int h;void areaOfCircle() { double area1 = pi * r * r; System.out.println("area of circle=" + area1);}void areaOfCylinder() { double area2 = 2 * pi * r * (r + h); System.out.println("area of cylinder=" + area2);}public static void main(String args[]) { Scanner sc = new Scanner(System.in); System.out.println("Enter the value of r"); Area a = new Area(); a.r = sc.nextInt(); System.out.println("enter the value h"); a.h = sc.nextInt(); a.areaOfCircle(); a.areaOfCylinder(); }}


