I've got a problem similar to the one already posted here. The validator does not believe I'm using the relativize() method of the Path class. I'm wondering why.
I also have another question, not related to the validation process. The tasks "hints" that if I can't find the relative path between path1 and path2, I should try to find the relative path between path2 and path1. I'm checking for that with the if-else statement (and the validator agrees that my program displays the relative path between the entered paths, if it exists) but I'm not sure that this idea of mine is really good. The thing is, there is no method like "ifRelative()" or "ifRelativePathExists()", so I decided to use !(...).ifAbsolute() and also check for a null input just in case (idk if there can be a null at all in this case). Was that really worth doing?
package en.codegym.task.pro.task15.task1514;
import java.nio.file.Path;
import java.util.Scanner;
/*
It's all relative
*/
public class Solution {
public static void main(String[] args) throws IllegalArgumentException {
Scanner scanner = new Scanner(System.in);
String str1 = scanner.nextLine();
String str2 = scanner.nextLine();
Path path1 = Path.of(str1);
Path path2 = Path.of(str2);
Path result = path1.relativize(path2);
if (!result.isAbsolute() && result !=null)
System.out.println(result);
else {
result = path2.relativize(path1);
if (!result.isAbsolute() && result !=null)
System.out.println(result);
}
}
}