Advertisement
desislava_topuzakova

05. Messages

Jan 14th, 2023
484
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Messages_05 {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6. int countLetters = Integer.parseInt(scanner.nextLine());
  7.  
  8. for (int i = 1; i <= countLetters ; i++) {
  9. int inputNumbers = Integer.parseInt(scanner.nextLine());
  10. //44 -> "44"
  11. String numberAsText = Integer.toString(inputNumbers);
  12. int digitsCount = numberAsText.length();
  13. int mainDigit = inputNumbers % 10;
  14. int offset = (mainDigit - 2) * 3;
  15. if(mainDigit == 8 || mainDigit == 9) {
  16. offset++;
  17. }
  18. int letterIndex = offset + digitsCount - 1;
  19. if(inputNumbers == 0) {
  20. System.out.print(" ");
  21. } else {
  22. System.out.print((char)(letterIndex + 97));
  23. }
  24.  
  25. }
  26. }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement