CPSC 233 Tutorial January 21 st /22 nd, 2015
Linux Commands
Primitive Types byte short int long float double boolean char
Variable Assignment int num = 5; char c = ‘a’; boolean bool = true; long longNum = 100l; float floatNum = 1.5f;
String A String represents a sequence of characters. String text = “Hello World”; String character = “a”; “a” vs. ‘a’ == vs..equals()
Printing to Console System.out.println(“Hello); String word = “Hello”; System.out.println(word); int num = 5; System.out.print(num); print vs. println
If Statements Used for Control flow. Execute a piece of code only if some condition is true
If Statements If ( ){ }
If Statements If ( ){ } else ( ){ }
If Statements If ( ){ } else if ( ){ } else if ( ){ }
If Statements If ( ){ } else if ( ){ } else if ( ){ } else { }
Scanners A Java class that allows the program to read input. Read from console Read from file
Scanner
Exercise Write a Java program that prompts the user for the course program (“CPSC”) and the course number (233) and checks if it matches this course. i.e. “CPSC” and 233. Print a message that states if the input matches or not. Compile: javac InputMatch.java Run: java InputMatch