• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Showing the factors of a number in JOptionPane.

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 7113
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 8384
594
Mac OS X VI Editor BSD Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Marshal
Posts: 76405
364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Drove my Chevy to the levee but the levee was dry. A wrung this tiny ad and it was still dry.
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic