Advertisement
damesova

05-Messages-FORMULA

Jan 25th, 2019
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.94 KB | None | 0 0
  1. package _03_RevisionMoreExcercises;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class _05_Messeges1 {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.  
  9.         int n = Integer.parseInt(scanner.nextLine());
  10.  
  11.         for (int i = 1; i <= n; i++) {
  12.             String input = scanner.nextLine();
  13.             int numbersDigits = input.length();
  14.             if (input.equals("0")) {
  15.                 System.out.print(" ");
  16.             } else {
  17.                 int number = Integer.parseInt(input);
  18.                 int digit = number % 10;
  19.                 int offset = 0;
  20.                 if (digit == 8 || digit == 9) {
  21.                     offset = (digit - 2) * 3 + 1;
  22.                 } else {
  23.                     offset = (digit - 2) * 3;
  24.                 }
  25.                 int index = offset + numbersDigits - 1;
  26.                 System.out.print((char) (index + 97));
  27.             }
  28.         }
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement