Oo ganyan poAh bale pag nag input ka ng 991 ang lalabas yung Ninehundred ninenty one? Note pad bale cmd, cd, tapus javac filename.java
Salamat rito pero alam.ko na po yanCheck it buddy, google is your friend.
You do not have permission to view the full content of this post. Log in or register now.
Salamat po ng sobra pasensiya na poCode:import java.util.Scanner; public class Test1 { public static void main(String[] args) { int number = 0; Scanner scanner = new Scanner(System.in); System.out.print("Please type a number between 0 and 999 OR type -1 to exit: "); number = scanner.nextInt(); while(number!=-1){ if(number>=0 && number<=999){ if(number==0){ System.out.print("NUMBER AFTER CONVERSION:\tZERO"); } else { System.out.print("NUMBER AFTER CONVERSION:\t"); numberToWord(((number / 100) % 10), " HUNDRED"); numberToWord((number % 100), " "); } } else{ System.out.print("NUMBER OUT OF RANGE"); } System.out.print("\nPlease type a number between 0 and 999 OR type -1 to exit: "); number = scanner.nextInt(); } } public static void numberToWord(int num, String val) { String ones[] = {" ", " ONE", " TWO", " THREE", " FOUR", " FIVE", " SIX", " SEVEN", " EIGHT", " NINE", " TEN", " ELEVEN", " TWELVE", " THIRTEEN", " FOURTEEN", " FIFTEEN", " SIXTEEN", " SEVENTEEN", " EIGHTEEN", " NINETEEN" }; String tens[] = {" ", " ", " TWENTY", " THIRTY", " FOURTY", " FIFTY", " SIXTY", " SEVENTY", " EIGHTY", " NINETY"}; 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); } } }
Welcome po.Salamat po ng sobra pasensiya na po
Nag pm po ako pero bukas na lang ako mag tanungWelcome po.
Ok po nag aaral din po kasi ako ng java gusto ko kasi masterin din yung java nag simula din po kami dyan sa notepad saka sa cmd din namen po pinapa run.Nag pm po ako pero bukas na lang ako mag tanung
Talga gumamit ng loop?Welcome po.
Buti po nag reply ka nahihirapan ako mapa run sa java e di kasi lumalabas code ko sa cmd e file not found nakalagay eOk po nag aaral din po kasi ako ng java gusto ko kasi masterin din yung java nag simula din po kami dyan sa notepad saka sa cmd din namen po pinapa run.
Ano po error?Buti po nag reply ka nahihirapan ako mapa run sa java e di kasi lumalabas code ko sa cmd e file not found nakalagay e
Cd ka po muna tapus javac filename.java tapus filename.javaAno po error?
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);
}
}
}
Buti po nag reply ka nahihirapan ako mapa run sa java e di kasi lumalabas code ko sa cmd e file not found nakalagay e
Tigilan mo koate namiss kana ni menin bat di kana daw nag popost ng meme nyahahahhahhahaa
Ang sakit sa ulo neto
You do not have permission to view the full content of this post. Log in or register now.
Logic side written in C# Console which is very similar to Java
This will convert from 0 to Millions. from negative to positive to integers to decimal point.
*Max is 2M input.
//Conversion for Decimals
private static string DecimalToWords(decimal number)
{
string inWords = "";
int firstNumber, secondNumber = 0;
string[] splitNumber = new string[2];
splitNumber = number.ToString().Split('.');
firstNumber = int.Parse(splitNumber[0]);
secondNumber = int.Parse(splitNumber[1]);
inWords += IntegerToWords(firstNumber) + " Point " + IntegerToWords(secondNumber);
return inWords;
}
//Convertion for Integers
private static string IntegerToWords(int number)
{
string inWords = "";
string[] Units = new string[] { "Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen" };
string[] Tens = new string[] { "Zero", "Ten", "Twenty", "Thirty", "Forty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninety" };
if (number == 0)
{
return "Zero";
}
if (number < 0)
{
return "Negative " + IntegerToWords(Math.Abs(number));
}
inWords = "";
if ((number / 1000000) > 0)
{
inWords += IntegerToWords(number / 1000000) + " Million ";
number %= 1000000;
}
if ((number / 1000) > 0)
{
inWords += IntegerToWords(number / 1000) + " Thousand ";
number %= 1000;
}
if ((number / 100) > 0)
{
inWords += IntegerToWords(number / 100) + " Hundred ";
number %= 100;
}
if (number > 0)
{
if (number < 20)
{
inWords += Units[number];
}
else
{
inWords += Tens[number / 10];
if ((number % 10) > 0)
{
inWords += "-" + Units[number % 10];
}
}
}
return inWords;
}
//Conversion for Decimals
private static string DecimalToWords(decimal number)
{
string inWords = "";
int firstNumber, secondNumber = 0;
string[] splitNumber = new string[2];
splitNumber = number.ToString().Split('.');
firstNumber = int.Parse(splitNumber[0]);
secondNumber = int.Parse(splitNumber[1]);
inWords += IntegerToWords(firstNumber) + " Point " + IntegerToWords(secondNumber);
return inWords;
}
//Convertion for Integers
private static string IntegerToWords(int number)
{
string inWords = "";
string[] Units = new string[] { "Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen" };
string[] Tens = new string[] { "Zero", "Ten", "Twenty", "Thirty", "Forty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninety" };
if (number == 0)
{
return "Zero";
}
if (number < 0)
{
return "Negative " + IntegerToWords(Math.Abs(number));
}
inWords = "";
if ((number / 1000000) > 0)
{
inWords += IntegerToWords(number / 1000000) + " Million ";
number %= 1000000;
}
if ((number / 1000) > 0)
{
inWords += IntegerToWords(number / 1000) + " Thousand ";
number %= 1000;
}
if ((number / 100) > 0)
{
inWords += IntegerToWords(number / 100) + " Hundred ";
number %= 100;
}
if (number > 0)
{
if (number < 20)
{
inWords += Units[number];
}
else
{
inWords += Tens[number / 10];
if ((number % 10) > 0)
{
inWords += "-" + Units[number % 10];
}
}
}
return inWords;
}
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?