• 8
  • unavailable
We continue our attempts to enter the cosmic space belonging to Planet Linear Chaos. Here's another task taken from a border-crossing interview, for young arrivals: find the greatest common divisor (GCD) of two positive integers.
You can't complete this task, because you're not signed in.
  • Popular
  • New
  • Old
You must be signed in to leave a comment
SvenLevel 19 , Hanover
16 August, 14:28
I don't see the problem here, but I always get a Time out! when I try to do the validation... Any suggestions on why that happens?
AlexLevel 41
16 August, 14:41
Sounds like you may have an infinite loop in your code. Please consult the Help section with your code to get a definite answer.
AhmedLevel 19 , Amsterdam
26 May, 17:09
Waa what tough exercise! I just googled the answer on Google about how to calculate the GCD and I came up with an answer that uses recursive. After copying and pasting I passed the verification but I have no clue how the code that I copied works :-)
Guadalupe GagnonLevel 36 , Tampa
4 December 2018, 17:57
Some added notes to the task for (hopefully) further clarification (my thoughts after passing it, not from the developers): 1) The program does not need to display anything other than the greatest common divisor. This means that no message needs to be displayed if an exception is thrown. (where the user doesn't enter a number or the number is not positive) this is what i used: throw new NumberFormatException("Number needs to be positive"). 2) no need to use any try-catch statements for invalid user data. If an exception is thrown it will crash the program, but i passed just fine not catching these exceptions. 3) example inputs and outputs from my program that passed. The first two lines are user input and the third line being the program output (noted in the first example): A) (enter 2 positive numbers) 500 // user input 50 // user input 50 // output from program of the greatest common divisor B) (enter a negative number) -50 Exception in thread "main" java.lang.NumberFormatException: Number needs to be positive at com.codegym.task.task14.task1420.Solution.getPositiveInt(Solution.java:71) at com.codegym.task.task14.task1420.Solution.main(Solution.java:15) Process finished with exit code 1 C) (enter a positive number then a string) 20 twelve Exception in thread "main" java.lang.NumberFormatException: For input string: "twelve" at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) at java.lang.Integer.parseInt(Integer.java:580) at java.lang.Integer.parseInt(Integer.java:615) at com.codegym.task.task14.task1420.Solution.getPositiveInt(Solution.java:69) at com.codegym.task.task14.task1420.Solution.main(Solution.java:16) Process finished with exit code 1
franLevel 14 , Cordoba
13 March, 18:48
There are very useful notes provided by Guadalupe in order to acomplish this task. I will add to these notes that the 0 (zero) number is not a postive number. Cheer up friends!!!!!!
BerksonLevel 17 , Fortaleza
21 June, 14:08
Man the same to me I hate the 0 number hahahaha... finished.