Java Programming

http://thenewboston.org/watch.php?cat=31&number=2

Java Switch Statement

 
class apples{
	public static void main(String args[]){
		int age;
		age = 2;
 
		switch (age){
		case 1:
			System.out.println("You can crawl");
			break;
		case 2:
			System.out.println("You can talk");
			break;
		case 3:
			System.out.println("You can get in trouble");
			break;
		default:
			System.out.println("I dont know how old you are");
			break;
		}
	}
}

Java While Loop

class apples{
	public static void main(String args[]){
		int counter =  0;
		while (counter < 10){
			System.out.println(counter);
			counter++;
		}
	}
}

Java Using Multiple Classes

class apples{
	public static void main(String args[]){
 
			tuna tunaObject = new tuna();
			tunaObject.simpleMessage();
 
	}
}
 
 
 
 
 
public class tuna {
	public void simpleMessage(){
		System.out.println("This is another class");
	}
}

Java Use Methods with Parameters

import java.util.Scanner;
 
class apples{
	public static void main(String args[]){
 
		Scanner input = new Scanner(System.in);
		tuna tunaObject = new tuna();
 
		System.out.println("Enter your name here: ");
		String name = input.nextLine();
 
		tunaObject.simpleMessage(name);
	}
}
 
 
 
 
 
 
public class tuna {
	public void simpleMessage(String name){
		System.out.println("Hello "+name);
	}
}