I’m writing a program in the Java language, and I’m using if else statement. In this program i need to input word(s), i.e., alphabet character that has been assigned to be the values of the String data type. So that the program will print the sequential if statement, but is seems that program is not recognizing the input, because it keep printing only else statement. I need to know how to assign String values in Java language, import java.util.Scanner;
on an if else Statement algorithm.
import java.util.Scanner;
public class Compare
{
public static void main (String []args)
{
Scanner input = new Scanner(System.in);
String name = “Henry”;
System.out.println(“Enter a NAME”);
name = input.nextLine();
If ( name = “Henry”)
System.out.println(“Welcome Henry”);
else
System.out.println(“Invalid Input”);
}
}
When i run it in CMD:
C:\CODE>java Compare
Enter a NAME:
Henry
Invalid Input
It doesn’t accept the String value “Henry” thats why the else statement keeps displaying “Invalid Input”.
Aucun commentaire:
Enregistrer un commentaire