
mata mea code ekata user input karana number eka check karanna one 900 walata wada wadida kiyala wadinam invalid kiyala awith ayeth number eka input karanna kiyala kiyanna ona, mama loops dala try kala eth errors enawa godak pls help me
import java.util.Scanner;
import javax.swing.JOptionPane;
class NumberToString
{
public enum hundreds {OneHundred, TwoHundred, ThreeHundred, FourHundred, FiveHundred, SixHundred, SevenHundred, EightHundred, NineHundred}
public enum tens {Twenty, Thirty, Forty, Fifty, Sixty, Seventy, Eighty, Ninety}
public enum ones {One, Two, Three, Four, Five, Six, Seven, Eight, Nine}
public enum denom {Thousand, Lakhs, Crores}
public enum splNums { Ten, Eleven, Twelve, Thirteen, Fourteen, Fifteen, Sixteen, Seventeen, Eighteen, Nineteen}
public static String text = "";
public static void main(String[] args)
{
JOptionPane.showMessageDialog(null," Welcome to my maths app");
long num=0;
System.out.println("input number between one and nine hundred");
Scanner sc = new Scanner(System.in);
num = sc.nextInt();
int rem = 0;
int i = 0;
long r = num;
long hundreds = r/100;
long Tens = (r-hundreds*100)/10;
long Ones = r-(hundreds*100+Tens*10);
System.out.print("Hundreds : ");
for(int h=0; h<hundreds; h++){
System.out.print("o");
}
System.out.println("");
System.out.print("Tens : ");
for(int h=0; h<Tens; h++){
System.out.print("o");
}
System.out.println("");
System.out.print("Ones : ");
for(int h=0; h<Ones; h++){
System.out.print("o");
}
System.out.println("");
while(num > 0)
{
if(i == 0){
rem = (int) (num % 1000);
printText(rem);
num = num / 1000;
i++;
}
else if(num > 0)
{
rem = (int) (num % 100);
if(rem > 0)
text = denom.values()[i - 1]+ " " + text;
printText(rem);
num = num / 100;
i++;
}
}
if(i > 0)
System.out.println(text);
else
System.out.println("Zero");
}
public static void printText(int num)
{
if(!(num > 9 && num < 19))
{
if(num % 10 > 0)
getOnes(num % 10);
num = num / 10;
if(num % 10 > 0)
getTens(num % 10);
num = num / 10;
if(num > 0)
getHundreds(num);
}
else
{
getSplNums(num % 10);
}
}
public static void getSplNums(int num)
{
text = splNums.values()[num]+ " " + text;
}
public static void getHundreds(int num)
{
text = hundreds.values()[num - 1]+ " " + text;
}
public static void getTens(int num)
{
text = tens.values()[num - 2]+ " " + text;
}
public static void getOnes(int num)
{
text = ones.values()[num - 1]+ " " + text;
}
}
Last edited:



udaw karapankoo