View Code of Problem 3931

import java.util.*;
public class Main {
	public static void main(String[] args) {
	      Scanner in=new Scanner(System.in);
	      int t=in.nextInt();
	      for(int i =0;i<t;i++) {
	    	  char[] ch = in.next().toCharArray();
	    	  for(char c:ch) {
	    		  if(c>='0' && c<='9') {
	    			  System.out.print(c);
	    		  }else {
	    			  System.out.print(pass(c));  
	    		  }
	    	  }
	    	  System.out.println();
	      }
	}
	public static char pass(char ch) {
		if(ch>'A' && ch<='Z') {
			if(ch=='Z') {
				return '2';
			}else {
				ch= (char)((2+(ch+33-97)/3)+(int)'0');
				return ch;
			}
		}else{
			if(ch=='z') {
				return '9';
			}else {
				ch= (char)((2+(ch-97)/3)+(int)'0');
				return ch;
			}
		}
	}
}

Double click to view unformatted code.


Back to problem 3931