+ 2

Input in java

how do we add an input to a java programme just like "cin" in c++??is there a such an easy way in java?

19th Oct 2017, 1:28 PM
Akila Godigamuwa
Akila Godigamuwa - avatar
2 Answers
+ 5
you need to import java.util.scanner package..then... Scanner sc=new Scanner(System.in); String text=sc.next();//For taking string as input. You may use any name instead of sc..
19th Oct 2017, 1:39 PM
Md. Nafis Ul Haque Shifat
Md. Nafis Ul Haque Shifat - avatar
+ 8
For example for integer it could be: import java.util.Scanner ... int a = new Scanner(System.in).nextInt();
19th Oct 2017, 1:39 PM
Vukan
Vukan - avatar