package ques3; import javax.swing.JOptionPane; public class Consecutive { public static void main(String[] args) { int [] input = new int [4]; int number= Integer.parseInt(JOptionPane.showInputDialog("Enter a 4 digit or less positive number:")); for (int i=3; i>=0; i=i-1){ input[i]=number%10; number=number/10; } if((IsConsecutive(input[3],input[2],input[1],input[0]))==true){ System.out.println("The number is Consecutive"); }else{ System.out.println("The number is NOT Consecutive"); } } public static boolean IsConsecutive(int ones,int tens,int hundreds, int thousands) { if( (ones==tens+1) || ((ones==tens+1)&& (tens==hundreds+1)) || ((ones==tens+1)&&(tens==hundreds+1)&&(hundreds==thousands+1)) ){ return true; }else{ return false; } } }
Comments 3