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: public class Infinity { public static void main(String args[]) { /* Start by assigning your default value to n, here it is 0 If valid argument is not … Read more