Predict the output? int arr[] = {10, 20, 30, 40, 50}; for(int i=0; i < arr.length; i++) { System.out.print(" " + arr[i]); }
Question
Predict the output? int arr[] = {10, 20, 30, 40, 50}; for(int i=0; i < arr.length; i++) { System.out.print(" " + arr[i]); }
Solution
The output of the given code will be:
10 20 30 40 50
Explanation: The code is written in Java. It declares an array 'arr' of integers and initializes it with the values 10, 20, 30, 40, 50. Then it uses a for loop to iterate over the array from the first element (index 0) to the last element (index arr.length - 1). In each iteration, it prints the current element of the array followed by a space.
Similar Questions
Find the output of the following code.class Output { public static void main(String args[]) { int arr[] = {11, 21, 31, 41, 51}; for ( int i = 1; i < arr.length - 2; ++i) System.out.println(arr[i] + " "); } }*11 21 31 4111 21 3121 3131 41 51
for (int i = 0; i < arr.length-1; i++){ for (int j = i+1; j < arr.length; j++) { if( (arr[i].equals(arr[j])) && (i != j) ) { System.out.println(arr[i]); } }}
Fill the code to print the numbers in the array using for each loop public class Main{ public static void main(String args[]) { int arr[]={50,70,80,90,100}; //fill code to print the array for(Answer) System.out.println(num); }}
public class Test{ public static void main(String[] args){ int[] x = {120, 200, 016 }; for(int i = 0; i < x.length; i++) System.out.print(x[i] + " "); }}
Determine output:public class Test{ public static void main(String args[]){ int i, j; for(i=1, j=0;i<10;i++) j += i; System.out.println(i); }}1011920
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.