Journey to Java: Episode 4 “Java Basics and Methods.”

  • boolean
  • byte
  • char
  • class
  • double
  • float
  • if
  • int
  • long
  • short
  • public
  • static
  • void
// you cannot do something like this
int int = 3;
int void = 25;
int highestNum = 10;
int newNum = 11;
if (newNum > highestNum){
System.out.println("you are higher than the highest number");
System.out.println("congrats");
}
int highestNum = 10;
int newNum = 11;
if (newNum > highestNum)
System.out.println("you are higher than the highest number");
int highestNum = 10;
int newNum = 2;
if (newNum > highestNum){
System.out.println("you are higher than the highest number");
} else {
System.out.println("you were not higher than highest number");
}
int highestNum = 10;
int average = 5;
int newNum = 6;
if (newNum > highestNum){
System.out.println("you are higher than the highest number");
} else if (newNum > average && newNum < highestNum) {
System.out.println("not bad");
} else {
System.out.println("this number is pretty low");
}
public class Practice {   public static void main(String[] args) {   }

//we want to write a new method here. Outside the main method but
//still inside the Practice class}
public class Practice {
public static void main(String[] args) {
int firstNum = 1;
int secondNum = 2;
}

public static void ourFirstMethodAddsNumbers() {
int total = firstNum + secondNum;
System.out.println(total)
}}
public static void main(String[] args) {   int firstNum = 1;   int secondNum = 2;   ourFirstMethodAddsNumbers(firstNum,secondNum);}
public class Practice {   public static void main(String[] args) {      int firstNum = 1;      int secondNum = 2;      ourFirstMethodAddsNumbers(firstNum,secondNum);   }   public static void ourFirstMethodAddsNumbers(int one, int two) {      int total = one + two;      System.out.println(total);   }}
public class Practice {   public static void main(String[] args) {      int firstNum = 1;      int secondNum = 2;      ourFirstMethodAddsNumbers(firstNum,secondNum);   }   public static int ourFirstMethodAddsNumbers(int one, int two) {      int total = one + two;      return total;   }}
public class Practice {   public static void main(String[] args) {      int firstNum = 1;      int secondNum = 2;      System.out.println(
ourFirstMethodAddsNumbers(firstNum,secondNum)
);
} public static int ourFirstMethodAddsNumbers(int one, int two) { int total = one + two; return total; }}
public class Practice {   public static void main(String[] args) {      int firstNum = 1;      int secondNum = 2;      
int calculation =
ourFirstMethodAddsNumbers(firstNum,secondNum);

System.out.println(calculation);
} public static int ourFirstMethodAddsNumbers(int one, int two) { int total = one + two; return total; }}

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store