/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package cities;
import java.util.Scanner;
import java.util.Vector;
public class Cities {
public static void main(String a[]) {
Scanner z = new Scanner(System.in);
int x;
String name, del;
Vector<String> vct = new Vector<String>();
vct.add("Los Angeles");
System.out.println(vct);
System.out.println("Select : \n1.Add City \n2.Remove City\n3.Display\n");
x = z.nextInt();
switch (x) {
case 1:
System.out.println("Enter a city name to add :");
name = z.nextLine();
if (vct.contains(name)) {
System.out.println("Already Exists.");
} else {
vct.add(name);
System.out.println("Updated Vector :" + vct);
break;
}
case 2:
System.out.println("Enter the city name to delete :");
del = z.nextLine();
vct.remove(del);
System.out.println("Updated Vector :" + vct);
break;
case 3:
System.out.println(vct);
break;
default:
System.out.println("Please provide a proper input.");
break;
}
}
}
答案 0 :(得分:1)
您错过了案例1的结尾break;
。