如何在 .txt 文件中存储输入数字中的最大数字(以单词为单位)?
我应该从所有输入数字中获取最大数字并将最大数字转换为单词。实际上是我们语言中的数字。我在将其存储到 .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 文件中。但文本文件包含数字,而不是单词,请帮忙?非常感谢。
I am supposed to get the highest number from all input numbers and convert the highest number into words. Numbers in our language actually. I am kind of having trouble in storing it into a .txt file. My program stores the number but not the word, how can I make my program store the word and not the number?
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);
}
My code's not yet finished but I've tried storing my maximumnumber into the output.txt file. But the text file contains the number, not the word, help please? Thank you very much.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
将您的所有:更改
为
Change all your:
to
您必须将 switch...cases 中的 System.out.print 更改为 outFile.print。
You have to change the System.out.print in the switch...cases to outFile.print.
另一种方法是将输出组织为字符串值,之后您可以对结果执行任何您想要的操作。并使用 File.write() 写入文件。
The other way is to organize your output as string value, and after that you may do everything what you want with your result. And write to file with File.write() .