+ 4
Can you please tell me what is wrong with this problem? one test fails
You need to know if a number is divisible by each of a group of other numbers. If you are given the number and the group of other numbers, you will test to make sure that it is divisible by all of them. Task: Test your number against all of the other numbers that you are given to make sure that it is divisible by them. Input Format: Two inputs: an integer value (the number you are testing) and a string of variable length of the integers that you should test against separated by spaces. Output Format: A string that says 'divisible by all' or 'not divisible by all'. Sample Input: 100 2 5 10 Sample Output: divisible by all https://code.sololearn.com/cYYdCiUsrn7h/?ref=app
15 Respuestas
+ 6
Андрей Колесник ,
there is an exception (dividion by zero) with these inputs:
7
0
8
2 0
this input is ok:
7
2 0
+ 5
I took a look at the code anyhow, and the only issue I found was that (other than not checking for invalid input) inside the loop it was doing an operation with modulus to check for divisibility before checking if the divisor was not zero. In that case your code could fail if you added 0 as one of the divisors.
If you change that, it should work or at least bypass that logic error.
Just for laughs, I rewrote it in a more functional style using the Streams API. Check it out if you like. I think it's more concise.
https://www.sololearn.com/compiler-playground/c2ae4U0MA3Fw
+ 3
I rewrote your code with minor changes. It passed all the tests.
You should know the features of the Scanner class.
The variable num must be written as
int num = sc.nextInt();
sc.nextLine();
or
int num = Integer.parseInt (sc.nextLine().trim());
+ 2
code of Marcos Chamosa Rodríguez
is not openable so I'm reposting it
https://code.sololearn.com/c2ae4U0MA3Fw/?ref=app
+ 1
It would be helpful if you specified which test fails.
+ 1
Marcos Chamosa Rodríguez, thank you very much for the answer) your code is awesome, but isn't working(
+ 1
Lothar, thank you for your answer. I tested the code in Intellij Idea, and everything is working)
+ 1
Dzianis Mitrokhin , thank you very much, it helps me) have a nice day, everyone!
+ 1
@Marcos, in playground up-right is ikon for sharing and copy link.
then link has same id code, but has different format and ends with ?ref=app
+ 1
I didn't find any wrong in given code.
I checked this code in other platform it is working fine.
Problem is in the taking input in sololearn playground.
0
Unfortunately the test that fails is hidden... otherwise I could solve the problem
0
That's too bad. It works just fine for me both in my PC and in the playground of solo learn.
The compiler of the platform you're using likely is for a version of Java that is incompatible with some of my code.
My guess is that it's Java 8. My code uses features from more recent versions.
0
playground uses Java 19 ea (early access),
it means java 18 complete version
https://code.sololearn.com/c1rk18PiBd95/?ref=app
0
Thanks zemiak. Where do you get those functional links for code? I can't find it
0
Ah, thank you!