Home  • Programming • Java
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


thnx sir Happy Tongue out thing really DO work out for me if i see an example Tongue out but how do i post it like this as a comment
To make post title write title inside [h1] your post title [/h1]
Try again for comment same way as you did in main post
About Author
Arshiful Islam Shadman
Copyright © 2024. Powered by Intellect Software Ltd