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 an application that illustrates method overriding in the same package and different packages. Also demonstrate accessibility rules in inside and outside packages

Describe abstract class called Shape which has three subclasses say Triangle, Rectangle, and Circle. Define one method area()in the abstract class and override this area() in these three subclasses to calculate for specific object.

Write a Java Program with class Rectangle having instance variable width, length, area and colour. Create methods like setData() and area().Create two object of Rectangle and compare their area and colour. If area and colour both are the same for the objects then display “Matching Rectangles”, otherwise display “Non matching Rectangle”.