我已经申请了一张不允许使用字母表的支票,但它不起作用 import java.util.Scanner; 公共类主扩展Hashmap{ 公共静态void main(字符串[]args){ Hashmap hm=新的Hashmap(); int x=0; 扫描仪输入=新扫描仪(System.in); 做{ System.out.print(“输入1到12之间的任何整数值:”); x=input.nextInt(); }while(x12); 扫描仪sc=新的扫描仪(System.in); //整数; 做{ 而(!sc.hasnetint()) { System.out.println(“那不是一个数字!”); sc.next(); } x=sc.nextInt(); }而(x>=0); 字符串月份=hm.getEntry(x); 系统输出打印项次(月); } }
在这里,我需要限制用户输入字母表。但它不起作用。 请帮忙…首先,再看看你的问题。我很确定,他在例3中为您解决了这个问题 然后,作为用户界面的替代设计:接受任何用户输入,验证输入,如果输入不正确,则提供有用的消息,并要求用户再次输入值。这非常容易实现,用户也应该对此感到满意我已经申请了一张不允许使用字母表的支票,但它不起作用 import java.util.Scanner; 公共类主扩展Hashmap{ 公共静态void main(字符串[]args){ Hashmap hm=新的Hashmap(); int x=0; 扫描仪输入=新扫描仪(System.in); 做{ System.out.print(“输入1到12之间的任何整数值:”); x=input.nextInt(); }while(x12); 扫描仪sc=新的扫描仪(System.in); //整数; 做{ 而(!sc.hasnetint()) { System.out.println(“那不是一个数字!”); sc.next(); } x=sc.nextInt(); }而(x>=0); 字符串月份=hm.getEntry(x); 系统输出打印项次(月); } },java,Java,在这里,我需要限制用户输入字母表。但它不起作用。 请帮忙…首先,再看看你的问题。我很确定,他在例3中为您解决了这个问题 然后,作为用户界面的替代设计:接受任何用户输入,验证输入,如果输入不正确,则提供有用的消息,并要求用户再次输入值。这非常容易实现,用户也应该对此感到满意 publicstaticvoidmain(字符串[]args){ import java.util.Scanner; public class Main extends Hashmap{ public static
publicstaticvoidmain(字符串[]args){
import java.util.Scanner;
public class Main extends Hashmap{
public static void main(String[] args) {
Hashmap hm = new Hashmap();
int x=0;
Scanner input = new Scanner(System.in);
do{
System.out.print("Enter any integer value between 1 to 12: ");
x = input.nextInt();
}while(x<=0 || x>12);
Scanner sc = new Scanner(System.in);
//int number;
do {
while (!sc.hasNextInt())
{
System.out.println("That's not a number!");
sc.next();
}
x = sc.nextInt();
}while(x>=0);
String month = hm.getEntry(x);
System.out.println(month);
}
}
HashMap hm=新的HashMap();
/**
*填充hashmap..您的逻辑在这里
*/
扫描仪sc=新的扫描仪(System.in);
int x;
System.out.println(“输入一个介于1和12之间的数字”);
做{
而(!sc.hasnetint()){
System.out.println(“那不是一个数字!输入一个介于1和12之间的数字”);
sc.next();
}
x=sc.nextInt();
字符串月份=hm.get(x);
System.out.println(“对应月份为”+月份);
}而(x>=0);
}
我想这就是你想要达到的目标。我不太清楚你的答案,但看一眼。。。1.为什么要扩展HashMap?看起来你不需要这么做。2.变量“hm”未填充任何值,因此最后两行“month”将不起作用。程序运行正常。只是检查不起作用。请具体说明。你希望它表现如何?准确地陈述问题描述。
public static void main(String[] args) {
HashMap<Integer, String> hm = new HashMap<Integer, String>();
/**
* Populate hashmap.. Your logic goes here
*/
Scanner sc = new Scanner(System.in);
int x;
System.out.println("Enter a number between 1 and 12");
do {
while (!sc.hasNextInt()) {
System.out.println("That's not a number! Enter a number between 1 and 12");
sc.next();
}
x = sc.nextInt();
String month = hm.get(x);
System.out.println("The corresponding month is " + month);
} while (x >= 0);
}