0

Divisible medium sololearn

Why my code doesn't work? Test #3 - fail It's my code: https://code.sololearn.com/cjSpSlZkM2qE/#java

17th Feb 2020, 12:45 PM
Николай Макаренко
Николай Макаренко - avatar
15 Answers
0
We need use .trim() when read line
17th Feb 2020, 3:28 PM
Николай Макаренко
Николай Макаренко - avatar
+ 1
perhaps the code will look better and more readable. But code doesn't work on Test case #3. Where is my mistake?
17th Feb 2020, 1:16 PM
Николай Макаренко
Николай Макаренко - avatar
+ 1
my code doesnt work on test case #3 why? Where is my mistake in the code?
17th Feb 2020, 1:55 PM
Николай Макаренко
Николай Макаренко - avatar
+ 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!
17th Feb 2020, 2:30 PM
Николай Макаренко
Николай Макаренко - avatar
0
Can you explain more about problem description...?
17th Feb 2020, 1:53 PM
Jayakrishna 🇮🇳
0
this test case is hidden and I don't know why it is fail =(
17th Feb 2020, 1:57 PM
Николай Макаренко
Николай Макаренко - avatar
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...
17th Feb 2020, 1:59 PM
Jayakrishna 🇮🇳
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 =\
17th Feb 2020, 2:06 PM
Николай Макаренко
Николай Макаренко - avatar
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
17th Feb 2020, 2:13 PM
Jayakrishna 🇮🇳
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
17th Feb 2020, 2:21 PM
Николай Макаренко
Николай Макаренко - avatar
0
Put the special case for zero as it is but don't increment res.
17th Feb 2020, 2:26 PM
Jayakrishna 🇮🇳
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..
17th Feb 2020, 3:02 PM
Jayakrishna 🇮🇳
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'.
17th Feb 2020, 3:13 PM
Николай Макаренко
Николай Макаренко - avatar
0
Ha ha.. Fine you got it..
17th Feb 2020, 3:36 PM
Jayakrishna 🇮🇳
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])
21st Jun 2022, 5:27 AM
Dondon Bautista
Dondon Bautista - avatar