Print Int to String (im getting correct output failing testcases ,kindly help)

import java.io.;
import java.util.
;

public class Main {

public static void main(String[] args) throws Exception {
Scanner scn=new Scanner(System.in);
String str=scn.nextLine();
printEncodings(str," ");
}

public static void printEncodings(String str,String asf) {
   if(str.length()==0){
        System.out.println(asf);
        return;
    }
    
    char ch1=str.charAt(0);
    int pos1=Integer.parseInt(ch1+"");
    printEncodings(str.substring(1),asf+(char)('A'+pos1-1));
    
     if(str.length()>2){
        char ch2=str.charAt(1);
        char ch3=str.charAt(2);
       int pos3=Integer.parseInt(""+ch2+ch3);
       if(pos3>=10||pos3<=26){
    printEncodings(str.substring(3),asf+(char)('A'+pos1-1)+ (char)('A'+pos3-1));
       }        
    }
    if(str.length()>2){
        char ch2=str.charAt(1);
       int pos2=Integer.parseInt(""+ch1+ch2);
       if(pos2>=10||pos2<=26){
    printEncodings(str.substring(2),asf+(char)('A'+pos2-1));
       }        
    }
    
}

}

for input 9999 output should be just IIII
you re getting

 IIII
 II£
 I£I
 I£I
 £II

Then do help me with this code ,im asking to help,i know im getting wrong output .

try debugging your code for this test case.if you still dont get it do let me know :slight_smile:

Now only im able to handle that case and getting failed in other test cases

import java.io.;
import java.util.
;

public class Main {

public static void main(String[] args) throws Exception {
Scanner scn=new Scanner(System.in);
String str=scn.nextLine();
printEncodings(str," ");
}

public static void printEncodings(String str,String asf) {
   if(str.length()==0){
        System.out.println(asf);
        return;
    }
    
    char ch1=str.charAt(0);
    int pos1=Integer.parseInt(ch1+"");
    printEncodings(str.substring(1),asf+(char)('A'+pos1-1));
    
    //  if(str.length()>2){
    //     char ch2=str.charAt(1);
    //     char ch3=str.charAt(2);
    //    int pos3=Integer.parseInt(""+ch2+ch3);
    //    if(pos3>=10||pos3<=26){
    // printEncodings(str.substring(3),asf+(char)('A'+pos1-1)+ (char)('A'+pos3-1));
    //    }        
    // }
    // if(str.length()>2){
    //     char ch2=str.charAt(1);
    //    int pos2=Integer.parseInt(""+ch1+ch2);
    //    if(pos2>=10||pos2<=26){
    // printEncodings(str.substring(2),asf+(char)('A'+pos2-1));
    //    }        
    // }
    
}

}

try to help me in the code

sure, please share your code after saving it on ide.codingblocks.com

no youre getting a stray space before the ans IIII

you can see this:

use ide for sharing code in future
if this solves your doubt mark it resolved :slight_smile:

Mam pls help me with the code ,I got stuck .

Kindly help me

Do debug the code ,I’m not able to solve it .

what help do you need ? i corrected your code