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
Answer Question 1:
Output:
Explanation:
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:
Explanation:
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:
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:
Explanation:
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