GratefulDeadpoo
May 23, 2016, 03:47 PM
I'm creating a program where it detects whether an inputted number matches one of the pre-defined formats. Every time I execute my code and input a number, it will say "Invalid input." I'm not sure if it's due to boolean logic or me not using DecimalFormat correctly. Here's the code I have thus far:
do
{
System.out.println("Enter the amount you wish to deposit ==>> $");
amount = inputDW.nextLine();
moneyInput = new DecimalFormat (amount);
corInput1 = new DecimalFormat ("000.00");
corInput2 = new DecimalFormat ("00.00");
corInput3 = new DecimalFormat ("0.00");
if((moneyInput.equals(corInput1) == false) && (moneyInput.equals(corInput2) == false) && (moneyInput.equals(corInput3) == false))
{
System.out.println("Invalid input");
}
}
while((moneyInput.equals(corInput1) == false) && (moneyInput.equals(corInput2) == false) && (moneyInput.equals(corInput3) == false));
Note: It's obviously only part of my entire code for the program.
do
{
System.out.println("Enter the amount you wish to deposit ==>> $");
amount = inputDW.nextLine();
moneyInput = new DecimalFormat (amount);
corInput1 = new DecimalFormat ("000.00");
corInput2 = new DecimalFormat ("00.00");
corInput3 = new DecimalFormat ("0.00");
if((moneyInput.equals(corInput1) == false) && (moneyInput.equals(corInput2) == false) && (moneyInput.equals(corInput3) == false))
{
System.out.println("Invalid input");
}
}
while((moneyInput.equals(corInput1) == false) && (moneyInput.equals(corInput2) == false) && (moneyInput.equals(corInput3) == false));
Note: It's obviously only part of my entire code for the program.