Skip to content

Instantly share code, notes, and snippets.

@mangkoran
Created April 7, 2021 03:57
Show Gist options
  • Save mangkoran/460c5b66e7d0256e06d818d23bba0409 to your computer and use it in GitHub Desktop.
Save mangkoran/460c5b66e7d0256e06d818d23bba0409 to your computer and use it in GitHub Desktop.
// Name: Afiq Nazrie Rabbani
// Matric: A19EC0216
public class Test1 {
public static void main(String[] args) {
T t1 = new T();
System.out.print("t1's static i=" + t1.i);
System.out.println(" and instance j=" + t1.j);
T t2 = new T();
System.out.print("t2's static i=" + t2.i);
System.out.println(" and instance j=" + t2.j);
T t3 = new T();
System.out.printf("t3's static i=" + t3.i);
System.out.println(" and instance j=" +t3.j);
}
}
public class T {
static int i = 0;
int j = 0;
public T() {
i++;
j++;
}
}
// Output
// ❯ java Test1.java
// t1's static i=1 and instance j=1
// t2's static i=2 and instance j=1
// t3's static i=3 and instance j=1
// ❯
// Name: Afiq Nazrie Rabbani
// Matric: A19EC0216
public class Test5 {
public static void main(String[] args) {
int i = 5;
int j = 2;
int k = max(i, j);
System.out.print("The maximum between " + i);
System.out.println(" and " + j + " is " + k);
}
public static int max(int num1, int num2) {
int result;
if (num1 > num2) {
result = num1;
}
else result = num2;
return result;
}
}
// Output
// ❯ java Test5.java
// The maximum between 5 and 2 is 5
// ❯
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment