Question 8
Identify the COMPILER ERRORS and EXCEPTIONS in this program. This program is saved in a file named MyProgram.java.
public class MYProgram
{
public static void main( String [] args )
{
int [] arrayOfIntegers = { 15, 20, 30 50, 60 };
for( int i = 0; i <= arrayOfIntegers.length(); i++ )
{
System.out.println( "Hello" + i * 2 )
int i = 100 * arrayOfIntegers[ i ];
doSomething( i );
}
}
Public static void DoSomething( )
{ String str = "Hello, there!" );
System.out.println( str.substring( 5, 35 );
return str.length();
}
}
public class MYProgram { public static void main(String[] args) { int[] arrayOfIntegers = {15, 20, 30, 50, 60}; for (int i = 0; i < arrayOfIntegers.length; i++) { System.out.println("Hello" + i * 2); i = 100 * arrayOfIntegers[i]; DoSomething(); } } public static int DoSomething() { String str = "Hello, there!"; try { System.out.println(str.substring(5, 35)); } catch (Exception e) { } return str.length(); } }
Question 8 Identify the COMPILER ERRORS and EXCEPTIONS in this program. This program is saved in...
Trying to practice this assignment Argument list: the *yahoonews.txt Data file: yahoonews.txt Write a program named WordCount.java, in this program, implement two static methods as specified below: public static int countWord(Sting word, String str) this method counts the number of occurrence of the word in the String (str) public static int countWord(String word, File file) This method counts the number of occurrence of the word in the file. Ignore case in the word. Possible punctuation and symbals in the file...
// 2. Practice debugging this program. It has approximately 22 compiler errors, 1 logic error and //1 usability error. Identify them all. import java.util.scanner; //This program finds the average of three input values. public class Arithmeticx { public static void main( String [] args ) // declare variables double number1, number2, number3; // input data scanner in = newscanner( ); System.out.print( "Number 1? " ); System.out.print( "Number 2? " ); System.out.print( "Number 3? " ); number 1 = in.nextDouble; number...
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...
Explain in detail what the code below does: public class MyClass { public static void main(String args[]) { System.out.println(isUniqueChars("something")); } public static boolean isUniqueChars(String str) { int checker = 0; for (int i = 0; i < str.length(); ++i) { int val = str.charAt(i) - 'a'; if ((checker & (1 << val)) > 0) return false; checker |= (1 << val); } return true;...
Write a program that will check a Java file for syntax errors. The program will ask for an input-file name and output-file name and will then copy all the code from the Java input file to the Java output file, but with the following changes: 1. Any syntax error found in the Java input file will be corrected: a. Missing semicolon b. Missing compound statements (curly braces) c. All comments have to start with // and end with a period....
DEBUGGING. JAVA. Identify the errors in the following. There are no logical errors in this one just syntax issues. //start import java.util.Scanner; public class NumbersDemo { public static void main (String args[]) { Scanner kb = new Scanner(System.in); int num1, num2; System.out.print("Enter an integer >> "); num1 = kb.nextInt(); System.out.print("Enter another integer >> "); num2 = kb.nextDouble(); displayTwiceTheNumber(num1); displayNumberPlusFive(num1); displayNumberSquared(num1) displayTwiceTheNumber(num2); displayNumberPlusFive(num2); displayNumberSquared(num2); } ...
Write the output of the two codes below, unless there is a compiler error or a runtime error. In those cases, write CE or RE, respectively, and explain why those errors occur. If the code produces an infinite loop, write “LE: infinite loop”. public class ForLoopsDemo{ public static void main(String[] args){ int x = 4; fint x = 4; for( int i = 0; i < x; i++ ){ } } for( int j = 0; j < 2*i+1; j++)}...
Get the file “HW4Part4a.java” from the repository. Modify the program class to match the new file name. Complete it by writing a recursive static int function named “pow2” with one parameter, an integer n. The function is defined as follows: if n ≤ 0 then pow2(n) = 1. Otherwise, pow2(n) = 2 · pow2(n − 1). public class HW4Part4a { public static void main(String[] args) { for (int i = 0; i <= 20; i++) { System.out.println("pow2("+i+") = "+pow2(i)); }...
Consider the following short program. If there's an error (either compilation or runtime) in the program, then tell me what the problem is. But if the program works fine, then describe in 1 or 2 sentences what's the goal of the program. public class Main { public static void main(String[] args) { String[] arr = args; m(arr); public static void m(String... a) { for (int i = 0; i < a.length; i++) System.out.println(a[i] + a[i]);
Fix 15 errors in the code below public class CallingMethodsInSameClass { string fName = Joe; string lName = Hasley; string fullName; public static void main(String[] args) { printOne() concatThem() } public static void printOne() { System.out.println(Hello World) public static void concatThem() { fullName = fName + “ “ + lName; if(fullName.equals(fName + lName){ system.out.println(“It’s a match! fullName is: “ + fullname”) } else ...