Advertisement
Guest User

Untitled

a guest
Feb 6th, 2016
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.util.Arrays;
  3.  
  4. public class wordsto {
  5.  
  6. public static void main(String[] args) {
  7. int input = new Scanner(System.in).nextInt();
  8.  
  9. int a = (input / 10) -2 ;
  10. int b = (input % 10) ;
  11. String[] zeroToNineteen = new String[]{"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten",
  12. "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"};
  13.  
  14. String[] tens = new String[]{"twenty", "thirty", "fourty", "fifty", "sixty", "seventy", "eighty", "ninety" };
  15.  
  16. if(input >= 0 && input <= 100 ){
  17. if(input >= 0 && input <=19){
  18. System.out.println(zeroToNineteen[input]);
  19. }else if(input == 100){
  20. System.out.println("one hundred");
  21. }else if(input % 10==0 && input>=20 && input < 100){
  22. System.out.println(tens[a]);
  23. }else{
  24. System.out.println(tens[a] + " " + zeroToNineteen[b]);
  25. }
  26.  
  27. }else{
  28. System.out.println("invalid number");
  29. }
  30. }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement