Java Program For Input Numbers in Array

By | July 3, 2019

Task: Java Program For Input Numbers in Array and display them.

The source code for  Java program to declare and enter numbers in array, and display them using for loop

/*
 * Write a Java program to declare 
one dimentionalarray of 10 integers. Input 
numbers using for loop and display them.
 */
package inputnumbersarray;
import java.util.Scanner;
/**
 * @author www.EasyCodeBook.com
 */
public class InputNumbersArray {

    public static void main(String[] args) {
        int a[] = new int[10], i ;
        Scanner input = new Scanner(System.in);
        for(i=0;i<10;i++)
        {
        System.out.print("Enter number "+(i+1)+ " in array=");
        a[i] = input.nextInt();
        }
       System.out.println("You have entered the following values in Array:");
       for(i=0;i<10;i++)
           System.out.print(a[i]+", ");
    }
}

Output of the Java program to declare array of 10 integers, input and output of 10 numbers in array

Enter number 1 in array=10
Enter number 2 in array=20
Enter number 3 in array=30
Enter number 4 in array=40
Enter number 5 in array=50
Enter number 6 in array=60
Enter number 7 in array=70
Enter number 8 in array=80
Enter number 9 in array=90
Enter number 10 in array=100
You have entered the following values in Array:
10, 20, 30, 40, 50, 60, 70, 80, 90, 100,

One thought on “Java Program For Input Numbers in Array

  1. Pingback: Java Arrays sort Method to Sort Arrays » EasyCodeBook.com

Leave a Reply

Your email address will not be published. Required fields are marked *