扫二维码与项目经理沟通
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流
可以通过”Scanner“函数 直接输入参数的形式,来实现输入语句,举例:
在成都网站设计、成都做网站中从网站色彩、结构布局、栏目设置、关键词群组等细微处着手,突出企业的产品/服务/品牌,帮助企业锁定精准用户,提高在线咨询和转化,使成都网站营销成为有效果、有回报的无锡营销推广。创新互联专业成都网站建设10多年了,客户满意度97.8%,欢迎成都创新互联客户联系。
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
System.out.println("请输入一个整数:");
int length=input.nextInt();//输入一个整数
System.out.println("输入的整数是:"+length);}
}
备注:Scanner函数就是用来进行语句输入的,上面举例的是整数类型,也可以用以下语句“String length=input.next()”,输入的就是字符串类型等。
import java.util.Scanner;
/**
* 用户输入n1和n2:求不能同时被3和5整除的累加和
* @author 你好qiulinhe
*
*/
public class Ceshi {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("请依次输入1-10的数字");
for(int i=1;i11;i++){
int ceshi = scanner.nextInt();
switch (ceshi) {
case 1:
System.out.println("1对应的字母是A");
break;
case 2:
System.out.println("2对应的字母是B");
break;
case 3:
System.out.println("3对应的字母是C");
break;
case 4:
System.out.println("4对应的字母是D");
break;
case 5:
System.out.println("5对应的字母是E");
break;
case 6:
System.out.println("6对应的字母是F");
break;
case 7:
System.out.println("7对应的字母是G");
break;
case 8:
System.out.println("8对应的字母是H");
break;
case 9:
System.out.println("9对应的字母是I");
break;
case 10:
System.out.println("10对应的字母是J");
break;
default:
break;
}
}
}
}
结果为:
public final class NumberReader {
private long number;
private boolean displatCharacter = false;
private static final String[][] DIGITS =
{{"Ling ", "Yi ", "Er ", "San ", "Si ", "Wu ", "Liu ", "Qi ", "Ba ", "Jiu ", ""}
, {"零", "一", "二", "三", "四", "五", "六", "七", "八", "九", ""}};
private static final String[][] NUM_BASE =
{{"Qian ", "Bai", "Shi", ""}, {"千", "百", "十", ""}};
private static final String[][] EXTENDED_BASE =
{{"Zhao ", "Yi ", "Wan ", ""}, {"兆", "亿", "万", ""}};
public NumberReader(final long number) {
this.number = number;
}
public NumberReader(final long number, final boolean displatCharacter) {
this.number = number;
this.displatCharacter = displatCharacter;
}
public String getPrononciation() {
final String dataSrc = String.valueOf(number);
final StringBuilder sb = new StringBuilder();
int sIndex = 0;
int eIndex = dataSrc.length() % 4 == 0 ? 4 : dataSrc.length() % 4;
for (int bIndex = EXTENDED_BASE[0].length - (dataSrc.length() / 4) - 1; bIndex EXTENDED_BASE[0].length; bIndex++) {
sb.append(resolveNumberBase(dataSrc.substring(sIndex, eIndex), sIndex == 0));
sb.append(EXTENDED_BASE[displatCharacter ? 1 : 0][bIndex]);
sIndex += eIndex;
eIndex += 4;
}
return sb.toString();
}
private String resolveNumberBase(final String num, final boolean displayZeros) {
final StringBuilder sb = new StringBuilder();
for (int index = 0; index num.length(); index++) {
final int digit = charToInt(num.charAt(index));
sb.append(DIGITS[displatCharacter ? 1 : 0][
digit == 0 index == 0 displayZeros ?
DIGITS[0].length - 1 : index == 2 digit == 1 ? DIGITS[0].length - 1 :
digit == 1 index == num.length() - 2 num.length() == 2 ? DIGITS[0].length - 1 :
digit == 0 index != 0 charToInt(num.charAt(index - 1)) == 0 ? DIGITS[0].length - 1 :
digit]);
sb.append(NUM_BASE[displatCharacter ? 1 : 0][digit == 0 ? NUM_BASE[0].length - 1 : NUM_BASE[0].length - num.length() + index]);
}
return sb.toString();
}
private int charToInt(final char digit) {
return digit - '0';
}
public static void main(String[] args) {
System.out.println(new NumberReader(100010408L, true).getPrononciation());
}
}
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流