head first java chapter 1
Post on 17-Feb-2017
166 Views
Preview:
TRANSCRIPT
HelloWorldpublic class HelloWorld {
public static void main (String[] args) {
System.out.println(“Hello World”);
}
}
Statements//declaration
String name;
//assignment
name = “Tom”;
//method call
double d = Math.Random();
Loopswhile (score > 10) {
score = score + 1;
}
For (int v = 0; v < 5; v++) {
System.out.println(v);
}
Branchingif (x = 10) {
System.out.println(“x is ten”);
} else {
System.out.println(“x is NOT ten”);
}
NameLoop.javapublic class NameLoop {
public static void main (String[] args) {
int x = 1;
while (x < 10) {
System.out.println(“My name is Tom!”)
}
}
Java Basics● Statements end with a semicolon;
● Code blocks are defined by curly braces {}
● Declare an int variable with a name and a type: int x;
● The assignment operator is one equals sign =
● The equals operator uses two equals signs ==
Java Basics● A while loop runs everything within its block as long as
conditional test is true
● If the conditional is false, the while loop code block won’t
run, and execution will move down
● Put your boolean test within parentheses
while (x==4) {}
top related