| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1908 人关注过本帖
标题:用Java将100以内的数字翻译成英文,为什么我的程序输入后不能输出
只看楼主 加入收藏
紫诺
Rank: 1
来 自:中国
等 级:新手上路
帖 子:8
专家分:0
注 册:2019-11-3
结帖率:0
收藏
 问题点数:0 回复次数:3 
用Java将100以内的数字翻译成英文,为什么我的程序输入后不能输出
package ch02;
import java.util.Scanner;

public class L {
    public static void main(String[] args) {
        int x[] = { 0, 1};
        int y[]={ 2, 3, 4, 5, 6, 7, 8, 9 };
        int h[]={1,2,3,4,5,6,7,8,9};
        String z[] = { "zero", "one", "two", "three", "four", "five", "six",
                "eight", "nine" };
        String w[] = {"ten", "eleven", "twelve", "thirteen", "fourteen",
                "fifteen", "sixteen", "seventeen", "eighteen", "nineteen" };
        String t[] = {"twenty", "thirty", "fourty", "fifty", "sixty",
                "seventy", "eighty", "ninty" };
        Scanner sin=new Scanner(System.in);
        System.out.println("请输入数字");
        int m=sin.nextInt();
        int num[]=new int[m];
        for(int i=0;i<3;i++){
            num[i]=sin.nextInt();
        }
        for(int j=0;j<3;j++)
        {
        if(num[0]==1)
            {
                for(int i=0;i<10;i++)
                {
                    if(num[1]==x[i])
                    {
                        System.out.println(w[i]);
                    }
                }
            }
            else if(num[0]==0)
            {
                for(int i=0;i<10;i++)
                {
                    if(num[1]==x[i])
                    {
                        System.out.println(z[i]);
                    }
                }
            }
            else
            {
                for(int i=0;i<10;i++)
                {
                    if(num[0]==y[i])
                    {
                        for(int a=0;a<10;a++)
                        {
                            if(num[1]==h[a])
                            {
                                System.out.println(t[i]+"-"+z[i+1]);
                            }
                            else if(num[1]==0)
                            {
                                System.out.println(t[a]);
                            }
                        }
                    }
                }
               
            }
        }
        
        sin.close();
    }
}
搜索更多相关主题的帖子: println System int num for 
2020-03-08 20:41
林月儿
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:湖南
等 级:版主
威 望:138
帖 子:2277
专家分:10647
注 册:2015-3-19
收藏
得分:0 
java的问题建议去java板块问,发了好几个,其他的有人帮你移过了

剑栈风樯各苦辛,别时冰雪到时春
2020-03-08 23:18
叶纤
Rank: 8Rank: 8
等 级:禁止访问
威 望:1
帖 子:658
专家分:848
注 册:2019-11-22
收藏
得分:0 
程序代码:
#include <iostream>
#include<string>
using namespace std;
int main()
{
   string own[]={"zero","one","two","three","four","five","six","seven","eight","nine","ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen",
   "seventeen","eighteen","nineteen"};
   string  t[] = {"twenty", "thirty", "fourty", "fifty", "sixty",
                "seventy", "eighty", "ninty" };

             int tem{};


                cout<<"请输入数字\n ";

                cin>>tem;


                if(tem<20){cout<<own[tem];}

                else{

                    int shiwei=tem/10;
                    int gewei=tem%10;
                    if(gewei==0){cout<<t[shiwei-2];}
                    else{cout<<t[shiwei-2]<<"-"<<own[gewei];}
                    }
            }


请输入数字
 2
two
请输入数字
 13
thirteen
请输入数字
 45
fourty-five
请输入数字
 90
ninty

把学习时间浪费在混坛上是傻瓜行为,更何况自己的水平连一两都没到。
2020-03-09 01:46
xianfajushi
Rank: 7Rank: 7Rank: 7
等 级:黑侠
威 望:8
帖 子:527
专家分:690
注 册:2007-9-8
收藏
得分:0 
我看找蛙代码和C#有点像.
看代码有点疑惑为何限制为3,假如输入大于3?
        int m=sin.nextInt();
        int num[]=new int[m];
        for(int i=0;i<3;i++){
            num[i]=sin.nextInt();
        }
2020-03-09 08:42
快速回复:用Java将100以内的数字翻译成英文,为什么我的程序输入后不能输出
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.037647 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved