1) In Java, a library of classes is called
a) an application
b) a folder
c) a directory
d) a package
2) In the technique of Top-Down design, the problem of designing a method is divided into subproblems, which are then solved using the same technique.
a) true
b) false
3) It is possible to have two methods in the same class that have the same name, the same number and types of arguments, but different return types.
a) true
b) false
4) The == operator can be used to see if two strings have the same characters.
a) true
b) false
5) The Java compiler translates Java programs into machine language.
a) true
b) false
6) The characters // in a line
a) is an escape sequence
b) mean that the rest of the line is a comment
c) has no meaning
d) False are part of an expression that uses integer division
7) The following is an infinite loop:
j = 1; while ( j < 10 ) System.out.println( j++ ); j = j - 1;
a) true
b) false
8) The following is an infinite loop:
j = 1; while ( j < 10 ) System.out.println( j ); j++;
a) true
b) false
9) What happens if the catch-block of a more general exception comes before the catch-block of a more specific exception?
a) The more specific catch-block will never execute
b) Both catch-blocks will execute when the more specific exception occurs
c) Both catch-blocks will execute when the more general exception occurs
d) The more general catch-block will never execute
10) Consider the following code:
int[][] form = new int[2][5];
for ( int i=0; i<2; i++ )
{
for ( int j=0; j<5; j++ )
{
form[i][j] = i+4*j;
}
}
Match the indices of the array to the answers provided
form[0][1]:
form[1][1]:
form[2][4]:
form[0][2]:
form[1][3]:
Options:
a) invalid
b) 13
c) 8
d) 5
e) 4
Answer:-----------
a) true
a) true
b) false
b) false
b) mean that the rest of the line is a comment
b) false
a) true
c) Both catch-blocks will execute when the more general exception occurs
form[0][1]:------------ e) 4
form[1][1]: ----------- d) 5
form[2][4]: ----------- a) invalid
form[0][2]: ------------ c) 8
form[1][3]: ------------- b) 13
1) In Java, a library of classes is called a) an application b) a folder c)...
Hi. This is a prototype of Java. The following Java program was developed for prototyping a mini calculator. Run the program and provide your feedback as the user/project sponsor. (Save the code as MiniCalculator.java; compile the file: javac MiniCalculator.java; and then run the program: java MiniCalculator). HINTs: May give feedback to the data type and operations handled by the program, the way the program to get numbers and operators, the way the calculation results are output, the termination of the...
Question 10 (3 points) Which of the following statement is not true? There is a recursive sum method as shown below. When sum (19) is called, summation of all odd numbers less than 19 will be calculated and returned public int sum(int x){ if (x == 0) return 0: else return sum(x-2) + x; The following code segment will throw a testException. This exception has been handled in the way that do nothing but to continue when this exception happens....
Question 1 (5 points) Question 1 Unsaved What is displayed on the console when running the following program? public class Quiz2B { public static void main(String[] args) { try { System.out.println("Welcome to Java"); int i = 0; int y = 2 / i; System.out.println("Welcome to Java"); } catch (RuntimeException ex) { System.out.println("Welcome to Java"); } finally { System.out.println("End of the block"); } } } Question 1 options: The program displays Welcome to Java two times. The program displays Welcome to...
JAVA CODE This program causes an error and crashes. Compile and give it a test run, note the exception that is thrown. Then do the following to fix the problem 1. Write code to handle this exception 2. Use try, catch and finally blocks. 3. Display, the name of the exception 4. Display a message from the user about what happened. Here is the starting file BadArray.java: public class BadArray { public static void main(String[] args) { // Create an...
The ability of computers to perform complex tasks is built on combining simple commands into control structures. Of these control structures, blocks, while loop, the do..while loop, and the for loop. A block is the simplest type of structured statement. Its purpose is simply to group a sequence of statements into a single statement. The format of a block is: { } Here are two examples of blocks: { System.out.print("The answer is "); System.out.println(ans); } // This block exchanges the...
import java.util.Scanner; import java.io.File; public class Exception2 { public static void main(String[] args) { int total = 0; int num = 0; File myFile = null; Scanner inputFile = null; myFile = new File("inFile.txt"); inputFile = new Scanner(myFile); while (inputFile.hasNext()) { num = inputFile.nextInt(); total += num; } System.out.println("The total value is " + total); } } /* In the first program, the Scanner may throw an...
I created this program using the Java-oriented programming application known as Eclipse for a lottery system, however it's not giving me the output I want. The output should look something like this: Trial Sum Count of Occurrence 3 150 4 170 5 1100 6 1460 ... 83 240 84 90 Any help with the following program would be appreciated /* Simulate a Pick 3 lottery system and conduct 100,000 independent lottery trials* reporting out aggregate statistical data based on your...
Please help me with this Java project. I'm trying to create a loop so if user enter value > 12, will prompt them a message and take them back to "How many elements do you wan to enter?". Thanks public static void main(String[] args) { Scanner sc = new Scanner(System.in); int i, j; System.out.print("\n How meny elements do you want to enter? (N should be no more than 12) "); int num...
JAVA PROBLEMS 1. Update the below method to throw an IndexOutOfBoundsException: public E get(int index) { if (index < 0 || index > numItems) { System.out.println("Get error: Index " + index + " is out of bounds."); return null; } return array[index]; } Hint: Update both the method signature and the method body! 2. Update the below method to include a try-catch block rather than throwing the exception to...
1) Consider the following Java program: 1 public class HelloWorld { 2 // My first program! 3 public static void main(String[] args) { 4 System.out.println("Hello, World!"); 5 } 6 } What is on line 1? a. a variable declaration b. a statement c. a method (subroutine) definition d. a comment e. a class definition 2) Which one of the following does NOT describe an array? a. It can be used in a for-each loop. b. It has a numbered sequence...