Comments
-26

Hi guys, I did join this website yesterday. and I am really happy for this. Few minutes ago I did submit my attempt to solve the problem A but I see runtime error on test1.

I am quasi sure that my solution is working well. I did use java. should I stop using things like demanding the user to enter an input "java.util.Scanner" ? please help me!

The solution is bellow :

package javaapplication7;
import java.util.Scanner;
public class JavaApplication7 {
    public static void main(String[] args) {
        //Reading user's number and adding leading zeros 
        Scanner s = new Scanner(System.in);
        System.out.println("Enter the number please");
        Long in = s.nextLong();
        String in_to_str = in+"";
                
        int in_last_index = in_to_str.length()-1;
        String sub_str_to_add = "";
        while(in_to_str.charAt(in_last_index)=='0'){
            sub_str_to_add=sub_str_to_add+"0";
            in_last_index--;
        }
        in_to_str = sub_str_to_add + in_to_str;
       
        //testing whether it's a palindromic or NOT
        int in_len = in_to_str.length();
        int ind_diff=-1;
        for (int start=0,end=in_len-1;start<in_len/2&&end>in_len/2;end--,start++){
            if(in_to_str.charAt(start)!=in_to_str.charAt(end))
            {
                ind_diff = start;
                break; 
            }       
        }
           
        /* the second part of the if condition [in_len==2&&in_to_str.charAt(0)!=in_to_str.charAt(1)] 
        is to treat the case of a number composed of two digits which is not included in the previous test */
        if(ind_diff<in_len/2&&ind_diff!=-1||in_len==2&&in_to_str.charAt(0)!=in_to_str.charAt(1))
        System.out.println("The number "+in+" is NOT quasi-palindromic");
        else 
        System.out.println("The number "+in+" is quasi-palindromic");            
    }   
}