fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12.  
  13. //Integer values
  14. int a=01;
  15. int b=19517865;
  16.  
  17. String s1,s2;
  18. s1=Integer.toString(a);
  19. s2=Integer.toString(b);
  20.  
  21. System.out.println(s2.indexOf(s1)+" result");
  22.  
  23. //fun() is for converting the integer to an array with same order.
  24. int arra[] = fun(a);
  25. int arrb[] = fun(b);
  26.  
  27. //FunA() function which takes two array as input ,do the main task and return the result.
  28.  
  29. System.out.println(FunA(arra,arrb)+" This is the result");
  30.  
  31. }
  32.  
  33. //
  34.  
  35. public static int FunA (int [] A , int [] B){
  36.  
  37. int [] arra = A; //Array having the small part of main integer
  38. int [] arrb = B; //Array having the main big integer
  39. int result=-1; //return value
  40.  
  41. for(int i1 = 0; i1< arrb.length; i1++){
  42. if (arra[0] == arrb[i1] ){
  43. if(arra.length == 1)
  44. {result =i1;
  45. break; }
  46. else{
  47. try{
  48.  
  49. for(int k =1 ; k < arra.length;k++ ){
  50. if(arra[k] == arrb[i1+k])
  51. {
  52. result=1;}
  53. else
  54. {result=-1 ; break;}
  55. }
  56.  
  57. }catch (Exception e ){
  58. System.out.println(e+" exception in loop, most probabbl;y array out of bound");
  59. }
  60.  
  61. if(result == 1)
  62. {result = i1; break;}
  63. }
  64.  
  65. }
  66.  
  67. }
  68. return result;
  69. }
  70.  
  71.  
  72. public static int[] fun(int num){
  73.  
  74. int n= num;
  75. int l = Integer.toString(n).length();
  76. int arr[] = new int[l];
  77.  
  78. try{
  79. for(int k= (l-1); k>=0; k--){
  80. arr[k]= n %10;
  81. n=n/10;
  82. }
  83. }catch (Exception e ){
  84. System.out.println(" exception in array building functionfunction");
  85. }
  86. return arr;
  87.  
  88. }
  89.  
  90.  
  91. }
Success #stdin #stdout 0.09s 33852KB
stdin
Standard input is empty
stdout
0  result
0  This is the result