r/learnjava • • 2h ago

What is wrong with this code? MOOC.FI

So this piece of code is for finding the absolute value:

import java.util.Scanner;


public class AbsoluteValue {


    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
         int num = Integer.valueOf(scanner.nextLine());
         if(num < 0){
            num = (num*(-1));
         }
            System.out.println(num);
    }
}

But TMC MOOC.FI is showing this error:

TestMyCode
Some tests failed on the server

Need help?

Points: 0.00%

...

x

Test passed!

AbsoluteValueTest absolute ValueOfNegativeThree

Test passed!

AbsoluteValueTest absoluteValueOfSix
1 Upvotes

5 comments sorted by

View all comments

•

u/Cross_22 10m ago

Code looks okay to me. You'd need to check with the course provider why it's graded as 0 points when there are no test failures.