You need to wrap your next code in a block (either method or static).
BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); System.out.println("What is your name?"); String name = in.readLine(); ; System.out.println("Hello " + name);
Without a block, you can only declare variables and more than assign them a value in a single expression.
For the main () method, there will now be a better choice:
public class details { public static void main(String[] args){ BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); System.out.println("What is your name?"); String name = in.readLine(); ; System.out.println("Hello " + name); } }
or If you want to use a static block, then ...
public class details { static { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); System.out.println("What is your name?"); String name = in.readLine(); ; System.out.println("Hello " + name); } }
or if you want to create another method, then ..
public class details { public static void main(String[] args){ myMethod(); } private static void myMethod(){ BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); System.out.println("What is your name?"); String name = in.readLine(); ; System.out.println("Hello " + name); } }
Also worry about exception due to BufferedReader.
source share