I'm trying to read in two floats but I'm not allowed to assign num1 or num2 to the input dialog box. Therefore, I'm having to assign the string variable msg to my input dialog box and then covert msg back over to a float and assign it to my float variables. whew! that was sentence.
How can I reduce the complexity of this by just reading in num1 and num2 from the start?
Please disregard commented out sections.
import javax.swing.*; public class Week_4_test1 { //public Week_4_test1(){} public static void main(String[] args) { float sum = 0.0f; float num1 = 0.0f; float num2 = 0.0f; //needs to be done because we are creating it dynamically //String prompt = "Enter your name: "; //Scanner me = new Scanner(System.in); //System.out.printf("Enter your name: "); //String name = me.nextLine(); String msg = ""; //System.out.printf("Welcome To Java..."); //System.out.print(name + "\n"+ msg + "\n"); //JOptionPane.showMessageDialog(null, "Again, welcome to Java" + name); //JOptionPane.showInputDialog(null, prompt); //JOptionPane.showMessageDialog(null, "Another LIne " + name); msg = JOptionPane.showInputDialog(null, "Enter num1"); num1 = Float.parseFloat(msg); msg = JOptionPane.showInputDialog(null, "Enter num1"); num2 = Float.parseFloat(msg); sum = num1 + num2; JOptionPane.showMessageDialog(null, "The sume of " + num1 + " + " + num2 + " is " + sum); } }