Advertisement
Hiteshw11

Increment Factor In Array

Jan 20th, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.91 KB | None | 0 0
  1. import java.util.*;
  2. class IncrementByOne {
  3.     public static void main(String[] args) {
  4.         int n;
  5.         Scanner src=new Scanner(System.in);
  6.         System.out.println("Enter the size of array");
  7.         n=src.nextInt();
  8.         int a[]=new int[n];
  9.         for(int i=0;i<n;i++)
  10.         {
  11.             System.out.println("Enter the element");
  12.             a[i]=src.nextInt();
  13.         }
  14.         System.out.println("The array is ");
  15.         for(int j=0;j<n;j++)
  16.         {
  17.             System.out.println(a[j]);
  18.         }
  19.         System.out.println("What increment factor do you need?");
  20.         int inc=src.nextInt();
  21.         for(int k=0;k<n;k++)
  22.         {
  23.             int temp=a[k]+inc;
  24.             a[k]=temp;
  25.         }
  26.         System.out.println("The new array is with the increment factor "+inc+" is");
  27.         for(int m=0;m<n;m++)
  28.         {
  29.             System.out.println(a[m]);
  30.         }
  31.  
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement