• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Break the order of numbers when it is 0 using while.

 
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello !! I'm trying to do an exercise with 2 whiles that cuts when it is entered and finds out if it's prime or not...the issue is that the cousin thing went ok, now that it doesn't cut...or it enters an infinite loop or short. Does anyone have it clearer? Thanks
 
Marshal
Posts: 79923
395
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Afraid I don't understand the problem. Please explain it so even I can understand it.
 
Sheriff
Posts: 17675
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bruno Valdeolmillos wrote:Hello !! I'm trying to do an exercise with 2 whiles that cuts when it is entered and finds out if it's prime or not...the issue is that the cousin thing went ok, now that it doesn't cut...or it enters an infinite loop or short. Does anyone have it clearer?



It will probably be easier for people to understand what you're doing if you posted the code you've written so far.

When posting code, please UseCodeTags (←click that, it's a link to instructions on how to use them).
 
Bruno Valdeolmillos
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Junilu Lacar wrote:

Bruno Valdeolmillos wrote:Hello !! I'm trying to do an exercise with 2 whiles that cuts when it is entered and finds out if it's prime or not...the issue is that the cousin thing went ok, now that it doesn't cut...or it enters an infinite loop or short. Does anyone have it clearer?



It will probably be easier for people to understand what you're doing if you posted the code you've written so far.

When posting code, please UseCodeTags (←click that, it's a link to instructions on how to use them).


I must make a program that ends when the user enters 0. And that program must find out how many numbers entered are prime using the repetitive while structure.
 
Bruno Valdeolmillos
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Junilu Lacar wrote:

Bruno Valdeolmillos wrote:Hello !! I'm trying to do an exercise with 2 whiles that cuts when it is entered and finds out if it's prime or not...the issue is that the cousin thing went ok, now that it doesn't cut...or it enters an infinite loop or short. Does anyone have it clearer?



It will probably be easier for people to understand what you're doing if you posted the code you've written so far.

When posting code, please UseCodeTags (←click that, it's a link to instructions on how to use them).


well i try, i have only in pseudocode.
 
Campbell Ritchie
Marshal
Posts: 79923
395
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please post that code again with indentation, so we can readily see which endXXX corresponds to which XXX. I think your end yes might be better written as endIf. What happens if you enter negative numbers? How are you trying to find whether a number is prime or not? You do realise that iterating all numbers smaller than the argument is an inefficient way to find prime numbers.
 
Junilu Lacar
Sheriff
Posts: 17675
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bruno Valdeolmillos wrote:
well i try, i have only in pseudocode.


I'm afraid that's not good enough. You can try implementing your algorithm in Java and show us the code you have. Try to at least get the code you share to compile even if it doesn't entirely work the way you want it to. Nobody here is going to write the code for you though.
 
Campbell Ritchie
Marshal
Posts: 79923
395
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am afraid I think neither code nor pseudocode is going to help us here. I think we need to go back to the logic for thee whole app. Never mind about 0s for now, but tell us how you intend to find out that a number is prime, and also how you intend to show that. No computing words allowed; see this FAQ.
 
Bruno Valdeolmillos
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Please post that code again with indentation, so we can readily see which endXXX corresponds to which XXX. I think your end yes might be better written as endIf. What happens if you enter negative numbers? How are you trying to find whether a number is prime or not? You do realise that iterating all numbers smaller than the as.


Well, I don't want to get into something more difficult, first I would start with positives, if that works well, then expand to negatives.
Step by Step.rgument is an inefficient way to find prime number
 
Bruno Valdeolmillos
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:I am afraid I think neither code nor pseudocode is going to help us here. I think we need to go back to the logic for thee whole app. Never mind about 0s for now, but tell us how you intend to find out that a number is prime, and also how you intend to show that. No computing words allowed; see this FAQ.


Well, I tried it in a flowchart, there in theory everything is very beautiful, but in "reality" in a compiler, reality appears there in its maximum expression and it doesn't work.
 
Bartender
Posts: 5546
213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bruno Valdeolmillos wrote:(...) Well, I don't want to get into something more difficult, first I would start with positives, if that works well, then expand to negatives.
Step by Step.rgument is an inefficient way to find prime number



A very fast way to determine prime numbers is what is called the 'Sieve of Eratosthenes'. Ever heard of it? Then, having the primes, it should be very easy to count how many primes there are that are smaller than or equal to some inputnumber.
 
Campbell Ritchie
Marshal
Posts: 79923
395
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bruno Valdeolmillos wrote:. . . first I would start with positives . . .

I believe that a prime number is defined as a special case of a natural number, so there would be no such thing as a negative prime number. Nor is 0 a prime number. Nor is 1; the smallest prime number is 2.
 
what if we put solar panels on top of the semi truck trailer? That could power this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic