What's new

Closed Pa help po sa java

Status
Not open for further replies.
Code:
import java.util.*;

public class NumberToWords
{
    static int number;
    static Scanner userInput;
    static String ones[] = {" ", " ONE", " TWO", " THREE", " FOUR", " FIVE", " SIX", " SEVEN", " EIGHT", " NINE", " TEN", " ELEVEN", " TWELVE", " THIRTEEN", " FOURTEEN", " FIFTEEN", " SIXTEEN", " SEVENTEEN", " EIGHTEEN", " NINETEEN"};
    static String tens[] = {" ", " ", " TWENTY", " THIRTY", " FOURTY", " FIFTY", " SIXTY", " SEVENTY", " EIGHTY", " NINETY"};
    static int num;
    static String val;
  
    public static void main ( String [] args){
      
        initializeNumber();
      
        initializeScanner();
      
        whileNumber();
      
        logic(num,val);
      
    }
  
    static void initializeNumber(){
        number = 0;
    }
  
    static void initializeScanner(){
      
        userInput = new Scanner(System.in);
    }
  
    static void whileNumber(){
      
      
        System.out.print("Please type a number between 0 and 999  \n");
        number = userInput.nextInt();
          
        if(number>=0 && number<=999){
            if(number==0){
                System.out.print("NUMBER AFTER CONVERSION:\tZERO");
            } else {
                System.out.print("NUMBER AFTER CONVERSION:\t");
                logic(((number / 100) % 10), " HUNDRED");
                logic((number % 100), " ");
            }

        } else{
            System.out.print("NUMBER OUT OF RANGE");
        }
        System.out.print("\nPlease type a number between 0 and 999 OR  \n");  
  
}
  
    static void logic(int num, String val){
        if (num > 19) {
            System.out.print(tens[num / 10] + " " + ones[num % 10]);
        } else {
            System.out.print(ones[num]);
        }
        if (num > 0) {
            System.out.print(val);
        }
    }
}
ate wala ba 9999?
 
Status
Not open for further replies.

Similar threads

Back
Top