如何在 .txt 文件中存储输入数字中的最大数字(以单词为单位)?

发布于 2024-12-05 11:06:25 字数 4348 浏览 1 评论 0原文

我应该从所有输入数字中获取最大数字并将最大数字转换为单词。实际上是我们语言中的数字。我在将其存储到 .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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

江城子 2024-12-12 11:06:25

将您的所有:更改

case n: System.out.print("xxx"); break;

case n: outFile.print("xxx"); break;

Change all your:

case n: System.out.print("xxx"); break;

to

case n: outFile.print("xxx"); break;
时间海 2024-12-12 11:06:25

您必须将 switch...cases 中的 System.out.print 更改为 outFile.print。

You have to change the System.out.print in the switch...cases to outFile.print.

踏月而来 2024-12-12 11:06:25

另一种方法是将输出组织为字符串值,之后您可以对结果执行任何您想要的操作。并使用 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() .

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文