题解 | #简单密码#

简单密码

http://www.nowcoder.com/practice/7960b5038a2142a18e27e4c733855dac

import java.util.Scanner;

public class Main{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); String str = sc.nextLine(); char[] strings = str.toCharArray(); StringBuilder s = new StringBuilder(); for(int i = 0; i< strings.length;i++){ if(strings[i] >='a' && strings[i] <='c'){ s.append("2"); }else if(strings[i] >='d' && strings[i] <='f'){ s.append("3"); }else if(strings[i] >='g' && strings[i] <='i'){ s.append("4"); }else if(strings[i] >='j' && strings[i] <='l'){ s.append("5"); }else if(strings[i] >='m' && strings[i] <='o'){ s.append("6"); }else if(strings[i] >='p' && strings[i] <='s'){ s.append("7"); }else if(strings[i] >='t' && strings[i] <='v'){ s.append("8"); }else if(strings[i] >='w' && strings[i] <='z'){ s.append("9"); }else if(strings[i] >= '0' && strings[i] <='9'){ s.append(strings[i]); }else if(strings[i] >='A' && strings[i] <='Z'){ if(strings[i] + 32 != 'z') strings[i] += 33; else strings[i] = 'a'; s.append(strings[i]); }

    }
      System.out.print(s);
}

}

全部评论

相关推荐

点赞 1 评论
分享
牛客网
牛客企业服务