+ 1

How do I take input from the user?

I am working in a program and I want to have take input from the user ,so please help me, Below is my program please tell where to edit or what to do to get input from the user using Int method. public class Program { public static void main(int n) { if (n==1) System.out.println("hi"); { if (n==2) System.out.println("hell"); { if (n==3) System.out.println("g"); } } }}

6th Jun 2020, 5:14 AM
Aryan Goel
Aryan Goel - avatar
5 Answers
+ 4
Aryan Goel Use Scanner class. Scanner sc = new Scanner (System.in); int n = sc.nextInt(); Btw public static void main(int n) should be public static void main(String[] args)
6th Jun 2020, 6:36 AM
A͢J
A͢J - avatar
+ 4
Aryan Goel See this import java.util.*; public class Program { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); main(n); } public static void main(int n) { if(n == 1) System.out.println("Hi"); else if(n == 2) System.out.println("Hello"); else System.out.println("Bye"); } }
6th Jun 2020, 6:40 AM
A͢J
A͢J - avatar
+ 1
There is no error in the program but whenever I run it it says "no output"..
6th Jun 2020, 5:15 AM
Aryan Goel
Aryan Goel - avatar
+ 1
So nice aj anant
6th Jun 2020, 6:38 AM
Prahlad Gaur
Prahlad Gaur - avatar
+ 1
Oh ! Thanks alot AJ Anant
6th Jun 2020, 7:14 AM
Aryan Goel
Aryan Goel - avatar