vendredi 9 janvier 2015

Java If Else statement for abbreviations

I've been working on this code, its really basic but I just started working with Java and I don't know whats going on with it.



import java.util.Scanner;


public class Proj {


public static void main(String[] args) {

//Create Scanner
Scanner scanner = new Scanner(System.in);

//Input Abbreviation
System.err.print("Input METAR Abbreviation: ");
scanner.nextLine( );

//Abbreviations
String abb = "";
if (abb.equals("B")) {
System.out.println ("Began At Time ");
}
else if(abb.equals("+")) {
System.out.println ("Heavy intensity");
}
else if(abb.equals("-")) {
System.out.println ("Light intensity");
}
else if(abb.equals("DZ")) {
System.out.println ("Drizzle");
}
else if(abb.equals("E")) {
System.out.println ("Ended At Time");
}
else if(abb.equals("HZ")) {
System.out.println ("Haze");
}
else if(abb.equals("RA")) {
System.out.println ("Rain");
}
else if(abb.equals("SN")) {
System.out.println ("Snow");
}
else(abb !=NULL) {
System.out.println("Unknown Abbreviation");
}
//Close scanner
scanner.close( );
}
}


So what I'm trying to do is when someone enters one of the abbreviations it prints out what it means, and if the abbreviation doesn't exist it prints out Unknown Abbreviation. So my problem is that when I run the code it prints Input METAR Abbreviation and you can enter a string but after that nothing happens, can someone help me out. Thanks


Aucun commentaire:

Enregistrer un commentaire