In Java, how to assign the variable number=Integer.parseInt(args[0]) a value if no argument is passed?

You could assign value of n as 0 or any other value by default and use if(args.length > 0) { to check whether any arguments is given. Below is full example with comments: Note: Users which are not so familiar with java, this program can be run by: Saving it to Infinity.java Compiling it with cmd or terminal by writing: javac Infinity.java Executing it … Read more