New course! Every coder should learn Generative AI!
Try a free lesson+ 2
This moves nearly all the code out of main:
https://ctxt.io/2/AACgkdD1Eg
Please copy within 24 hours because that site will erase it at that point.
I didn't paste here because sololearn limits answers to 2048 characters and the code is longer than 2048.
The following requirement:
"Read in user input and verify that correct values were entered
Both, x,y > 0 and x<y" was in conflict with how you implemented the checks for cases when x is 0, y is 0, or x == y so I changed the operators to meet the requirements. You checked for x < 0 when the opposite of x > 0 is x <= 0.
Why do you limit to 3 errors? I don't see that requirement in your question.
+ 1
Greig's code has two methods:
printPrimes(int lowerBound, int upperBound)
getValidRangeFromUser()
+ 1
dharmik patel wrote, "Still need to write the code with methods in java if anyone knows"
Response:
Why? I already did. Didn't you check the link https://ctxt.io/2/AACgkdD1Eg ?
main is very short because nearly everything was moved into separate methods. In other words, I wrote the other methods that the question is asking for.
0
A string cannot be split by the end of a line, such
System.out.print("\n Invalid input. Please enter numbers
greater than 0 or both.\n");