0
Divisible medium sololearn
Why my code doesn't work? Test #3 - fail It's my code: https://code.sololearn.com/cjSpSlZkM2qE/#java
15 Answers
0
We need use .trim() when read line
+ 1
perhaps the code will look better and more readable.
But code doesn't work on Test case #3.
Where is my mistake?
+ 1
my code doesnt work on test case #3
why?
Where is my mistake in the code?
+ 1
class Divisible {
public static void div(int a, String b) {
String[] c = b.split(" ");
int res = 0;
int zero = 0;
for (int i = 0; i < c.length; i++) {
if (Integer.parseInt(c[i]) == 0){
zero= zero + zero;
}
else if (a % Integer.parseInt(c[i]) == 0) {
res++;
}
}
if (res == c.length) {
System.out.println("divisible by all");
} else {
System.out.println("not divisible by all");
}
}
}
IT
STILL
FAIL
TEST #3
!!!
WHY?
I am angry!
0
Can you explain more about problem description...?
0
this test case is hidden and I don't know why it is fail =(
0
What is this code is about?
What is expected output for a sample input?
I think it's a pro-code coach problem.. So we don't know, problem description...
But for any input it will print only else part...
0
Yes, it is from pro-code coach.
In input we receive number
and String with numbers
We need to check if number divisible by all numbers in string
A = 100;
String = 2 5 10
We split to String array
Then we case string to int
then for loop
if 100%2 == 0 && 100%5==0 && 100%10==0
It will print " else if " part.
I dont understand why test case #3 fail =\
0
res += res;
} else{
res++;
}
What these statements do?
If it divisible then just increment res by 1. So res++;
There is no need of next else part.
And last res==0 means non divisible. So it should be i equal to c array length.
res==c.length
0
class Divisible {
public static void div(int a, String b) {
String[] c = b.split(" ");
int res = 0;
for (int i = 0; i < c.length; i++) {
if (a % Integer.parseInt(c[i]) == 0) {
res++;
}
}
if (res == c.length) {
System.out.println("divisible by all");
} else {
System.out.println("not divisible by all");
}
}
}
It still fail on test #3
0
Put the special case for zero as it is but don't increment res.
0
Check by increment res, for zero also..
If still no effect, then may be, you are missing any special logic from description... May be, read again..
0
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'.
0
Ha ha.. Fine you got it..
0
For python
number = int(input())
divisible = input()
divisible_list = divisible.split()
x = ["divisible by all" if number % int(each) == 0 else "not divisible by all" for each in divisible_list]
print(x[0])