我应该从所有输入数字中获得最高数字,并将最高数字转换为单词。实际上我们语言中的数字。我将它存储到.txt文件中有点麻烦。我的程序存储了数字而不是单词,如何使我的程序存储单词而不是数字?
public static int getHighest1(int ... dNums) throws IOException, FileNotFoundException {
PrintWriter outFile = new PrintWriter("Output1.txt");
for (int iCtr=0; iCtr<dNums.length; iCtr++) {
System.out.println("Values:" +dNums[iCtr]);
}
int dMax = 0;
for (int iCtr=0; iCtr<dNums.length; iCtr++) {
if (dMax<dNums[iCtr]) {
dMax = dNums[iCtr];
}
}
outFile.println("Ang pinakamataas na numero ay:" +dMax);
int dTenThousands, dThousands, dHundreds, dTens, dOnes, dRemainder=0;
dTenThousands = dMax/10000;
dMax = dMax%10000;
dThousands = dMax/1000;
dMax = dMax%1000;
dHundreds = dMax/100;
dMax = dMax%100;
dTens = (dMax%100)/10;
if (dMax>10 && dMax <20) {
dTens = 0;
dOnes = 0;
dRemainder=dMax%10;
}
else {
dTens = dMax/10;
dOnes = dMax;
}
switch(dTenThousands) {
case 1: System.out.print("Sampung libo"); break;
case 2: System.out.print("Dalawgpung libo"); break;
case 3: System.out.print("Tatlunpung libo"); break;
case 4: System.out.print("Apatnapung libo"); break;
case 5: System.out.print("Limangpung libo"); break;
case 6: System.out.print("Animnapung libo"); break;
case 7: System.out.print("Pitongpung libo"); break;
case 8: System.out.print("Walongpung libo"); break;
case 9: System.out.print("Siyamnapung libo"); break;
}
switch(dThousands) {
case 1: System.out.print("Isang libo"); break;
case 2: System.out.print("Dalawang libo"); break;
case 3: System.out.print("Tatlong libo"); break;
case 4: System.out.print("Apat na libo"); break;
case 5: System.out.print("Limang libo"); break;
case 6: System.out.print("Anim na libo"); break;
case 7: System.out.print("Pitong libo"); break;
case 8: System.out.print("Walong libo"); break;
case 9: System.out.print("Siyam na libo"); break;
}
switch(dHundreds) {
case 1: System.out.print("Isandaan"); break;
case 2: System.out.print("Dalawandaan"); break;
case 3: System.out.print("Tatlundaan"); break;
case 4: System.out.print("Apatnadaan"); break;
case 5: System.out.print("Limangdaan"); break;
case 6: System.out.print("Animnaraan"); break;
case 7: System.out.print("Pitongraan"); break;
case 8: System.out.print("Walongraan"); break;
case 9: System.out.print("Siyam naraan"); break;
}
switch(dRemainder) {
case 1: System.out.print("Labingisa"); break;
case 2: System.out.print("Labindalawa"); break;
case 3: System.out.print("Labintatlo"); break;
case 4: System.out.print("Labing apat"); break;
case 5: System.out.print("Labinlima"); break;
case 6: System.out.print("Labing anim"); break;
case 7: System.out.print("Labing pito"); break;
case 8: System.out.print("Labing walo"); break;
case 9: System.out.print("Labing siyam"); break;
}
switch(dTens) {
case 1: System.out.print("Sampu"); break;
case 2: System.out.print("Dalawampu"); break;
case 3: System.out.print("Tatlumpu"); break;
case 4: System.out.print("Apatnapu"); break;
case 5: System.out.print("Limampu"); break;
case 6: System.out.print("Animnapu"); break;
case 7: System.out.print("Pitumpu"); break;
case 8: System.out.print("Walumpu"); break;
case 9: System.out.print("Siyamnapu"); break;
}
switch(dOnes) {
case 1: System.out.print("Isa"); break;
case 2: System.out.print("Dalawa"); break;
case 3: System.out.print("Tatlo"); break;
case 4: System.out.print("Apat"); break;
case 5: System.out.print("Lima"); break;
case 6: System.out.print("Anim"); break;
case 7: System.out.print("Pito"); break;
case 8: System.out.print("Walo"); break;
case 9: System.out.print("Siyam"); break;
}
System.out.println("\nAng pinamataas na numero ay:" +dMax);
}
我的代码尚未完成,但我已尝试将我的最大数量存储到output.txt文件中。但文本文件包含数字,而不是单词,请帮忙吗?非常感谢你。
答案 0 :(得分:3)
更改所有内容:
case n: System.out.print("xxx"); break;
到
case n: outFile.print("xxx"); break;
答案 1 :(得分:0)
您必须将switch ... case中的System.out.print更改为outFile.print。
答案 2 :(得分:0)
另一种方法是将输出组织为字符串值,之后您可以根据结果执行所需的操作。并使用File.write()写入文件。