Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

My code below works perfect, just not sure how to promt user \"No Command line a

ID: 3656621 • Letter: M

Question



My code below works perfect, just not sure how to promt user "No Command line arguments. Cannot proceed" if they dont enter there input and output from the command line.


import java.io.File;

import java.util.Formatter;

import java.util.Scanner;

public class question3b {

public static void main(String[] args)

{

String inpuFileName = args[0];

String outpuFileName = args[1];

System.out.printf("Processing Complete");


try {

Scanner input = new Scanner(new File(inpuFileName));

Formatter output = new Formatter(outpuFileName);

while (input.hasNext()) {

String line = input.nextLine();

String[] tokens = line.split("//");

output.format("%s ", tokens[0]); }

input.close(); output.close(); }

catch (Exception e) { e.printStackTrace();

System.exit(1); }

}


}

Explanation / Answer

you gotta check the length of the arguments... include this in your code... hope it helps. if(args.length == 0) { System.out.println("No Command line arguments. Cannot proceed."); System.exit(0); }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote