Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Showing the factors of a number in JOptionPane.  RSS feed

 
Cygnus de los Santos
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there I'm new here and this should be my first post.
So I need to write a program that would accept an integer and show it's factors in JOptionPane. So far this is my code..



This is a program that I wrote before, so what I need is something that has the output as this one but it should show in a JOptionPane window.


Thank you for taking the time to read this.
 
Knute Snortum
Sheriff
Posts: 4073
112
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch!

First, write down the steps to factoring a number, one by one, in your native language. Make it simple enough that a ten-year-old could do it. Then turn that, line by line, into code.

If you're not sure how to factor a number, Google can find that for you.
 
Liutauras Vilda
Marshal
Posts: 4634
316
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch, nice to see you around

Someone else definitely more knowledgeable on JOptionPane's than me will advice you better. Give them some time.

1. But to my eyes stuck one little tiny thing. You don't need to have numberB as a parameter in your showFactor method. You can initialize it to 1 within the for loop. I'd keep only numberA as an argument.

2. Why you returning Integer from that method and not using it nowhere? Consider if you ever need to return it.

3. Also, please format your code consistently, these things could help you loose some marks. Beside that, your code is difficult to read. Make by 1 space around all binary operators. Break your String text within print statements, as the lines at the moment are the way too long, I can't even see till the end.

 
Campbell Ritchie
Marshal
Posts: 55681
162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Liutauras Vilda wrote:. . . Someone else definitely more knowledgeable on JOptionPane's than me will advice you better. Give them some time. . . .
First things first. Get the factors method working first. Print out the result to the command line, and when you can do that you can add option panes very easily. But, as Knute said, you need to turn your computer off and work out the algorithm first.
Make it simple enough that Campbell Ritchie could do it.
And welcome again
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!