Results 1 to 4 of 4
Thread: output shows null !!!!
- 12-09-2012, 11:35 PM #1
Member
- Join Date
- Dec 2012
- Posts
- 1
- Rep Power
- 0
output shows null !!!!
hi all
can anyone tell me whats wrong with the code... the output gives only null rather than the supposed output
Java Code:public class FDebugEight4 { public static void main(String[] args) { int x = 0, y; String[] array = new String[100]; String entry; final String STOP = "XXX"; StringBuffer message = new StringBuffer("The words in reverse order are\n"); entry = JOptionPane.showInputDialog(null, "Enter any word\n" + "Enter " + STOP + " when you want to stop"); while(!(entry.equals(STOP))) //keep asking for word till XXX is inputed { array[x] = entry; x++; entry = JOptionPane.showInputDialog(null, "Enter another word\n" + "Enter " + STOP + " when you want to stop"); } for( y = x; y > 0 ; --y) { message.append(array[y]); message.append("\n"); } JOptionPane.showMessageDialog(null, message); } }
-
Re: output shows null !!!!
What line shows null and in what way?
- 12-11-2012, 03:07 PM #3
Member
- Join Date
- Dec 2012
- Posts
- 26
- Rep Power
- 0
Re: output shows null !!!!
Where does it say null?
- 12-11-2012, 10:15 PM #4
Member
- Join Date
- Dec 2012
- Posts
- 74
- Rep Power
- 0
Re: output shows null !!!!
When the user clicks the cancel button, you get a null. So all you have to do is to check to see if entry == null.
Java Code:import javax.swing.JOptionPane; public class FDebugEight4 { public static void main(String[] args) { int x = 0, y; String[] array = new String[100]; String entry; final String STOP = "XXX"; StringBuffer message = new StringBuffer("The words in reverse order are\n"); entry = JOptionPane.showInputDialog(null, "Enter any word\n" + "Enter " + STOP + " when you want to stop"); while(entry != null && !(entry.equals(STOP))) //keep asking for word till XXX is inputed { array[x] = entry; x++; entry = JOptionPane.showInputDialog(null, "Enter another word\n" + "Enter " + STOP + " when you want to stop"); } for( y = x; y > 0 ; --y) { message.append(array[y]); message.append("\n"); } JOptionPane.showMessageDialog(null, message); } }
Similar Threads
-
Unwanted Null output.
By steinarsen in forum New To JavaReplies: 8Last Post: 11-08-2012, 10:01 AM -
I am created this program.but it shows null pointer exception...can any one help me..
By vetrivelmanian in forum Threads and SynchronizationReplies: 3Last Post: 07-26-2011, 11:30 AM -
how do you create application using JAVA codes? in IDE, it just shows output
By learning_grjava in forum New To JavaReplies: 3Last Post: 07-09-2011, 01:21 PM -
output shows undesired results(advice ?)
By jasperFernandes in forum New To JavaReplies: 0Last Post: 03-10-2011, 02:32 AM -
Program can run but output all null
By matt_well in forum New To JavaReplies: 15Last Post: 07-24-2008, 08:48 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks