Knowee
Questions
Features
Study Tools

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

Question

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

🧐 Not the exact question you are looking for?Go ask a question

Solution

Here is the completed code:

public class Main{    
    public static void main(String args[])    
    {                
        int arr[]={50,70,80,90,100};                
        //fill code to print the array               
        for(int num : arr)                           
            System.out.println(num);    
    }
}

In the for-each loop, int num : arr means for each integer num in the array arr. The loop will iterate over each element in the array and print it to the console.

This problem has been solved

Similar Questions

Predict the output?       int arr[] = {10, 20, 30, 40, 50};       for(int i=0; i < arr.length; i++)       {             System.out.print(" " + arr[i]);                     }

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

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] + " "); }}

Find the output:class PrintNumber {    public static void main(String args[]) {          System.out.println(print());    }    int print() {        return 30;    }}

import java.util.Scanner;public class Test { public static void main(String[] args) { Scanner sc=new Scanner(System.in); System.out.println("Enter the number of elements in the array"); int n = sc.nextInt(); //Declare the array int arr[ ]=new int[n]; //Get the elements from user System.out.println("Enter the elements of the array"); for(int i=0;i<n;i++){ arr[i]=sc.nextInt(); } //Code to find the sum of odd elements in the array int sum=findSumOddElements();   // invoke the method System.out.println("The sum is "+);        } public int findSumOddElements() { int sum=0; for(int i=0;i<;i++) { if(()!=0) { sum=sum+arr[i]; } }   ;  //return statement }}

1/3

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.