我是编程新手,我试图使用Switch case实现HashMaps,用户选择一个选项并添加或删除键.如果用户选择插入键值对的选项1,程序在此之后结束,我不能选择允许用户显示键集等的其他选项.我想编程以在成功案例之后继续执行执行.对不起,我的英语不好.
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashMap;
public class HashMapImplementation {
public static void main(String args[]) throws Exception {
HashMap<String, String> hashMap = new HashMap<String, String>();
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Please select what you want to do:");
System.out.println("1. Add Key-Value to HashMap ");
System.out.println("2. Delete Key-Value from HashMap ");
System.out.println("3. Display all Keys");
System.out.println("4. Display all Values");
System.out.println("5. Display Key-Value Set");
System.out.println("6. Find a Value in HashMap");
int c = Integer.parseInt(reader.readLine());
switch (c) {
case 1:
System.out.println("Please …Run Code Online (Sandbox Code Playgroud) 我最近开始学习python.我正在解决一个问题.
class Person:
age = 0
def __init__(self,initial_Age):
if initial_Age<0:
age=0
print("This person is not valid, setting age to 0.")
else:
age = initial_Age
def amIOld(self):
if(age<13):
print("You are young.")
elif(age>=13 and age<18):
print("You are a teenager.")
else:
print("You are old.")
def yearPasses(self):
age = age + 1
T=int(input())
for i in range(0,T):
age=int(input())
p=Person(age)
p.amIOld()
for j in range(0,3):
p.yearPasses();
p.amIOld();
print ("")
Run Code Online (Sandbox Code Playgroud)
我得到的错误显示如下:
Traceback (most recent call last):
File "solution.py", line 27, in <module>
p.yearPasses();
File "solution.py", line …Run Code Online (Sandbox Code Playgroud)