214k views
3 votes
Write a program Not.java that reads one boolean value from the command line,stores it in a boolean variable b, and prints out its negation, not b. For example, if b is true, the program should printfalse. (Question: What happens if you type something other than true or false on the command-line?)

User Billygoat
by
5.4k points

1 Answer

3 votes

Answer:

if user pass true or TRUE program show output as "false" and if user pass false or FALSE program shows output as true, except these four input, for all other input it shows true, and if we do not pass command line arguments it throws ArrayIndexOutOfBoundsException

Step-by-step explanation:

public class Not{

public static void main(String [] args){

boolean b = Boolean.parseBoolean(args[0]);

System.out.println(!b);

}

}

User Jason Axelrod
by
6.1k points