How to reduce the lines in this java Program
public
class Manager {
publicstaticvoid main(String[] args) {
String[] units = { " ", "one", "two", "three", "four", "five", "six",
"seven", "eight", "nine" };
String[] teens = { " ", "ten", "eleven", "twele", "thirteen",
"fourteen", "fi fteen", "sixteen", "seventeen", "eighteen",
"nineteen" };
String[] tens = { " ", "twenty", "thirty", "fourty", "fifty", "sixty",
"seventy", "eighty", "ninety", "hundred" };
Scanner nte = new Scanner(System.in);
System.out.println("Enter any Value from One to Hundred");
try {
int num = Integer.parseInt(nte.next());
if (num>1 && num < 10) {
System.out.println(units[num%10]);
} elseif (num>1 && num < 19) {
System.out.println(teens[(num/10)+(num%10)]);
} elseif (num>1 && num > 19) {
System.out.println(tens[num/10 - 1] + " "+units[num%10]);
} else {
System.out.println("Invalid Number");
}
} catch (NumberFormatException ex) {
System.out.println("Number Format Exception");
}
}
}
hai guys can anyone tellme how to reduce lines in this program
class Manager {
publicstaticvoid main(String[] args) {
String[] units = { " ", "one", "two", "three", "four", "five", "six",
"seven", "eight", "nine" };
String[] teens = { " ", "ten", "eleven", "twele", "thirteen",
"fourteen", "fi fteen", "sixteen", "seventeen", "eighteen",
"nineteen" };
String[] tens = { " ", "twenty", "thirty", "fourty", "fifty", "sixty",
"seventy", "eighty", "ninety", "hundred" };
Scanner nte = new Scanner(System.in);
System.out.println("Enter any Value from One to Hundred");
try {
int num = Integer.parseInt(nte.next());
if (num>1 && num < 10) {
System.out.println(units[num%10]);
} elseif (num>1 && num < 19) {
System.out.println(teens[(num/10)+(num%10)]);
} elseif (num>1 && num > 19) {
System.out.println(tens[num/10 - 1] + " "+units[num%10]);
} else {
System.out.println("Invalid Number");
}
} catch (NumberFormatException ex) {
System.out.println("Number Format Exception");
}
}
}
hai guys can anyone tellme how to reduce lines in this program
Replies
You are reading an archived discussion.
Related Posts
I need a simple mini project on any topic of computer that suites my qualifications and condition..........
i'm goin to enter in 5th sem by the end of this july.........
I am a great fan of such ads and this is another , in tribute to FIFA 2010.
All the animals are trained animals except the oal keeping croc which...
Hello dear fellows,
i am in urgent need of WPS (Welding Procedure Specification) of GMAW aka MIG as per Sec IX ASME.
If any one have it pls.. PM me...
PROMOTE YOUR SITE!GUYS! ITS THE SITE WE WILL ALWAYS FOLLOW AND WE SHOULD PROMOTE IT. ITS BETTER THAN ORKUT AND FACEBOOK...isnt it?
some tips!!
1. be an integral part of...
These days almost all websites have a mobile web version of theirs which are customized for surfing from mobile internet(gprs). I've noticed that there is no such thing for CE...