怎么把输入的阿拉伯数字转成英文?
展开全部
很简单的程序,我就不写注释了吧import java.util.Scanner;
public class EnglishNumberFormatter {
private static final String[] BITS = {"ONE", "TWO", "THREE", "FOUR", "FIVE",
"SIX", "SEVEN", "EIGHT,", "NINE", "TEN"};
private static final String[] TEENS = {"ELEVEN", "TWELF", "THIRTEEN",
"FOURTEEN", "FIFTEEN", "SIXTEEN", "SEVETEEN", "EIGHTEEN", "NIGHTEEN"};
private static final String[] TIES = {"TWENTY", "THRITY", "FORTY", "FIFTY",
"SIXTY", "SEVENTY", "EIGHTY", "NINETY"};
private static Scanner sc;
public static void main(String[] args) {
sc = new Scanner(***.in);
int num = 0;
while(num != -1) {
System.out.print("Please type a number between 0 and 999: ");
num = sc.nextInt();
if(num <0 || num > 999) {
continue;
}
String english = toEnglish(num);
System.out.println(english);
}
System.out.println("Thank you for using this program");
}
private static String toEnglish(int num) {
if(num == 0) {
return "Zero";
}
StringBuffer buffer = new StringBuffer();
if(num >= 100) {
buffer.append(pickHunder(num));
if(num % 100 != 0) {
buffer.append(" AND ");
}
num -= (num / 100) * 100;
}
boolean largerThan20 = false;
if(num >= 20) {
largerThan20 = true;
buffer.append(pickTies(num));
num -= (num / 10) * 10;
}
if(!largerThan20 && num > 10) {
buffer.append(pickTeens(num));
num = 0;
}
if(num > 0) {
String bit = pickBits(num);
if(largerThan20) {
buffer.append(" ");
}
buffer.append(bit);
}
return buffer.toString();
}
private static String pickHunder(int num) {
int hunder = num / 100;
return BITS[hunder - 1] + " HUNDER";
}
private static String pickTies(int num) {
int ties = num / 10;
return TIES[ties - 2];
}
private static String pickTeens(int num) {
return TEENS[num - 11];
}
private static String pickBits(int num) {
return BITS[num - 1];
}
}
public class EnglishNumberFormatter {
private static final String[] BITS = {"ONE", "TWO", "THREE", "FOUR", "FIVE",
"SIX", "SEVEN", "EIGHT,", "NINE", "TEN"};
private static final String[] TEENS = {"ELEVEN", "TWELF", "THIRTEEN",
"FOURTEEN", "FIFTEEN", "SIXTEEN", "SEVETEEN", "EIGHTEEN", "NIGHTEEN"};
private static final String[] TIES = {"TWENTY", "THRITY", "FORTY", "FIFTY",
"SIXTY", "SEVENTY", "EIGHTY", "NINETY"};
private static Scanner sc;
public static void main(String[] args) {
sc = new Scanner(***.in);
int num = 0;
while(num != -1) {
System.out.print("Please type a number between 0 and 999: ");
num = sc.nextInt();
if(num <0 || num > 999) {
continue;
}
String english = toEnglish(num);
System.out.println(english);
}
System.out.println("Thank you for using this program");
}
private static String toEnglish(int num) {
if(num == 0) {
return "Zero";
}
StringBuffer buffer = new StringBuffer();
if(num >= 100) {
buffer.append(pickHunder(num));
if(num % 100 != 0) {
buffer.append(" AND ");
}
num -= (num / 100) * 100;
}
boolean largerThan20 = false;
if(num >= 20) {
largerThan20 = true;
buffer.append(pickTies(num));
num -= (num / 10) * 10;
}
if(!largerThan20 && num > 10) {
buffer.append(pickTeens(num));
num = 0;
}
if(num > 0) {
String bit = pickBits(num);
if(largerThan20) {
buffer.append(" ");
}
buffer.append(bit);
}
return buffer.toString();
}
private static String pickHunder(int num) {
int hunder = num / 100;
return BITS[hunder - 1] + " HUNDER";
}
private static String pickTies(int num) {
int ties = num / 10;
return TIES[ties - 2];
}
private static String pickTeens(int num) {
return TEENS[num - 11];
}
private static String pickBits(int num) {
return BITS[num - 1];
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
很简单的程序,我就不写注释了吧import java.util.Scanner;
public class EnglishNumberFormatter {
private static final String[] BITS = {"ONE", "TWO", "THREE", "FOUR", "FIVE",
"SIX", "SEVEN", "EIGHT,", "NINE", "TEN"};
private static final String[] TEENS = {"ELEVEN", "TWELF", "THIRTEEN",
"FOURTEEN", "FIFTEEN", "SIXTEEN", "SEVETEEN", "EIGHTEEN", "NIGHTEEN"};
private static final String[] TIES = {"TWENTY", "THRITY", "FORTY", "FIFTY",
"SIXTY", "SEVENTY", "EIGHTY", "NINETY"};
private static Scanner sc;
public static void main(String[] args) {
sc = new Scanner(***.in);
int num = 0;
while(num != -1) {
System.out.print("Please type a number between 0 and 999: ");
num = sc.nextInt();
if(num <0 || num > 999) {
continue;
}
String english = toEnglish(num);
System.out.println(english);
}
System.out.println("Thank you for using this program");
}
private static String toEnglish(int num) {
if(num == 0) {
return "Zero";
}
StringBuffer buffer = new StringBuffer();
if(num >= 100) {
buffer.append(pickHunder(num));
if(num % 100 != 0) {
buffer.append(" AND ");
}
num -= (num / 100) * 100;
}
boolean largerThan20 = false;
if(num >= 20) {
largerThan20 = true;
buffer.append(pickTies(num));
num -= (num / 10) * 10;
}
if(!largerThan20 && num > 10) {
buffer.append(pickTeens(num));
num = 0;
}
if(num > 0) {
String bit = pickBits(num);
if(largerThan20) {
buffer.append(" ");
}
buffer.append(bit);
}
return buffer.toString();
}
private static String pickHunder(int num) {
int hunder = num / 100;
return BITS[hunder - 1] + " HUNDER";
}
private static String pickTies(int num) {
int ties = num / 10;
return TIES[ties - 2];
}
private static String pickTeens(int num) {
return TEENS[num - 11];
}
private static String pickBits(int num) {
return BITS[num - 1];
}
}
public class EnglishNumberFormatter {
private static final String[] BITS = {"ONE", "TWO", "THREE", "FOUR", "FIVE",
"SIX", "SEVEN", "EIGHT,", "NINE", "TEN"};
private static final String[] TEENS = {"ELEVEN", "TWELF", "THIRTEEN",
"FOURTEEN", "FIFTEEN", "SIXTEEN", "SEVETEEN", "EIGHTEEN", "NIGHTEEN"};
private static final String[] TIES = {"TWENTY", "THRITY", "FORTY", "FIFTY",
"SIXTY", "SEVENTY", "EIGHTY", "NINETY"};
private static Scanner sc;
public static void main(String[] args) {
sc = new Scanner(***.in);
int num = 0;
while(num != -1) {
System.out.print("Please type a number between 0 and 999: ");
num = sc.nextInt();
if(num <0 || num > 999) {
continue;
}
String english = toEnglish(num);
System.out.println(english);
}
System.out.println("Thank you for using this program");
}
private static String toEnglish(int num) {
if(num == 0) {
return "Zero";
}
StringBuffer buffer = new StringBuffer();
if(num >= 100) {
buffer.append(pickHunder(num));
if(num % 100 != 0) {
buffer.append(" AND ");
}
num -= (num / 100) * 100;
}
boolean largerThan20 = false;
if(num >= 20) {
largerThan20 = true;
buffer.append(pickTies(num));
num -= (num / 10) * 10;
}
if(!largerThan20 && num > 10) {
buffer.append(pickTeens(num));
num = 0;
}
if(num > 0) {
String bit = pickBits(num);
if(largerThan20) {
buffer.append(" ");
}
buffer.append(bit);
}
return buffer.toString();
}
private static String pickHunder(int num) {
int hunder = num / 100;
return BITS[hunder - 1] + " HUNDER";
}
private static String pickTies(int num) {
int ties = num / 10;
return TIES[ties - 2];
}
private static String pickTeens(int num) {
return TEENS[num - 11];
}
private static String pickBits(int num) {
return BITS[num - 1];
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
很简单的程序,我就不写注释了吧import java.util.Scanner;
public class EnglishNumberFormatter {
private static final String[] BITS = {"ONE", "TWO", "THREE", "FOUR", "FIVE",
"SIX", "SEVEN", "EIGHT,", "NINE", "TEN"};
private static final String[] TEENS = {"ELEVEN", "TWELF", "THIRTEEN",
"FOURTEEN", "FIFTEEN", "SIXTEEN", "SEVETEEN", "EIGHTEEN", "NIGHTEEN"};
private static final String[] TIES = {"TWENTY", "THRITY", "FORTY", "FIFTY",
"SIXTY", "SEVENTY", "EIGHTY", "NINETY"};
private static Scanner sc;
public static void main(String[] args) {
sc = new Scanner(***.in);
int num = 0;
while(num != -1) {
System.out.print("Please type a number between 0 and 999: ");
num = sc.nextInt();
if(num <0 || num > 999) {
continue;
}
String english = toEnglish(num);
System.out.println(english);
}
System.out.println("Thank you for using this program");
}
private static String toEnglish(int num) {
if(num == 0) {
return "Zero";
}
StringBuffer buffer = new StringBuffer();
if(num >= 100) {
buffer.append(pickHunder(num));
if(num % 100 != 0) {
buffer.append(" AND ");
}
num -= (num / 100) * 100;
}
boolean largerThan20 = false;
if(num >= 20) {
largerThan20 = true;
buffer.append(pickTies(num));
num -= (num / 10) * 10;
}
if(!largerThan20 && num > 10) {
buffer.append(pickTeens(num));
num = 0;
}
if(num > 0) {
String bit = pickBits(num);
if(largerThan20) {
buffer.append(" ");
}
buffer.append(bit);
}
return buffer.toString();
}
private static String pickHunder(int num) {
int hunder = num / 100;
return BITS[hunder - 1] + " HUNDER";
}
private static String pickTies(int num) {
int ties = num / 10;
return TIES[ties - 2];
}
private static String pickTeens(int num) {
return TEENS[num - 11];
}
private static String pickBits(int num) {
return BITS[num - 1];
}
}
public class EnglishNumberFormatter {
private static final String[] BITS = {"ONE", "TWO", "THREE", "FOUR", "FIVE",
"SIX", "SEVEN", "EIGHT,", "NINE", "TEN"};
private static final String[] TEENS = {"ELEVEN", "TWELF", "THIRTEEN",
"FOURTEEN", "FIFTEEN", "SIXTEEN", "SEVETEEN", "EIGHTEEN", "NIGHTEEN"};
private static final String[] TIES = {"TWENTY", "THRITY", "FORTY", "FIFTY",
"SIXTY", "SEVENTY", "EIGHTY", "NINETY"};
private static Scanner sc;
public static void main(String[] args) {
sc = new Scanner(***.in);
int num = 0;
while(num != -1) {
System.out.print("Please type a number between 0 and 999: ");
num = sc.nextInt();
if(num <0 || num > 999) {
continue;
}
String english = toEnglish(num);
System.out.println(english);
}
System.out.println("Thank you for using this program");
}
private static String toEnglish(int num) {
if(num == 0) {
return "Zero";
}
StringBuffer buffer = new StringBuffer();
if(num >= 100) {
buffer.append(pickHunder(num));
if(num % 100 != 0) {
buffer.append(" AND ");
}
num -= (num / 100) * 100;
}
boolean largerThan20 = false;
if(num >= 20) {
largerThan20 = true;
buffer.append(pickTies(num));
num -= (num / 10) * 10;
}
if(!largerThan20 && num > 10) {
buffer.append(pickTeens(num));
num = 0;
}
if(num > 0) {
String bit = pickBits(num);
if(largerThan20) {
buffer.append(" ");
}
buffer.append(bit);
}
return buffer.toString();
}
private static String pickHunder(int num) {
int hunder = num / 100;
return BITS[hunder - 1] + " HUNDER";
}
private static String pickTies(int num) {
int ties = num / 10;
return TIES[ties - 2];
}
private static String pickTeens(int num) {
return TEENS[num - 11];
}
private static String pickBits(int num) {
return BITS[num - 1];
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
很简单的程序,我就不写注释了吧import java.util.Scanner;
public class EnglishNumberFormatter {
private static final String[] BITS = {"ONE", "TWO", "THREE", "FOUR", "FIVE",
"SIX", "SEVEN", "EIGHT,", "NINE", "TEN"};
private static final String[] TEENS = {"ELEVEN", "TWELF", "THIRTEEN",
"FOURTEEN", "FIFTEEN", "SIXTEEN", "SEVETEEN", "EIGHTEEN", "NIGHTEEN"};
private static final String[] TIES = {"TWENTY", "THRITY", "FORTY", "FIFTY",
"SIXTY", "SEVENTY", "EIGHTY", "NINETY"};
private static Scanner sc;
public static void main(String[] args) {
sc = new Scanner(***.in);
int num = 0;
while(num != -1) {
System.out.print("Please type a number between 0 and 999: ");
num = sc.nextInt();
if(num <0 || num > 999) {
continue;
}
String english = toEnglish(num);
System.out.println(english);
}
System.out.println("Thank you for using this program");
}
private static String toEnglish(int num) {
if(num == 0) {
return "Zero";
}
StringBuffer buffer = new StringBuffer();
if(num >= 100) {
buffer.append(pickHunder(num));
if(num % 100 != 0) {
buffer.append(" AND ");
}
num -= (num / 100) * 100;
}
boolean largerThan20 = false;
if(num >= 20) {
largerThan20 = true;
buffer.append(pickTies(num));
num -= (num / 10) * 10;
}
if(!largerThan20 && num > 10) {
buffer.append(pickTeens(num));
num = 0;
}
if(num > 0) {
String bit = pickBits(num);
if(largerThan20) {
buffer.append(" ");
}
buffer.append(bit);
}
return buffer.toString();
}
private static String pickHunder(int num) {
int hunder = num / 100;
return BITS[hunder - 1] + " HUNDER";
}
private static String pickTies(int num) {
int ties = num / 10;
return TIES[ties - 2];
}
private static String pickTeens(int num) {
return TEENS[num - 11];
}
private static String pickBits(int num) {
return BITS[num - 1];
}
}
public class EnglishNumberFormatter {
private static final String[] BITS = {"ONE", "TWO", "THREE", "FOUR", "FIVE",
"SIX", "SEVEN", "EIGHT,", "NINE", "TEN"};
private static final String[] TEENS = {"ELEVEN", "TWELF", "THIRTEEN",
"FOURTEEN", "FIFTEEN", "SIXTEEN", "SEVETEEN", "EIGHTEEN", "NIGHTEEN"};
private static final String[] TIES = {"TWENTY", "THRITY", "FORTY", "FIFTY",
"SIXTY", "SEVENTY", "EIGHTY", "NINETY"};
private static Scanner sc;
public static void main(String[] args) {
sc = new Scanner(***.in);
int num = 0;
while(num != -1) {
System.out.print("Please type a number between 0 and 999: ");
num = sc.nextInt();
if(num <0 || num > 999) {
continue;
}
String english = toEnglish(num);
System.out.println(english);
}
System.out.println("Thank you for using this program");
}
private static String toEnglish(int num) {
if(num == 0) {
return "Zero";
}
StringBuffer buffer = new StringBuffer();
if(num >= 100) {
buffer.append(pickHunder(num));
if(num % 100 != 0) {
buffer.append(" AND ");
}
num -= (num / 100) * 100;
}
boolean largerThan20 = false;
if(num >= 20) {
largerThan20 = true;
buffer.append(pickTies(num));
num -= (num / 10) * 10;
}
if(!largerThan20 && num > 10) {
buffer.append(pickTeens(num));
num = 0;
}
if(num > 0) {
String bit = pickBits(num);
if(largerThan20) {
buffer.append(" ");
}
buffer.append(bit);
}
return buffer.toString();
}
private static String pickHunder(int num) {
int hunder = num / 100;
return BITS[hunder - 1] + " HUNDER";
}
private static String pickTies(int num) {
int ties = num / 10;
return TIES[ties - 2];
}
private static String pickTeens(int num) {
return TEENS[num - 11];
}
private static String pickBits(int num) {
return BITS[num - 1];
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询