Я новый программист в целом, так что простите меня, если эта проблема является честной базой.Класс закрытого символа рядом с индексом 525
Цель этой программы - простой расчет «оптимального веса тела» и постоянно выдает исключение во время выполнения по сравнению с сравнениями строк a и b в строке 35. Я попытался удалить логические операторы, и это все еще не кажется быть проблемой. Где я ошибаюсь?
import java.util.*;
public class WeightCalc {
//Initialize variables
static int feet = 0, inches = 0, totalWeight = 0;
static boolean isMale;
public static void optimalWeight(){
// Calculate optimal weight
if (isMale == true){
if (feet >= 5){
totalWeight = 106 + 6*(inches);
} else{
System.out.print("Error, you're a midget.");
}
}
if (isMale == false){
if (feet >= 5){
totalWeight = 100 + 5*(inches);
} else{
System.out.print("Error, you're a midget.");
}
}
}
public static void main(String[] args){
String a = "Male", b = "male";
// Initialize kboard Scanner
Scanner kboard = new Scanner(System.in);
// Ask for gender and assign isMale
System.out.println("What is your gender? ");
String gender = kboard.nextLine();
if (gender.equals(a) || gender.equals(b)){
isMale = true;
}else {
isMale = false;
}
// Ask for height, first feet, then inches
System.out.println("What is your height in regards to feet? ");
kboard.nextInt(feet);
System.out.println("What is your remaining h eight in inches? ");
kboard.nextInt(inches);
//Call optimalWeight method and run
optimalWeight();
// Print the output
System.out.println("Your optimal weight should be " + totalWeight + ".");
// Set isMale opposite to what it was before and calculate opposite sex's potential weight
isMale = !isMale;
optimalWeight();
// Print the output of the second run
System.out.println("If you were of the opposite sex, your weight would be " + totalWeight + ".");
// Close the Scanner variable
kboard.close();
}
}
Что является линия 35? 'if (gender.equals (a) || gender.equals (b)) {'? И что такое исключение? –
Не сравнивайте булевы с помощью 'a == true' или' a == false'. Просто используйте 'a' или'! A'. –
http://stackoverflow.com/questions/21816788/unclosed-character-class-error –