View Single Post
  #2 (permalink)  
Old 03-20-2008, 12:12 AM
rhm54 rhm54 is offline
Member
 
Join Date: Jan 2008
Posts: 12
rhm54 is on a distinguished road
It should look something like this:

Code:
public class numbert { public static void main(String[] args) { String inData; int num ,num2; int sum; int avg; inData = JOptionPane.showInputDialog (null, "Enter an Integer Value.") ; num = Integer.parseInt (inData); // convert inData to int inData = JOptionPane.showInputDialog (null, "Enter another Integer Value."); num2 = Integer.parseInt (inData); sum=num + num2; avg= sum/2; System.out.println ("Sum of both numbers:" +sum); System.out.println ("The average is:" +avg); System.out.println ("Good-bye for now, suckahfish!"); //always executed } }
The problem was you were trying to intialize sum and avg with the variables num and num2 before you had values there.
Reply With Quote