-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConsecutiveNumbers.java
49 lines (41 loc) · 1.25 KB
/
ConsecutiveNumbers.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/* Read input from STDIN. Print your output to STDOUT*/
import java.util.*;
import java.io.*;
public class ConsecutiveNumbers {
public boolean consecutiveNumber(int arr[]){
int i,j;
boolean flag=false;
for(i=0;i<arr.length-1;i++){
if(Math.abs(arr[i]-arr[i+1])==1){
System.out.println("Compare: " +"arr[i+1]: " +arr[i+1]+ " arr[i] :"+arr[i]);
flag=true;
}
else{
System.out.println("False "+"arr[i+1]: " +arr[i+1]+ " arr[i] :"+arr[i]);
return flag=false;
}
}
return flag;
}
public static void main(String args[] ) throws Exception {
//Write code here
Scanner sc=new Scanner(System.in);
System.out.print("Size: ");
int mSize=sc.nextInt();
System.out.print("Value: ");
int[] Array=new int[mSize];
for(int i=0;i<Array.length;i++){
Array[i]=sc.nextInt();
}
// for removing error
// class obj & accessing method using that object i.e obj
ConsecutiveNumbers obj=new ConsecutiveNumbers();
boolean result=obj.consecutiveNumber(Array);
if(result==true)
{
System.out.print("True");
}
else
System.out.print("False");
}
}