Read One-dimensional array having 5 elements from user and add amount of 15 in each element.

 

AIM: Read a One-dimensional array having 5 elements from user and add amount of 15 in each element.

CODE:

import java.util.Scanner;

public class p7

{

   public static void main( String args[] )

    {

            Scanner readme = new Scanner(System.in);

            int a[]=new int[5];

            System.out.println("Enter 5 Elemenys for array\n");

            for(int i=0;i<5;i++)

            {

                                    a[i] = readme.nextInt();

                                    a[i]+=15;

            }

            System.out.println("After adding 15:\n");

 

            for(int i=0;i<5;i++)

            {

                        System.out.println(a[i]);

            }

 

   }

}

 

OUTPUT:



Comments

Popular posts from this blog

Write a program in Java to demonstrate use of final class.

Write a java program to create 3 threads using Thread class. Three threads should calculate the sum of 1 to 5, 6 to 10 and 11to 15 respectively. After all thread finishes main thread should print the sum and average.

Write a program in Java to demonstrate single inheritance, multilevel inheritance and hierarchical inheritance.