-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathevenOdd.java
More file actions
61 lines (43 loc) · 1.43 KB
/
evenOdd.java
File metadata and controls
61 lines (43 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*public class evenOdd {
static int number = 4;
//number is static variable
public static void main(String[] args){
System.out.println(number + 4); //no need to define a function
}
}*/
import java.util.Scanner;
/*class Example {
int value = 10; // Non-static variable
}
public class Main {
public static void main(String[] args) {
Example obj = new Example(); // Create an object
System.out.println(obj.value); // Accessing via the object
}
}*/
public class evenOdd {
public static int number = 4; // number is a static variable
public static void main(String[] args) {
if (number % 2 == 0) {
System.out.println("a is even!");
} else {
System.out.println("a is odd!");
}
}
}
class Counter {
static int totalObjects = 0; // Shared among all instances
Counter() {
totalObjects++;
}
}
class Car {
String brand; // Each object has its own brand
Car(String brand) {
this.brand = brand;
}
}
class Num {
int x = 5;
System.out.println(x *= 2 + 3);
}