I’m trying to write a code for a program that recives strings as an input.
The program prints “Error” when the user does not put any data, otherwise it prints the first string argument.
Is it right to refer to no data as a “null”?
It does not work. what should I write instead?
public class Try {
public static void main(String[] args){
if (args[0]==null){
System.out.println("Error- please type a string");
}else {System.out.println(args[0]);}
}
}
Arguments will never be
nullif they exist in the first place — to check that, you should useargs.lengthinstead: