Advertisement
CR7CR7

pp2

Oct 12th, 2022
519
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.24 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class LastDigit {
  3.     public static void main(String[] args) {
  4.         Scanner sc = new Scanner(System.in);
  5.         int num = Integer.parseInt(sc.nextLine());
  6.         int lastDigit = FindLastDigit(num);
  7.         switch (lastDigit) {
  8.             case 1:
  9.                 System.out.println("one");
  10.                 break;
  11.             case 2:
  12.                 System.out.println("two");
  13.                 break;
  14.             case 3:
  15.                 System.out.println("three");
  16.                 break;
  17.             case 4:
  18.                 System.out.println("four");
  19.                 break;
  20.             case 5:
  21.                 System.out.println("five");
  22.                 break;
  23.             case 6:
  24.                 System.out.println("six");
  25.                 break;
  26.             case 7:
  27.                 System.out.println("seven");
  28.                 break;
  29.             case 8:
  30.                 System.out.println("eight");
  31.                 break;
  32.             case 9:
  33.                 System.out.println("nine");
  34.                 break;
  35.             default:
  36.                 System.out.println("zero");
  37.         }
  38.  
  39.     }
  40.  
  41.  
  42.     private static int FindLastDigit(int num) {
  43.  
  44.         return Math.abs(num % 10);
  45.     }
  46. }
  47.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement