我在输入此代码时收到无法访问的代码错误。我不确定为什么,是因为我在这个If语句中没有Else?接收Java无法访问的代码
import java.util.InputMismatchException;
import java.util.Scanner;
public class pickNumbers {
Scanner readInput = new Scanner(System.in);
float[] pickNumbers(int choice) {
float[] myFloats = new float[2];
do { // do loop will continue until user enters correct response
System.out.print("Please enter 2 numbers separated by a space in the formats of floats: "); // will prompt user to enter 2 floats
try {
myFloats[0] = readInput.nextFloat(); // will read first float entered
myFloats[1] = readInput.nextFloat(); // will read second float entered
if (choice == 4 && myFloats[1] == 0.0f)
;
{
System.out.println("Cannot complete calculation. Cannot divide by 0, please try again.");
myFloats[0] = myFloats[1] = 0.0f;
continue;
}
break; // i am receiving an error here saying unreachable code and i don't know why
} catch (final InputMismatchException e) {
System.out.println("You have entered an invalid input. Try again.");
readInput.nextLine(); // discard input that is not a float
continue; // loop will continue until the correct answer is found
}
} while (true);
return myFloats; // an an unreachable error here also
}
}
谢谢你,现在的工作 – userQuestion 2014-11-03 05:33:52