P1-P5: rewrite to match current syllabus
Signed-off-by: Amneesh Singh <natto@weirdnatto.in>
This commit is contained in:
37
P3.java
37
P3.java
@@ -1,14 +1,27 @@
|
||||
class P3 {
|
||||
public static void main(String[] _args) {
|
||||
int a = 5, b = -5, c = 55, mx;
|
||||
interface Animal {
|
||||
void makeSound();
|
||||
}
|
||||
|
||||
if (a > b && a > c)
|
||||
mx = a;
|
||||
else if ( b > a && b > c)
|
||||
mx = b;
|
||||
else
|
||||
mx = c;
|
||||
class Cat implements Animal {
|
||||
@Override
|
||||
public void makeSound() {
|
||||
System.out.println("Meow!");
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("max(" + a + ", " + b + ", " + c + ") = " + mx);
|
||||
}
|
||||
}
|
||||
class Cow implements Animal {
|
||||
@Override
|
||||
public void makeSound() {
|
||||
System.out.println("Moo!");
|
||||
}
|
||||
}
|
||||
|
||||
public class P3 {
|
||||
public static void main(String[] args) {
|
||||
Animal cat = new Cat();
|
||||
Animal cow = new Cow();
|
||||
|
||||
cat.makeSound();
|
||||
cow.makeSound();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user