Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-29-2008, 11:11 PM
Member
 
Join Date: Aug 2008
Posts: 2
Rep Power: 0
mandalay92 is on a distinguished road
Default Can't Remember How to Do This
In programming class, we just learned some very simple java. However, now I can't remember the code! Can someone tell me what I'm doing wrong?
import javax.swing.JOptionPane;


public class InputOutput {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub

System.out.println("Hello World!");//Output
int num1;
int num2;
int sum;
string input1;
string input2;

System.out.println("Enter an integer.");
input1=JOptionPane.showInputDialog("Input an integer...");
input2=JOptionPane.showInputDialog("Input another.");
num1=Int.parseInt(input1);
num2=Int.parseInt(input2);
sum=num1+num2;
System.out.println("The sum is"sum);

}

}
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 08-30-2008, 01:27 AM
Member
 
Join Date: Aug 2008
Posts: 4
Rep Power: 0
ruuebs is on a distinguished road
Default
You need to fix the following:

- Add the code
Code:
Import javax.swing*;
to the top of the class because you're using JOptionPane from the Swing libarary.

- The String Class is always spelt with a capital S, like all class names.

-
Code:
Integer.parseInt(input1);
Not
Code:
Int.parseInt(input1);
(int is a prmitive data type while Integer is an Object wrapper class)

-and lastly you need to use the + sign to add something to a String like:
Code:
System.out.println("The sum is " + sum);
Hope that helps.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 08-30-2008, 02:12 AM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: SouthWest Missouri, USA
Posts: 2,229
Rep Power: 4
Norm is on a distinguished road
Default
If you are getting errors, please copy and post the full text of the error message here.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 08-30-2008, 03:24 AM
Member
 
Join Date: Aug 2008
Posts: 2
Rep Power: 0
mandalay92 is on a distinguished road
Default
Thanks! I figured it was something like this.
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
JFileChooser remember the location Mr tuition AWT / Swing 3 12-08-2007 06:17 PM
how to have function variables remember their values between calls asterik123 New To Java 2 08-03-2007 05:06 PM


All times are GMT +2. The time now is 02:42 PM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org