• 3
• Locked
• Exercise
Student robot Peter is an overachiever. Previously, his server was configured to receive scores on a five-point scale, but now his teachers have switched to a 12-point scale. But Peter doesn't know this. He's still focused on getting fives. Let's write him a compare method that compares any number with five.
You can't complete this task, because you're not signed in.
Mike McKennaLevel 7 , Wilmington
22 June, 18:23
learned about if/else . with the straight forward requirements . is there really need for else ?
Prateek MishraLevel 8 , Bhopal
18 December 2018, 15:24
Please see this code and tell me Whats wrong, i am 100% sure i have written correct code. Why is it calling the function 4 times? package com.codegym.task.task04.task0408; public class Solution { public static void main(String[] args) { compare(3); compare(6); compare(5); } public static void compare(int a) { if(a==5) System.out.println("The number is equal to 5"); if(a<5) System.out.println("The number is less than 5"); else System.out.println("The number is greater than 5"); } } Output: The number is less than 5 The number is greater than 5 The number is equal to 5 The number is greater than 5
RomanLevel 41
19 December 2018, 07:30
If you need help, something isn't right in your code, the server won't accept your solution (even if you are 100% sure that it is correct). Describe your question/issue in the HELP section at codegym.cc/help.
HenryLevel 4 , Stuttgart
12 September, 20:57
It is because you used "if "for the first and second condition The second "if "should be "if else".
Alec CastilloLevel 4 , New Orleans
27 November 2018, 09:26
Why did this program not accept else statements? I want to program it as if-else and it will not allow that.
RomanLevel 41
28 November 2018, 06:26
If you need help, something isn't right in your code, the server won't accept your solution (even if you are 100% sure that it is correct). Describe your question/issue in the HELP section at codegym.cc/help.
ThomasLevel 9
26 October 2018, 19:34
Copied and pasted the conditions from the task yet the task is still failed. Ran the code inside IntelliJ and it works fine. Output is expected for different inputs. For example: compare(3); compare(6); compare(5); yields: The number is less than 5. The number is greater than 5. The number is equal to 5. So what is going on with this task?
RomanLevel 41
29 October 2018, 06:28
If you need help, something isn't right in your code, the server won't accept your solution (even if you are 100% sure that it is correct). Describe your question/issue in the HELP section at codegym.cc/help.