Java homework. Thank you Step 6: Edit the calls to System.err.println() so that
ID: 3879738 • Letter: J
Question
Java homework. Thank you
Step 6: Edit the calls to System.err.println() so that they output useful error messages. This means that you must explore the behavior of the program enough to understand what errors you can make
Program to take one command line argument, an integer, * and compute and output a function of that argument. *@see main class mpl * f is the function @param i an integer *@return the function of that ineger private static int f( inti)f if (1 2) { // basis case return i; ) else f // induction rule return i+ (i -1)+ f(i - 1); * main program *@param args an array of strings *@see Integer.parseInt for converting a string to an integer *@see f the function this uses public static void main( String args) if (args.length1) try f int i = Integer.parseInt( args [0] ); System.out.println "al gets: f(" + 1 + ") = " + f(i) catch (NumberFormatException e) ) else t System.err.println( ""args [0] + ""); System.err.println( "" );Explanation / Answer
Explanation :
Number format expection occurs in java when you try to convert some string into a number(int , float etc)
ex : string s="abc"; int i = Integer.parseInt(s) ; throws number format exception
Answer :
1.System.err.println("the input " +args[0] + " cannot be converted into integer type" );
2. System.err.println("more than one ore less than one input recived from command line , please give exactly one input");
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.