Bank account management program

+1 Arnab Banerjee · February 12, 2015
Even though I am typing saving or current it is giving result as NOT SET.


System.out.println("Enter account type ");
type = x.nextLine();
if(type=="Savings" || type == "savings"){
System.out.println(" account type entered correctly");
}
else if(type == "Current" || type == "current"){
System.out.println("Account type entered correctly");
}
else
type = "NOT SET";


Post a Reply

Replies

Oldest  Newest  Rating
+1 guga katsiashvili · February 12, 2015
just change == to .equals(); :)
+1 guga katsiashvili · February 12, 2015
just change  type == to type.equals("savings") ....
+1 Rian F · February 12, 2015
Okay, I see your problem now let's fix it. In Java the double equals sign (==) is used for comparing numbers and booleans. To compare strings you should use something like the matches method that is specified in the String class in the Java API. So lets see how to fix it.

System.out.println("Enter account type ");
type = x.nextLine();
x.toLowerCase(); //this saves having to write an or condition in the if statements
if(type.matches("savings")) //matches method will check if one string is the same as the other
     System.out.println(" account type entered correctly");
  • 1

Java / Android Development

107,153 followers
About

Very popular language used to create desktop applications, website applets, and Android apps.

Links
Moderators
Bucky Roberts Administrator