Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to use a for loop or any iteration in JOptionPane message dialogue?  RSS feed

 
Jaypee Hernandez
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Java developers.
I would like to ask what is the code or what to do to show the result of a for loop (or just any other iterations) in a JOptionPane message dialogue box?

Here is the code, and I want to show the factored numbers in a JOptionPane message dialogue box..
http://pastebin.com/kCySiviv

Any help is appreciated

Jaypee
 
Campbell Ritchie
Sheriff
Posts: 55333
157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

We do not simply provide complete solutions; please post the code here, and we'll have a look at it. You seem to have a factorial program. What do you need to show on an option pane?
 
Jaypee Hernandez
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry sir, my bad for posting a link.
Here's my factorial code in java:



I want to stress out this code:

where it should be an output in a JOptionPane message dialogue and not in the console.

Thank your sir for the help and for upcoming solutions

Cheers,
Jph
 
Campbell Ritchie
Sheriff
Posts: 55333
157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That isn't a factorial program: don't call the method factorial2.
Don't use shorts (or Shorts) for arithmetic. Use ints.
What do you expect if you factorise 480?

Do you mean something like appending the numbers to create a String something like this?
Factors of 128: 1 2 4 8 16 32 64 128
I think 1 does not count, just as 1 doesn't count as a prime number.
Are you aware of the StringBuilder class, or the new StringJoiner which adds a separator between successive values? I think those might help. Note those underlined words are links.
 
Jaypee Hernandez
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank for those who've comment.

I resolved this issue on my own and must now be closed.

The code that I've applied is that, I used a String on which I've stored the strings to be appended and to be finally posted in the message dialogue box and engaged it in the iteration process to create a storing method.
Anyways, thank you for your comments and it is very much appreciated by me.

Cheers,
Jph
 
Liutauras Vilda
Marshal
Posts: 4491
306
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
John Paul Hernandez wrote:I resolved this issue on my own and must now be closed.
Well done.

I hope you got separate method to do so, rather than one "main" method to do everything.
There are more ways to do it, but one could look simply like this:
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shorter:JOptionPane is array-aware.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!