import java.util.Scanner;
public class numberformat {
public void pw(int n, String ch) {
String one[] = { " ", " One", " Two", " Three", " Four", " Five", " Six", " Seven", " Eight", " Nine", " Ten"};
if (n<=10)
{
System.out.print(one[n]);
}
if (n > 0)
System.out.print(ch);
}
public static void main(String[] args)
{
int n = 0;
Scanner scanf = new Scanner(System.in);
System.out.println("Enter an integer number: ");
n = scanf.nextInt();
if (n <= 0)
{
System.out.println("Enter numbers greater than 0");
}
else{
numberformat a = new numberformat();
a.pw((n / 1000000000), " Hundred");
a.pw((n / 10000000) % 100, " billion");
a.pw(((n / 100000) % 100), " million");
a.pw(((n / 1000) % 100), " thousand");
a.pw(((n / 100) % 10), " hundred");
a.pw((n % 100), " ");
}
}
}
如何插入 NumberFormatException
和显示器 Error
,如果用户没有输入数字。
1条答案
按热度按时间3vpjnl9f1#
添加输入方法,因为如果数字不大于,则必须重新输入数字zero:-
在“main”中编辑method:-