In: Computer Science
In Java I need a Flowchart and Code. Write the following method that tests whether the array has four consecutive numbers with the same value: public static boolean isConsecutiveFour(int[] values) Write a test program that prompts the user to enter a series of integers and displays it if the series contains four consecutive numbers with the same value. Your program should first prompt the user to enter the input size—i.e., the number of values in the series.
import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.print("Enter the input
size: ");
int n=sc.nextInt();
int arr[]=new int[n];
System.out.print("Enter the
sequence: ");
for(int i=0;i<n;i++)
arr[i]=sc.nextInt();
if(isConsecutiveFour(arr))
{
System.out.print("yes the array
contain consecutive number:");
for(int i=0;i<n;i++)
System.out.print(arr[i]+" ");
}
else
System.out.print("Not a consecutive
sequence");
}
public static boolean isConsecutiveFour(int[]
values){
int c=0;
//consecutive seq :- 1 2 3 4 5
whose dffirence is 1
for(int
i=0;i<values.length-1;i++)
{
if(values[i]+1==values[i+1])
c++;
}
if(c+1==values.length)
return true;
else
return false;
}
}