Sep 21, 2024
public static void main(String[] args)
type variableName = value;
int myInt = 7;
System.out.println(variableName);
to print variable valuesSystem.out.println(myInt);
, output would be 7.int
- integerdouble
- decimal (e.g., double shoeSize = 9.5;
)char
- single character (e.g., char myInitial = 'J';
)String myName = "John";
.length
, .toUpperCase()
)accessModifier returnType methodName(parameters) { // code }
private static void burp() { System.out.println("burp"); }
burp();
)void printName(String name)
)return
to send a value back (e.g., return "my name is " + name;
)if(condition) { // code } else if(condition) { // code } else { // code }
if(name.equals("John")) { System.out.println("This guy is awesome"); }
for(initialization; condition; increment) { // code }
for(int i = 0; i < 10; i++) { System.out.println("These pretzels are making me thirsty"); }
public class Cat { public void meow() { System.out.println("meow"); } }
Cat myCat = new Cat();
String name; int age;
).
operator (e.g., myCat.name = "Fred";
)Cat.dingDong();
)myCat.meow();
)