Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-16-2012, 01:25 AM   PM User | #1
dannyboi
New Coder

 
Join Date: Jul 2012
Location: NYC
Posts: 23
Thanks: 1
Thanked 0 Times in 0 Posts
dannyboi is an unknown quantity at this point
"variable input might not have been initialized" ? Saying that after if statement?

Code:
import java.util.Scanner;
import javax.swing.JOptionPane;
public class Main {
static Scanner sc = new Scanner (System.in); 
public static void main (String [] args) { 


int number = 2;
String input;

while (true)
{
  JOptionPane.showMessageDialog(null, number + "");
JOptionPane.showInputDialog(null,"Do you want to keep counting " + " Y or N");


if (input.equalsIgnoreCase("N"))
    break;
number +=2;
        JOptionPane.showMessageDialog(null, "\nWhew! That was close.\n");
        
}

}

}

Last edited by dannyboi; 08-16-2012 at 01:27 AM..
dannyboi is offline   Reply With Quote
Old 08-16-2012, 04:10 AM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
if (input.equalsIgnoreCase("N")). Input cannot match this, ever. It is null and never assigned any different value, and the compiler knows this. You can fix it by initializing its value to an empty string.

JOptionPane.show* messages will return a result for you to work with. Strings for input, and integers for confirmation and option dialogs.
Fou-Lu is offline   Reply With Quote
Old 08-16-2012, 04:16 PM   PM User | #3
dannyboi
New Coder

 
Join Date: Jul 2012
Location: NYC
Posts: 23
Thanks: 1
Thanked 0 Times in 0 Posts
dannyboi is an unknown quantity at this point
ok, I still am running into the variable input problem
dannyboi is offline   Reply With Quote
Old 08-16-2012, 04:25 PM   PM User | #4
dannyboi
New Coder

 
Join Date: Jul 2012
Location: NYC
Posts: 23
Thanks: 1
Thanked 0 Times in 0 Posts
dannyboi is an unknown quantity at this point
Quote:
JOptionPane.show* messages will return a result for you to work with. Strings for input, and integers for confirmation and option dialogs.
ANd what does this mean?
dannyboi is offline   Reply With Quote
Old 08-16-2012, 05:35 PM   PM User | #5
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Quote:
Originally Posted by dannyboi View Post
ANd what does this mean?
The signature for input dialog off of JOptionPane is:
Code:
public static String showInputDialog(Component, Object);
public static String showInputDialog(Component, Object, Object);
public static String showInputDialog(Component, Object, String, int);
Every one of these returns a string.

The final one:
Code:
public static Object showInputDialog(Component, Object, String, int, Icon, Object[], Object);
Returns an object. It's used for selections though, not direct input.
Fou-Lu is offline   Reply With Quote
Reply

Bookmarks

Tags
java, java programming

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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

Forum Jump


All times are GMT +1. The time now is 05:13 AM.


Advertisement
Log in to turn off these ads.