Java program to display the elements in an array

PROGRAM 1:

package com.company;
import java.io.*;
public class Main {

public static void main(String[] args) {
int[] num ={1,5,6,77,88};
for(int i=0;i<num.length;i++)
{System.out.println(num[i]);
}}}

PROGRAM 2:
package com.company;
import java.io.*;
public class Main {
public static void main(String[] args) {
int[] num ={1,5,6,77,88};
for(int i:num)
{
System.out.println(i);
}}}

OUTPUT:
Output for both Progarm 1 and Program 2 are same as below
1
2
6
77
88

Comments

Popular posts from this blog

Java Program to create a large array and copy its values equally to two small arrays and display the second array only

Python program to sum up the Salary when the Name and Age matches with subsequent rows.