I just started using Eclipse and I'm quite new to Java. I have a block of code which won't compile because the random number I generated won't cast in to an integer. The error message reads "This method must return a result of type int" on line two in the following block of code.
public class passwordHelper {
public int rNum(String nums, String lets){
int z;
if(nums == "yes" && lets == "yes"){
z = (int)Math.random()*36;
return z;
} else if(nums == "yes"){
z = (int)Math.random()*10;
return z;
} else if(lets == "yes"){
z = (int)Math.random()*26 + 10;
return z;
} else {
System.out.println("Sorry, you need either letters or numbers in your password.");
}
}
}
As you can see I am using the "(int)" function to cast my number to an integer but it sends me the same error message, I have also tried using other methods of casting, such as "Math.floor()", "Math.round()" and combinations of all the three. And if anyone wants to know this is part of a code to generate a random string of numbers and letters for the user.
//Thanks for any help