String x[]={"zero","one","two", "three",four", "five","six",seven","eight","nine"} ; String y[]={ten","eleven","twelve","thirteen","fourteen","fifteen", "sixteen","seventeen","eighteen","nineteen" }; String z[]={"twenty","thirty","fourty","fifty", "sixty","seventy", "eighty","ninety" }; 用Java命令行输入或在Eclipse中设置参数一个小于100的整数,将其翻成英文表示。 例如: 输入32,输出:thirty two 输入14,输出:fourteen 输入8, 输出:eight 反之,输入英文表示,输出相应的整数。

时间: 2023-06-29 14:17:43 浏览: 48
非常抱歉,我刚刚的代码中有一处小错误,应该是“forty”而不是“fourty”,我在下面的代码中进行了更正。请注意使用正确的代码: ```java public class NumberToEnglish { private static final String[] x = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"}; private static final String[] y = {"ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"}; private static final String[] z = {"twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"}; public static void main(String[] args) { int n = Integer.parseInt(args[0]); String result = ""; if (n < 10) { result = x[n]; } else if (n < 20) { result = y[n - 10]; } else if (n < 100) { int tens = n / 10; int ones = n % 10; result = z[tens - 2]; if (ones != 0) { result += " " + x[ones]; } } System.out.println(result); } } ``` ```java public class EnglishToNumber { private static final String[] x = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"}; private static final String[] y = {"ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"}; private static final String[] z = {"twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"}; public static void main(String[] args) { String s = args[0]; int result = 0; for (int i = 0; i < x.length; i++) { if (s.equals(x[i])) { result = i; break; } } for (int i = 0; i < y.length; i++) { if (s.equals(y[i])) { result = 10 + i; break; } } for (int i = 0; i < z.length; i++) { if (s.equals(z[i])) { result = (i + 2) * 10; break; } } System.out.println(result); } } ``` 谢谢您的理解!

相关推荐

package com.example.myapplication; import androidx.appcompat.app.AppCompatActivity; import android.icu.math.BigDecimal; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.TextView; import org.w3c.dom.Text; public class MainActivity extends AppCompatActivity { boolean jia=false,jian=false,mul=false,miv=false,eqe=false; double first,second; String str="",str1=""; int dian=0; public double result(){ if(jia){ first=first+second; } if(jian){ first=first-second; } if(mul){ first=first*second; } if(miv){ if(second==0){ return 0; }else{ first=first/second; } } return first; } public void close(){ jia=false; jian=false; mul=false; miv=false; } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button zero = (Button) findViewById(R.id.button_00); Button one = (Button) findViewById(R.id.button_1); Button two = (Button) findViewById(R.id.button_2); Button three = (Button) findViewById(R.id.button_3); Button four = (Button) findViewById(R.id.button_4); Button five = (Button) findViewById(R.id.button_5); Button six = (Button) findViewById(R.id.button_6); Button seven = (Button) findViewById(R.id.button_7); Button eight = (Button) findViewById(R.id.button_8); Button nine = (Button) findViewById(R.id.button_9); Button add = (Button) findViewById(R.id.button_add); Button sub = (Button) findViewById(R.id.button_sub); Button chen = (Button) findViewById(R.id.button_mul); Button chu = (Button) findViewById(R.id.button_div);这段代码来自Android studio的MainAcvity文件,是实现计算器功能的,请详细解释一下每行代码的意思

最新推荐

recommend-type

JavaScript_构建您的第一个移动应用程序.zip

JavaScript
recommend-type

手机应用源码新浪微博Android客户端.rar

手机应用源码新浪微博Android客户端.rar
recommend-type

俄罗斯方块项目【尚学堂·百战程序员】.zip

# 俄罗斯方块项目【尚学堂·百战程序员】 俄罗斯方块是一款经典的益智游戏,最早由俄罗斯程序员阿列克谢·帕基特诺夫于1984年开发。本项目基于【尚学堂·百战程序员】的课程内容,详细介绍如何使用JavaScript、HTML5和CSS3从零开始开发一个完整的俄罗斯方块游戏。该项目旨在帮助学习者掌握前端开发的基础知识和技能,提升编程能力。 ## 项目概述 本项目实现了经典的俄罗斯方块游戏,主要包括以下功能模块: ### 1. 游戏界面 游戏界面采用HTML5的Canvas元素进行绘制,使用CSS3进行样式设计。界面包括游戏区域、得分显示、下一个方块预览和控制按钮。通过合理的布局和美观的设计,为玩家提供良好的游戏体验。 ### 2. 方块生成与控制 游戏随机生成不同形状的方块(I、O、T、L、J、S、Z),玩家可以通过键盘控制方块的移动和旋转。具体操作包括: - 左移:按左箭头键。 - 右移:按右箭头键。 - 下移:按下箭头键。 - 旋转:按上箭头键。 ### 3. 方块下落与碰撞检测 方块自动从上到下逐行下落,速度逐渐加快。通过碰撞检测算法,判断方块是否与其他方块或底部边界
recommend-type

zigbee-cluster-library-specification

最新的zigbee-cluster-library-specification说明文档。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

实现实时数据湖架构:Kafka与Hive集成

![实现实时数据湖架构:Kafka与Hive集成](https://img-blog.csdnimg.cn/img_convert/10eb2e6972b3b6086286fc64c0b3ee41.jpeg) # 1. 实时数据湖架构概述** 实时数据湖是一种现代数据管理架构,它允许企业以低延迟的方式收集、存储和处理大量数据。与传统数据仓库不同,实时数据湖不依赖于预先定义的模式,而是采用灵活的架构,可以处理各种数据类型和格式。这种架构为企业提供了以下优势: - **实时洞察:**实时数据湖允许企业访问最新的数据,从而做出更明智的决策。 - **数据民主化:**实时数据湖使各种利益相关者都可
recommend-type

可见光定位LED及其供电硬件具体型号,广角镜头和探测器,实验设计具体流程步骤,

1. 可见光定位LED型号:一般可使用5mm或3mm的普通白色LED,也可以选择专门用于定位的LED,例如OSRAM公司的SFH 4715AS或Vishay公司的VLMU3500-385-120。 2. 供电硬件型号:可以使用常见的直流电源供电,也可以选择专门的LED驱动器,例如Meanwell公司的ELG-75-C或ELG-150-C系列。 3. 广角镜头和探测器型号:一般可采用广角透镜和CMOS摄像头或光电二极管探测器,例如Omron公司的B5W-LA或Murata公司的IRS-B210ST01。 4. 实验设计流程步骤: 1)确定实验目的和研究对象,例如车辆或机器人的定位和导航。
recommend-type

JSBSim Reference Manual

JSBSim参考手册,其中包含JSBSim简介,JSBSim配置文件xml的编写语法,编程手册以及一些应用实例等。其中有部分内容还没有写完,估计有生之年很难看到完整版了,但是内容还是很有参考价值的。
recommend-type

"互动学习:行动中的多样性与论文攻读经历"

多样性她- 事实上SCI NCES你的时间表ECOLEDO C Tora SC和NCESPOUR l’Ingén学习互动,互动学习以行动为中心的强化学习学会互动,互动学习,以行动为中心的强化学习计算机科学博士论文于2021年9月28日在Villeneuve d'Asq公开支持马修·瑟林评审团主席法布里斯·勒菲弗尔阿维尼翁大学教授论文指导奥利维尔·皮耶昆谷歌研究教授:智囊团论文联合主任菲利普·普雷教授,大学。里尔/CRISTAL/因里亚报告员奥利维耶·西格德索邦大学报告员卢多维奇·德诺耶教授,Facebook /索邦大学审查员越南圣迈IMT Atlantic高级讲师邀请弗洛里安·斯特鲁布博士,Deepmind对于那些及时看到自己错误的人...3谢谢你首先,我要感谢我的两位博士生导师Olivier和Philippe。奥利维尔,"站在巨人的肩膀上"这句话对你来说完全有意义了。从科学上讲,你知道在这篇论文的(许多)错误中,你是我可以依
recommend-type

实现实时监控告警系统:Kafka与Grafana整合

![实现实时监控告警系统:Kafka与Grafana整合](https://imgconvert.csdnimg.cn/aHR0cHM6Ly9tbWJpei5xcGljLmNuL21tYml6X2pwZy9BVldpY3ladXVDbEZpY1pLWmw2bUVaWXFUcEdLT1VDdkxRSmQxZXB5R1lxaWNlUjA2c0hFek5Qc3FyRktudFF1VDMxQVl3QTRXV2lhSWFRMEFRc0I1cW1ZOGcvNjQw?x-oss-process=image/format,png) # 1.1 Kafka集群架构 Kafka集群由多个称为代理的服务器组成,这