Computer Science, asked by kritikawagish, 29 days ago

write a program in java to store 20 numbers in S.D.A and display all those numbers which are consecutive​

Answers

Answered by kamalrajatjoshi94
2

Answer:

import java.util.*;

public class Main

{

public static void main(String args[])

{

Scanner in=new Scanner(System.in);

int a[]=new int[20];

int f=1;

System.out.println("Enter the elements of the array:");

for(int i=0;i<a.length;i++)

{

a[i]=in.nextInt();

}

System.out.println("Consecutive numbers are:");

for(int i=0;i<a.length;i++)

{

if(a[i+f]-a[i]==1||a[i]-a[i+f]==1)

System.out.println(a[i]+","+a[i+f]);

if(i+f==19)

break;

}

}

}

Attachments:
Similar questions