ulamspiral | Python code to generate and print Ulam Spirals | 3D Printing library
kandi X-RAY | ulamspiral Summary
kandi X-RAY | ulamspiral Summary
Python code to generate and print Ulam Spirals.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Adds a new row to the current spiral
- Rotate the grid
- Returns a list of primes that start at stop
ulamspiral Key Features
ulamspiral Examples and Code Snippets
Community Discussions
Trending Discussions on ulamspiral
QUESTION
I got a challenge to make a Ulam Spiral in Java, but before the Ulam Spiral is created, the user should put in 2 numbers. Those 2 numbers should be checked so they aren't a prime number. As long as one of the numbers that are written is a prime number, then the program should restart and ask for 2 new numbers.
The getInput method is asking the user for 2 numbers. After that those numbers are written, the isPrime method should be called and one number at a time should be checked if it's a prime. If the first number checked isn't a prime, then the second number should be checked, if that also isn't a prime, then the next method should be called. What I don't understand is the isPrime method I have. It checks the number, but how do I make so if the first isn't a prime, then check the next number and as long as none of them are prime, then we are fine. I could make that the isPrime method takes in both numbers and they are checked, but I was not allowed to do that, I must check one number at a time.
Here you see my getInput and isPrime method. And yes, I know that isPrime(firstNumber); isPrime(secondsNumber); in my main method is weird and it shouldn't be like that, should it? is it a better way?
...ANSWER
Answered 2019-Mar-02 at 11:37Take the printing out of isPrime
method and have it after both the numbers are checked. Refactor the code as below:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install ulamspiral
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page