Java find output programs
- Java find output programs (Data Types) | set 1
- Java find output programs (Data Types) | set 2
- Java find output programs (Data Types) | set 3
- Java find output programs (Operators) | set 1
- Java find output programs (Operators) | set 2
- Java find output programs (Operators) | set 3
- Java find output programs (if else) | set 1
- Java find output programs (if else) | set 3
- Java find output programs (switch case) | set 1
- Java find output programs (switch case) | set 2
- Java find output programs (switch case) | set 3
- Java find output programs (Loops) | set 1
- Java find output programs (Loops) | set 2
- Java find output programs (Loops) | set 3
- Java find output programs (Arrays) | set 1
- Java find output programs (Arrays) | set 2
- Java find output programs (Arrays) | set 3
- Java find output programs (this Keyword) | set 1
- Java find output programs (final Keyword) | set 1
- Java find output programs (final Keyword) | set 2
- Java find output programs (static Keyword) | set 1
- Java find output programs (static Keyword) | set 2
- Java find output programs (Parameter Passing) | set 1
- Java find output programs (Class and Objects) | set 1
- Java find output programs (Class and Objects) | set 2
- Java find output programs (Class and Objects) | set 3
- Java find output programs (Constructor & Destructor) | set 1
- Java find output programs (Constructor & Destructor) | set 2
- Java find output programs (Constructor & Destructor) | set 3
- Java find output programs (Inheritance) | set 1
- Java find output programs (Inheritance) | set 2
- Java find output programs (Inheritance) | set 3
- Java find output programs (Interface) | set 1
- Java find output programs (Interface) | set 2
- Java find output programs (Interface) | set 3
- Java find output programs (Overloading) | set 1
- Java find output programs (Overloading) | set 2
- Java find output programs (Overriding) | set 1
- Java find output programs (Overriding) | set 2
- Java find output programs (Overriding) | set 3
- Java find output programs (Exception Handling) | set 1
- Java find output programs (Exception Handling) | set 2
- Java find output programs (Exception Handling) | set 3
- Java find output programs (Enumeration) | set 1
- Java find output programs (Enumeration) | set 2
- Java find output programs (Autoboxing & Unboxing) | set 1
- Java find output programs (Autoboxing & Unboxing) | set 2
- Find output programs (Java String class)
- Find Output of Java program - 1 (Mixed topics)
- Find Output of Java program - 2 (Mixed topics)
- Java find output programs (if else) | set 2

Java programming
Answer Question 1:
Output:
Main.java:5: error: ']' expected int arr[5]={1,2,3,4,5}; ^ Main.java:5: error: illegal start of expression int arr[5]={1,2,3,4,5}; ^ Main.java:5: error: illegal start of expression int arr[5]={1,2,3,4,5}; ^ Main.java:5: error: not a statement int arr[5]={1,2,3,4,5}; ^ Main.java:5: error: ';' expected int arr[5]={1,2,3,4,5}; ^ Main.java:8: error: illegal start of type for(int i=0; i<5;i++) ^ Main.java:8: error: ')' expected for(int i=0; i<5;i++) ^ Main.java:8: error: illegal start of type for(int i=0; i<5;i++) ^ Main.java:8: error: expected for(int i=0; i<5;i++) ^ Main.java:8: error: ';' expected for(int i=0; i<5;i++) ^ Main.java:8: error: expected for(int i=0; i<5;i++) ^ Main.java:8: error: illegal start of type for(int i=0; i<5;i++) ^ Main.java:8: error: '(' expected for(int i=0; i<5;i++) ^ Main.java:12: error: expected System.out.println(num); ^ Main.java:12: error: expected System.out.println(num); ^ Main.java:14: error: class, interface, or enum expected } ^ 16 errorsExplanation:
The above program will generate syntax errors because of the array declaration.
int arr[5]={1,2,3,4,5};Here, we declared array arr with size 5, here we must use a new operator to initialize the array.
The correct way is given below:
int arr[]; arr = new int[5];Answer Question 2:
Output:
Main.java:3: error: ']' expected int arr[5]; ^ Main.java:3: error: illegal start of expression int arr[5]; ^ 2 errorsExplanation:
The above program will generate syntax errors because of the array declaration.
int arr[5];We cannot define the size of an array like this, the correct way is given below,
int arr[]=new int[5];Answer Question 3:
Output:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 5 at Main.main(Main.java:10)Explanation:
The above program will generate runtime exception because array arr contains 5 elements. Then the index of an array starts from 0 to 4 but we tried to access the element at index 5 that is out of bounds of the array.
Answer Question 4:
Output:
Explanation:
The above program will print 0 on the console screen. Here, we declared an integer array initialized with 5,3,1,6,2 and an integer variable num initialized with 0.
Within the body of the loop and multiply with num every time but variable num is initialized with 0 that's why the result will be 0.
When I=0; Num = num *5; Num =0; When I=1; Num = num *3; Num =0; When I=2; Num = num *1; Num =0; When I=3; Num = num *6; Num =0; When I=4; Num = num *2; Num =0;Answer Question 5:
Output:
Main.java:10: error: cannot find symbol for(int i=1; i<arr.len();i++) ^ symbol: method len() location: variable arr of type int[] 1 errorExplanation:
The above program will generate syntax error because len() method is not available in Java, to get the length of the array we need to use length data members of the array.
need an explanation for this answer? contact us directly to get an explanation for this answer