I am new in Java im having a hardtime solving the problem in the "response = first.nextint(); and response = second.nextint();" and if i removed response first and second the code works but cant read the conditions if else when inputing a random number and a Indicated letters inside the if else.
import java.util.Scanner;
public class scanMe
{
public static void main (String[] args)
{
int first = '.';
int second = '.';
String response = ".";
Scanner scanMe = new Scanner(System.in);
System.out.println("Please input first Number: ");
response = first.nextint();
System.out.println("Please input second Number: ");
response = second.nextint();
System.out.println("Please Press A for Addition");
System.out.println("Please Press B for Subtraction");
System.out.println("Please Press C for Multiplication");
System.out.println("Please Press D for Division");
System.out.print("Input any letter: ");
response = scanMe.nextLine();
if(response ==("A")){
System.out.println("The Result is first+second");
}
else if(response ==("B")){
System.out.println("The Result is first+second");
}
else if(response ==("C")){
System.out.println("The Result is first+second");
}
else if(response ==("D")){
System.out.println("The Result is first+second");
}
else
System.out.println("Letter cannot be identify and is not registered to any function");
}
}
>Solution :
Your response is declared as string and the Scanner.nextInt() method returns an int. Change the type of response to int:
int response = 0;
Another issue with your code, you should invoke scanMe.nextInt(), not intvaraible.nextInt()