I want to take a string input from keyboard. But when I ran this program there are no option to take string input. I don't know what my fault is.
Here my code is:
import java.util.Scanner;
public class Input_Program {
public static void main(String args[])
{
Scanner in = new Scanner(System.in);
int a,b;
System.out.println("Enter the first number :");
a=in.nextInt();
System.out.println("Enter the second number :");
b=in.nextInt();
System.out.println("Value of first number:"+a);
System.out.println("Value of second number:"+b);
System.out.println("Do you want Add two numbers");
System.out.println("To Continue: Type Yes");
String S=in.nextLine();
if("Yes".equals(S)||"yes".equals(S))
{
int sum=a+b;
System.out.println("Summation :"+sum);
}
}
}
I want to take an input from this code. But it's not working.
String S=in.nextLine();
if("Yes".equals(S)||"yes".equals(S))
{
int sum=a+b;
System.out.println("Summation :"+sum);
}
And the result of this code is :
run:
Enter the first number :
2
Enter the second number :
3
Value of second number:3
Do you want the Summation of two numbers
To Continue: Type Yes
BUILD SUCCESSFUL (total time: 9 seconds)