The main problem is in case2.
public static void main(String[] args) {
String tmed;
int t;
Scanner in = new Scanner(System.in);
System.out.println("How many types of Tablets you want to buy?");
t = in.nextInt();
switch(t){
case 1: System.out.println("Enter name of medicine: ");
tmed=in.nextLine();
int pan,fla,total;
if((tmed.equals("panadol"))){
System.out.print("How many tablets of Panadol do you want? ");
pan = in.nextInt();
total=pan*5;
System.out.println(total);}break;
//here the problem starts
case 2: System.out.println("Enter name of medicines: "); tmed = in.nextLine(); tmed = in.nextLine();
if((tmed.equals("panadol"))){
System.out.print("How many tablets of Panadol do you want? ");
pan = in.nextInt();
total=pan*5;
System.out.println(total);
}`//some problem here`
System.out.println("Enter name of second medicine: ");
tmed = in.nextLine();
if((tmed.equals("flagyl"))){
System.out.print("How many tablets of Flagyl do you want? ");
fla = in.nextInt();
total=fla*7;
System.out.print(total);
}
break;
default: System.out.println("invalid number ");
}
}
}
Aucun commentaire:
Enregistrer un commentaire