+ 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"); } } }}
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)
+ 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");
}
}
+ 1
There is no error in the program but whenever I run it it says "no output"..
+ 1
So nice aj anant
+ 1
Oh ! Thanks alot AJ Anant