how to find number indexed at given number in java

given number indexed at given number
SOURCE : IndexNumber.java



public class IndexNumber {


public static void main(String[] args) {
int a = 158234554;
String sa = Integer.toString(a);
int saLen = sa.length();

int b = 2345;
String sb = Integer.toString(b);
int sbLen = sb.length();

int match;

for( int i = 0 ; i < saLen ; i++ ) {

match = 1;

if( sa.charAt(i) == sb.charAt(0) ) {

for( int j = 0 ; j < sbLen ; j++ ) {
if( sa.charAt(i+j) != sb.charAt(j) ) {
match = 0;
break;
}
}

if( match == 1 ) {
System.out.println(" Index Found at i : " + i);
System.exit(0);
}

}

}

}

}



INPUT

int a = 158234554;
int b = 2345;



OUTPUT

Index Found at i : 3







Sandeep Kumar D

Hi, I have written and developed this post so that most of people will be benefited. I'm committed to provide easy and in-depth tutorials on various technologies.I hope it will help you a lot.

- Sandeep Kumar D

Follow Me @Google+




SHARE

    Blogger Comment
    Facebook Comment

0 comments :

Post a Comment