The answer is simple, you are trying to work with variable that doesn't exist. Let's just say, that the first if returns false
, then variable name1
never initializes.
if(name.equalsIgnoreCase("...")) { // doesn't equal
System.out.print("...");
float name1 = SIn.readFloat(); // not initialized
} else if(name.equalsIgnoreCase("...")){
System.out.print("...");
float name2 = SIn.readFloat();
}
try {
float converted = name1 * valueget; // using non-existing variable
System.out.println(...);
}
What you should do is, declare a variable before that if-else
statement and initialize it inside the if-else
.
float floatName = 0; // set it up as zero, because you don't have else statement
if(name.equalsIgnoreCase("...")) {
System.out.print("...");
floatName = SIn.readFloat();
} else if(name.equalsIgnoreCase("...")){
System.out.print("...");
floatName = SIn.readFloat();
}
try {
float converted = floatName * valueget;
System.out.println(...);
}