im newbie to java , and i getting confused here , why i get error when i want to convert string to int in java , if i type in msi (a to e), and i want to use msii variable inside if statement to outside , and i can't , so i try using sout outside , but i got error , and sorry i have bad grammar
public static void main(String args[]){
Scanner i=new Scanner (System.in);
System.out.println("Name\t\t\t");
String nama=i.nextLine();
System.out.println("Nim\t\t\t");
String nim=i.nextLine();
System.out.println("grade\t\t");
String msi=i.next();
switch(msi) {
case "a||A":
{
msii=Integer.parseInt(msi);
msii=4;
break;
}
case "b||B":
{
msii=Integer.parseInt(msi);
msii=3;
break;
}
case "c||C":
{
msii=Integer.parseInt(msi);
msii=2;
break;
}
case "d||D":
{
msii=Integer.parseInt(msi);
msii=1;
break;
}
case "e||E":
{
msii=Integer.parseInt(msi);
msii=4;
break;
}
default:
System.out.println("tidak ada");
break;
}
System.out.println(+msii);
Aucun commentaire:
Enregistrer un commentaire