Question

Question 8 Identify the COMPILER ERRORS and EXCEPTIONS in this program. This program is saved in...

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();

}

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1
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();
    }
}
Add a comment
Know the answer?
Add Answer to:
Question 8 Identify the COMPILER ERRORS and EXCEPTIONS in this program. This program is saved in...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Trying to practice this assignment Argument list: the *yahoonews.txt Data file: yahoonews.txt Wr...

    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...

    // 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...

  • Explain in detail what the code below does: public class MyClass {       public static void...

    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...

    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....

  • 1) Consider the following Java program: 1 public class HelloWorld { 2     // My first program!...

    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...

  • DEBUGGING. JAVA. Identify the errors in the following. There are no logical errors in this one...

    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...

    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++)}...

  • Why float f = 10d will cause the compiler error/ and why int and double did...

    Why float f = 10d will cause the compiler error/ and why int and double did not cause any compiler error ? public class Main { public static void main(String[] args) { // write your code here char c = 38; int i = 'a'; double d = 10f; double d2 = 10; float f = 10d; System.out.println(a + b); } }

  • Get the file “HW4Part4a.java” from the repository. Modify the program class to match the new file...

    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)); }...

  • Predict the output generated at the marked println lines in the following program. The pro- gram...

    Predict the output generated at the marked println lines in the following program. The pro- gram makes use of the class Prob1. Please enter each answer in the space provided. import java.util.Stack; public class Prob1 { public static int mystery(int m, if(n == 0) return 0; if(n % 2 == 0) return mystery(m+m, n/2); return mystery(m+m, n/2) + m; } int n) { args) { 29)); //------------------(a) public static void main(String[] System.out.println(mystery(2, String str = "Harry Potter"; str.toLowerCase(); str.substring(0, 7);...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT