Question: For the questions that asks for instructions/programs, please answer them in JAVA if you can , thank you! 1.Assume that the main method has a
For the questions that asks for instructions/programs, please answer them in JAVA if you can , thank you!
1.Assume that the main method has a try block that includes a statement which calls method1. Inside method1 is another try block that includes a statement which calls method2. Inside method2 is another try block that includes a statement which calls method3. What happens if method3 throws an exception? What happens if method2 has a catch block which can handle the exception? What happens if it does not have a catch block which can handle the exception? How does this progress if none of the methods can handle the exception?
2.What are command line arguments and how can the program access them?
3.Write a program that will accept a list of strings as command line arguments. It will step through these strings, convert each one to an integer and add them to a total. Finally, it will print the total.
4.Write some instructions that will write an error message if there are no command line arguments for a program.
5.What does each of the following do?
a. java.io.File myFile = new java.io.File("c:/chapter8G.java");
b. System.out.println("Does it exist? " + myFile.exists());
6.What does each of the following do?
a.import java.io.File;
b.import java.io.PrintWriter;
c.File myFile = new File("data.txt");
d. if (myFile.exists()){
e. System.out.print(Replace file data.txt? (y or n): ); char reply = keyboard.next().toLowerCase().charAt(0);
f. if (reply != y)
g. System.exit(0); }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
