Initializing a variable in an if-statement in java?
问题 I keep getting an error variable F3 may have not been intialized on the last line of code you see. What am I doing wrong? { Float F1,F2, F3; F1 = Float.parseFloat( JOptionPane.showInputDialog("Enter a number and press ok.")); F2 = Float.parseFloat( JOptionPane.showInputDialog("Enter a second number and press ok.")); if(F1 >= F2) { F3=(F1 * F2) + (F1 * 2); } if(F2 >= F1) { F3 =(F1 + F2) + (F2 * 5); } DecimalFormat dec = new DecimalFormat("##.##"); JOptionPane.showMessageDialog(null,"Your