| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1496 人关注过本帖
标题:Java:将100以内的数字翻译成英文。问:为什么输入后没有输出
只看楼主 加入收藏
紫诺
Rank: 1
来 自:中国
等 级:新手上路
帖 子:8
专家分:0
注 册:2019-11-3
结帖率:0
收藏
已结贴  问题点数:10 回复次数:2 
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();
    }
}
搜索更多相关主题的帖子: System num println int for 
2020-03-08 20:30
叶纤
Rank: 8Rank: 8
等 级:禁止访问
威 望:1
帖 子:658
专家分:848
注 册:2019-11-22
收藏
得分:5 
可以看懂,不过我需要把它翻译成c++然后换种写法,你这样写太啰嗦了

把学习时间浪费在混坛上是傻瓜行为,更何况自己的水平连一两都没到。
2020-03-08 21:50
林月儿
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:湖南
等 级:版主
威 望:138
帖 子:2277
专家分:10647
注 册:2015-3-19
收藏
得分:5 
程序代码:
package com.test;

import java.util.Scanner;

public class Day0308 {
    public static void main(String[] args) {
        String oneArr[] = { "zero", "one", "two", "three", "four", "five", "six",
                "seven", "eight", "nine" };
        String twoArr[] = {"ten", "eleven", "twelve", "thirteen", "fourteen",
                "fifteen", "sixteen", "seventeen", "eighteen", "nineteen" };
        String tenArr[] = {"twenty", "thirty", "fourty", "fifty", "sixty",
                "seventy", "eighty", "ninty" };
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入数字");
        int m = scanner.nextInt();
        scanner.close();
        if (m < 10) {
            System.out.println(oneArr[m]);
        } else if (m < 20) {
            System.out.println(twoArr[m-10]);
        } else if (m < 100) {
            System.out.print(tenArr[m/10-2] + " ");
            if(m % 10 > 0) {
                System.out.println(oneArr[m%10]);
            }
        }
    }
}

剑栈风樯各苦辛,别时冰雪到时春
2020-03-08 22:50
快速回复:Java:将100以内的数字翻译成英文。问:为什么输入后没有输出
数据加载中...
 
   



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

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