Results 1 to 2 of 2
  1. #1
    Tb0h is offline Member
    Join Date
    Jul 2009
    Rep Power

    Talking Integer troubles again...

    I have just built a new computer, so I was installing Java and I'm trying the NetBeans IDE for a change instead of Eclipse. I haven't used Java much, so I'm kind of rusty. I tried making a simple program to refresh myself, and I failed epicly. There were no errors in the code below, but when I ran the code, the JOptionPane popped up. I entered the three things, and what was displayed to me was a bunch of gibberish. What have I done wrong? Here is the code. Thanks.
    P.S. Don't provide a whole new code, please just tell me what I did wrong :)
    Java Code:
    package multipliergreeter;
    import javax.swing.JOptionPane;
    import java.util.Scanner;
    public class Main {
        public static void main(String[] args) {
            Scanner myScanner = new Scanner(;
            String name;
            JOptionPane.showInputDialog(null, "Please enter your name.");
            String a;
            a = JOptionPane.showInputDialog("Enter a number");
            String b;
            b = JOptionPane.showInputDialog("Enter a second number.");
            int a1 = Integer.parseInt(a);
            int b1 = Integer.parseInt(b);
            int p = a1+b1;
            JOptionPane.showMessageDialog(null,""+myScanner+", "+a+" plus "+b+" equals "+p+".","Output",JOptionPane.INFORMATION_MESSAGE);

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Blog Entries
    Rep Power


    1) You don't do anything with the string entered into the first JOptionPane.
    2) What do you expect myScanner will show when you try to display this object in your final JOptionPane?

Similar Threads

  1. JOptionPane Troubles
    By Tb0h in forum New To Java
    Replies: 4
    Last Post: 08-26-2009, 01:12 PM
  2. Integer troubles
    By Tb0h in forum New To Java
    Replies: 11
    Last Post: 08-13-2009, 04:56 PM
  3. Gif decoding/LZW troubles
    By hellochar in forum Advanced Java
    Replies: 2
    Last Post: 07-14-2009, 11:26 PM
  4. Image troubles
    By Theodoreb in forum New To Java
    Replies: 24
    Last Post: 07-14-2009, 12:41 AM
  5. subclass troubles
    By xf021209 in forum New To Java
    Replies: 12
    Last Post: 04-20-2009, 11:46 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts