Results 1 to 6 of 6
- 12-24-2012, 11:06 AM #1
Member
- Join Date
- Dec 2012
- Location
- Netherlands
- Posts
- 4
- Rep Power
- 0
Print integer Array values into a single !, showMessagedialog
Hello, dear programmers
"I began this year with java, and i have a question about how to print the values of an integer Array into a Single showMessageDialog. The issue is that the program is printing the values in different shoMessageDialogs. "
The program is meant to find the random value in the Random int variable
This is my code:
Java Code:package testa; import javax.swing.*; import java.util.*; import java.lang.*; public class Testa { public static void main(String[] args){ int Random = (int)(Math.random()*10); int[] Array = new int[10]; Scanner read = new Scanner(System.in); // start programm read 10 ints into array for(int index = 0; index<Array.length;index++){ Array[index] = read.nextInt(); if(Array[index]>Random) { System.out.println("You are higher"); } else if(Array[index]<Random) { System.out.println("You are lower"); } if(Array[index]==Random) { System.out.println("Good job! you found the searching number " + Random); for(int i =0; i < Array.length;i++) { if(Array[i]!=0) { JOptionPane.showMessageDialog(null, "You Have Entered the values:"+Array[i]); } } break; } if(index == 9) { System.out.println("You are failed bitch!"); break; } } };.gif)
Iam very glad if you can help me
- 12-24-2012, 01:25 PM #2
AN21XX
- Join Date
- Mar 2012
- Location
- Munich
- Posts
- 297
- Rep Power
- 2
Re: Print integer Array values into a single !, showMessagedialog
Ah and... where is your problem in printing it in one single dialog?
I like likes!.gif)
- 12-24-2012, 01:58 PM #3
Member
- Join Date
- Dec 2012
- Location
- Netherlands
- Posts
- 4
- Rep Power
- 0
- 12-24-2012, 02:33 PM #4
AN21XX
- Join Date
- Mar 2012
- Location
- Munich
- Posts
- 297
- Rep Power
- 2
Re: Print integer Array values into a single !, showMessagedialog
Make a String variable, put all that is output in multiple dialogs currently, into one large string... should not be a difficult task as you have all there:
- Join strings by the plus sign ( "You Have Entered the values:\n" + Array[i]
- Show the dialog ( JOptionPane.showMessageDialog(...) )
- A loop ( for (...) )
Sorry, where is your problem? You go through the loop, join all strings together in a variable of type String. Move the message dialog out of the loop as you do not want multiple... and there you go.
Show a message dialog showing the string... separate maybe the lines by the "\n" character: for ( ... ) myOutput += myLine + "\n";I like likes!.gif)
- 12-24-2012, 02:56 PM #5
Member
- Join Date
- Dec 2012
- Location
- Netherlands
- Posts
- 4
- Rep Power
- 0
Re: Print integer Array values into a single !, showMessagedialog
I did this one:
for(int i =0; i < Array.length;i++)
{
if(Array[i]!=0)
{
JOptionPane.showMessageDialog(null, "You Have Entered the values:\n"+Arrays.toString(Array));
break;
}
This absolute works, it displays 1 single popup, but i dont want to see the 0 values. How can I remove the 0 values, i dont want to display them
- 12-24-2012, 02:57 PM #6
Member
- Join Date
- Dec 2012
- Location
- Netherlands
- Posts
- 4
- Rep Power
- 0
Similar Threads
-
How to print the integer value of char : '
By fatabass in forum New To JavaReplies: 2Last Post: 04-03-2012, 11:08 PM -
How to Print every tenth integer in my output
By jim01 in forum New To JavaReplies: 13Last Post: 04-16-2011, 03:00 AM -
cant print 2d array(giving null values)
By fneeks in forum New To JavaReplies: 1Last Post: 04-07-2010, 08:48 PM -
An Array of different integer values
By lithium002 in forum New To JavaReplies: 7Last Post: 12-04-2009, 05:25 AM -
How to make print function for single label?
By makpandian in forum AWT / SwingReplies: 2Last Post: 02-12-2009, 05:26 PM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote


Bookmarks