FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
JavaProgramming/JavaProgrammingBasics.java at main · obliviraorg/JavaProgramming · GitHub
obliviraorg
/
JavaProgramming
Public
forked from
Sbiswas001/JavaProgramming
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
JavaProgramming
/
JavaProgrammingBasics.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
109 lines (95 loc) · 4.01 KB
Breadcrumbs
JavaProgramming
/
JavaProgrammingBasics.java
Copy path
File metadata and controls
109 lines (95 loc) · 4.01 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// ================================================================
// File Name : JavaProgrammingBasics.java
// Author : Agnibesh Maity
// Description : A beginner-friendly Java program demonstrating
// basic programming concepts:
// 1. Class and Object
// 2. Methods and User Input
// 3. Conditional Statements
// 4. Loops and Function Calls
// Created On : October 2025
// ================================================================
import
java
.
util
.
Scanner
;
// ---------------------------------------------------------------
// A simple class with some basic Java functionalities
// ---------------------------------------------------------------
class
JavaProgrammingBasics
{
// Method to display a greeting
void
printGreeting
() {
System
.
out
.
println
(
"
\n
👋 Hello! Welcome to Java Programming Basics!"
);
System
.
out
.
println
(
"Let's explore some simple operations in Java.
\n
"
);
}
// Method to calculate the sum of two numbers
void
sumOfNumbers
(
Scanner
sc
) {
System
.
out
.
println
(
"=== SUM OF TWO NUMBERS ==="
);
System
.
out
.
print
(
"Enter first number: "
);
int
a
=
sc
.
nextInt
();
System
.
out
.
print
(
"Enter second number: "
);
int
b
=
sc
.
nextInt
();
System
.
out
.
println
(
"✅ Sum = "
+ (
a
+
b
));
}
// Method to check even or odd
void
checkEvenOdd
(
Scanner
sc
) {
System
.
out
.
println
(
"
\n
=== EVEN OR ODD CHECKER ==="
);
System
.
out
.
print
(
"Enter a number: "
);
int
n
=
sc
.
nextInt
();
if
(
n
%
2
==
0
)
System
.
out
.
println
(
n
+
" is Even ✅"
);
else
System
.
out
.
println
(
n
+
" is Odd ✅"
);
}
// Method to print a simple pattern
void
printPattern
() {
System
.
out
.
println
(
"
\n
=== SIMPLE PATTERN ==="
);
for
(
int
i
=
1
;
i
<=
5
;
i
++) {
for
(
int
j
=
1
;
j
<=
i
;
j
++) {
System
.
out
.
print
(
"* "
);
}
System
.
out
.
println
();
}
}
// Method to calculate factorial
void
factorialCalculator
(
Scanner
sc
) {
System
.
out
.
println
(
"
\n
=== FACTORIAL CALCULATOR ==="
);
System
.
out
.
print
(
"Enter a number: "
);
int
n
=
sc
.
nextInt
();
long
fact
=
1
;
for
(
int
i
=
1
;
i
<=
n
;
i
++)
fact
*=
i
;
System
.
out
.
println
(
"Factorial of "
+
n
+
" = "
+
fact
);
}
// ---------------------------------------------------------------
// Main Menu
// ---------------------------------------------------------------
public
static
void
main
(
String
[]
args
) {
Scanner
sc
=
new
Scanner
(
System
.
in
);
JavaProgrammingBasics
obj
=
new
JavaProgrammingBasics
();
int
choice
;
obj
.
printGreeting
();
do
{
System
.
out
.
println
(
"==========================================="
);
System
.
out
.
println
(
"🎯 JAVA PROGRAMMING MENU 🎯"
);
System
.
out
.
println
(
"==========================================="
);
System
.
out
.
println
(
"1️⃣ Print Greeting"
);
System
.
out
.
println
(
"2️⃣ Sum of Two Numbers"
);
System
.
out
.
println
(
"3️⃣ Check Even or Odd"
);
System
.
out
.
println
(
"4️⃣ Print Star Pattern"
);
System
.
out
.
println
(
"5️⃣ Find Factorial"
);
System
.
out
.
println
(
"6️⃣ Exit"
);
System
.
out
.
println
(
"-------------------------------------------"
);
System
.
out
.
print
(
"Enter your choice (1-6): "
);
choice
=
sc
.
nextInt
();
switch
(
choice
) {
case
1
->
obj
.
printGreeting
();
case
2
->
obj
.
sumOfNumbers
(
sc
);
case
3
->
obj
.
checkEvenOdd
(
sc
);
case
4
->
obj
.
printPattern
();
case
5
->
obj
.
factorialCalculator
(
sc
);
case
6
->
System
.
out
.
println
(
"
\n
👋 Exiting... Thank you for learning Java!"
);
default
->
System
.
out
.
println
(
"
\n
⚠️ Invalid choice! Please try again."
);
}
System
.
out
.
println
();
}
while
(
choice
!=
6
);
sc
.
close
();
}
}
Back
|
FazBrowse Home
|
New Git URL