Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
J
Java Practice
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Arsam Ali
Java Practice
Commits
ebd4d9e2
Commit
ebd4d9e2
authored
1 year ago
by
Arsam Ali
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
completed the remaining tasks
parent
f56b7608
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
74 additions
and
65 deletions
+74
-65
CelsiusToFahrenheit.java
src/main/java/org/example/CelsiusToFahrenheit.java
+3
-4
FutureDay.java
src/main/java/org/example/FutureDay.java
+4
-6
JavaDiagram.java
src/main/java/org/example/JavaDiagram.java
+3
-5
MonthIntoEnglish.java
src/main/java/org/example/MonthIntoEnglish.java
+4
-8
PopulationOfUs.java
src/main/java/org/example/PopulationOfUs.java
+2
-1
RevisedBMI.java
src/main/java/org/example/RevisedBMI.java
+7
-7
SortThreeIntegers.java
src/main/java/org/example/SortThreeIntegers.java
+17
-17
SumTheDigits.java
src/main/java/org/example/SumTheDigits.java
+15
-12
TableofAndNumeric.java
src/main/java/org/example/TableofAndNumeric.java
+3
-5
TriangleArea.java
src/main/java/org/example/TriangleArea.java
+16
-0
No files found.
src/main/java/org/example/CelsiusToFahrenheit.java
View file @
ebd4d9e2
...
@@ -4,9 +4,7 @@ import java.util.Scanner;
...
@@ -4,9 +4,7 @@ import java.util.Scanner;
public
class
CelsiusToFahrenheit
{
public
class
CelsiusToFahrenheit
{
public
static
void
public
static
void
main
(
String
[]
args
)
main
(
String
[]
args
)
{
{
Scanner
input
=
new
Scanner
(
System
.
in
);
Scanner
input
=
new
Scanner
(
System
.
in
);
...
@@ -14,9 +12,10 @@ public class CelsiusToFahrenheit {
...
@@ -14,9 +12,10 @@ public class CelsiusToFahrenheit {
System
.
out
.
print
(
"Enter a degree in Celsius: "
);
System
.
out
.
print
(
"Enter a degree in Celsius: "
);
double
celsius
=
input
.
nextDouble
();
double
celsius
=
input
.
nextDouble
();
// Fahrenheit=(
5/9 X Celsius)
+32
// Fahrenheit=(
9.0/5) X Celsius
+32
double
fahrenheit
=
(
9.0
/
5
)
*
celsius
+
32
;
double
fahrenheit
=
(
9.0
/
5
)
*
celsius
+
32
;
System
.
out
.
println
(
celsius
+
" Celsius is "
+
fahrenheit
+
" Fahrenheit"
);
System
.
out
.
println
(
celsius
+
" Celsius is "
+
fahrenheit
+
" Fahrenheit"
);
}
}
}
}
This diff is collapsed.
Click to expand it.
src/main/java/org/example/FutureDay.java
View file @
ebd4d9e2
...
@@ -4,22 +4,20 @@ import java.util.Scanner;
...
@@ -4,22 +4,20 @@ import java.util.Scanner;
public
class
FutureDay
{
public
class
FutureDay
{
public
static
void
main
(
String
[]
args
)
public
static
void
main
(
String
[]
args
)
{
{
Scanner
input
=
new
Scanner
(
System
.
in
);
Scanner
input
=
new
Scanner
(
System
.
in
);
System
.
out
.
print
(
"Enter today's day
(0 for Sunday, 1 for Monday, ..., 6 for Saturday):
"
);
System
.
out
.
print
(
"Enter today's day"
);
int
today
=
input
.
nextInt
();
int
today
=
input
.
nextInt
();
System
.
out
.
print
(
"Enter the number of days
elapsed since today:
"
);
System
.
out
.
print
(
"Enter the number of days"
);
int
daysElapsed
=
input
.
nextInt
();
int
daysElapsed
=
input
.
nextInt
();
int
futureDay
=
(
today
+
daysElapsed
)
%
7
;
int
futureDay
=
(
today
+
daysElapsed
)
%
7
;
String
[]
daysOfWeek
=
{
"Sunday"
,
"Monday"
,
"Tuesday"
,
"Wednesday"
,
"Thursday"
,
"Friday"
,
"Saturday"
};
String
[]
daysOfWeek
=
{
"Sunday"
,
"Monday"
,
"Tuesday"
,
"Wednesday"
,
"Thursday"
,
"Friday"
,
"Saturday"
};
System
.
out
.
println
(
"Today is "
+
daysOfWeek
[
today
]
+
" and the
future day is "
+
daysOfWeek
[
futureDay
]);
System
.
out
.
println
(
"Today is "
+
daysOfWeek
[
today
]
+
" and the future day is "
+
daysOfWeek
[
futureDay
]);
}
}
...
...
This diff is collapsed.
Click to expand it.
src/main/java/org/example/JavaDiagram.java
View file @
ebd4d9e2
...
@@ -10,14 +10,12 @@ public class JavaDiagram {
...
@@ -10,14 +10,12 @@ public class JavaDiagram {
"J J AAAAA V V AAAAA"
,
"J J AAAAA V V AAAAA"
,
"J A A V A A"
"J A A V A A"
};
};
for
(
String
row:
rows
){
for
(
String
row
:
rows
)
{
for
(
char
ch
:
row
.
toCharArray
()){
for
(
char
ch
:
row
.
toCharArray
())
{
System
.
out
.
print
(
ch
+
" "
);
System
.
out
.
print
(
ch
+
" "
);
}
}
System
.
out
.
println
();
System
.
out
.
println
();
}
}
}
}
}
}
This diff is collapsed.
Click to expand it.
src/main/java/org/example/MonthIntoEnglish.java
View file @
ebd4d9e2
...
@@ -6,13 +6,9 @@ public class MonthIntoEnglish {
...
@@ -6,13 +6,9 @@ public class MonthIntoEnglish {
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
{
// String[] months = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
String
[]
months
=
{
"January"
,
"February"
,
"March"
,
"April"
,
"May"
,
"June"
,
"July"
,
"August"
,
"September"
,
"October"
,
"November"
,
"December"
};
//
int
monthNumber
=
new
Random
().
nextInt
(
12
);
//
String
monthName
=
months
[
monthNumber
-
1
];
// Random random = new Random();
System
.
out
.
println
(
"Random month: "
+
monthName
);
// int monthNumber = random.nextInt(12) + 1;
//
//
// String monthName =
}
}
}
}
This diff is collapsed.
Click to expand it.
src/main/java/org/example/PopulationOfUs.java
View file @
ebd4d9e2
...
@@ -16,9 +16,10 @@ public class PopulationOfUs {
...
@@ -16,9 +16,10 @@ public class PopulationOfUs {
// Population Change Per Year=(Births Per Second−Deaths Per Second+Immigrants Per Second)×Seconds Per Day×Days Per Year
// Population Change Per Year=(Births Per Second−Deaths Per Second+Immigrants Per Second)×Seconds Per Day×Days Per Year
double
populationChangePerYear
=
(
BIRTHS_PER_SECOND
-
DEATHS_PER_SECOND
+
IMMIGRANTS_PER_SECOND
)
*
SECONDS_PER_DAY
*
DAYS_PER_YEAR
;
double
populationChangePerYear
=
(
BIRTHS_PER_SECOND
-
DEATHS_PER_SECOND
+
IMMIGRANTS_PER_SECOND
)
*
SECONDS_PER_DAY
*
DAYS_PER_YEAR
;
for
(
int
year
=
1
;
year
<=
5
;
year
++)
{
for
(
int
year
=
1
;
year
<=
5
;
year
++)
{
long
newPopulation
=
(
long
)
(
currentPopulation
+
populationChangePerYear
*
year
);
long
newPopulation
=
(
long
)
(
currentPopulation
+
populationChangePerYear
*
year
);
System
.
out
.
println
(
"Year "
+
year
+
": "
+
newPopulation
);
System
.
out
.
println
(
"Year "
+
year
+
": "
+
newPopulation
);
}
}
}
}
}
}
This diff is collapsed.
Click to expand it.
src/main/java/org/example/RevisedBMI.java
View file @
ebd4d9e2
...
@@ -14,24 +14,24 @@ public class RevisedBMI {
...
@@ -14,24 +14,24 @@ public class RevisedBMI {
System
.
out
.
print
(
"Enter inches: "
);
System
.
out
.
print
(
"Enter inches: "
);
int
inches
=
input
.
nextInt
();
int
inches
=
input
.
nextInt
();
// Height in Meters=(Feet
×0
.3048)+(Inches×0.0254)
// Height in Meters=(Feet
*12*
.3048)+(Inches×0.0254)
double
heightInMeters
=
(
feet
*
12
+
inches
)
*
0.0254
;
double
heightInMeters
=
(
feet
*
12
+
inches
)
*
0.0254
;
// Calculate BMI & The constant 0.45359237 is the conversion factor since 1 pound is approximately equal to 0.45359237 kilograms
// Calculate BMI & The constant 0.45359237 is the conversion factor since 1 pound is approximately equal to 0.45359237 kilograms
double
bmi
=
weightInPounds
*
0.45359237
/
(
heightInMeters
*
heightInMeters
);
double
bmi
=
weightInPounds
*
0.45359237
/
(
heightInMeters
*
heightInMeters
);
String
interpretation
=
null
;
String
Level
=
null
;
if
(
bmi
<
18.5
)
{
if
(
bmi
<
18.5
)
{
interpretation
=
"Underweight"
;
Level
=
"Underweight"
;
}
else
if
(
bmi
<
25
)
{
}
else
if
(
bmi
<
25
)
{
interpretation
=
"Normal"
;
Level
=
"Normal"
;
}
else
if
(
bmi
<
30
)
{
}
else
if
(
bmi
<
30
)
{
interpretation
=
"Overweight"
;
Level
=
"Overweight"
;
}
else
{
}
else
{
interpretation
=
"Obese"
;
Level
=
"Obese"
;
}
}
System
.
out
.
println
(
"BMI is "
+
bmi
);
System
.
out
.
println
(
"BMI is "
+
bmi
);
System
.
out
.
println
(
"
Interpretation: "
+
interpretation
);
System
.
out
.
println
(
"
Level: "
+
Level
);
}
}
}
}
This diff is collapsed.
Click to expand it.
src/main/java/org/example/SortThreeIntegers.java
View file @
ebd4d9e2
...
@@ -15,23 +15,23 @@ public class SortThreeIntegers {
...
@@ -15,23 +15,23 @@ public class SortThreeIntegers {
int
temp
;
int
temp
;
if
(
num1
>
num2
)
{
if
(
num1
>
num2
)
{
temp
=
num1
;
temp
=
num1
;
num1
=
num2
;
num1
=
num2
;
num2
=
temp
;
num2
=
temp
;
}
}
if
(
num1
>
num3
)
{
if
(
num1
>
num3
)
{
temp
=
num1
;
temp
=
num1
;
num1
=
num3
;
num1
=
num3
;
num3
=
temp
;
num3
=
temp
;
}
}
if
(
num2
>
num3
)
{
if
(
num2
>
num3
)
{
temp
=
num2
;
temp
=
num2
;
num2
=
num3
;
num2
=
num3
;
num3
=
temp
;
num3
=
temp
;
}
}
System
.
out
.
println
(
"Integers in non-decreasing order: "
+
num1
+
", "
+
num2
+
", "
+
num3
);
System
.
out
.
println
(
"Integers in non-decreasing order: "
+
num1
+
", "
+
num2
+
", "
+
num3
);
}
}
...
...
This diff is collapsed.
Click to expand it.
src/main/java/org/example/SumTheDigits.java
View file @
ebd4d9e2
...
@@ -4,19 +4,22 @@ import java.util.Scanner;
...
@@ -4,19 +4,22 @@ import java.util.Scanner;
public
class
SumTheDigits
{
public
class
SumTheDigits
{
public
static
void
public
static
void
main
(
String
[]
args
)
main
(
String
[]
args
)
{
{
// Scanner input = new Scanner(System.in);
Scanner
input
=
new
Scanner
(
System
.
in
);
//
// System.out.print("Enter a number between 0 and 1000: ");
System
.
out
.
print
(
"Enter a number between 0 and 1000: "
);
// int number = input.nextInt();
int
inputNumber
=
input
.
nextInt
();
//
// int sumOfDigits = 0;
int
sumOfDigits
=
0
;
// while (number > 0) {
while
(
inputNumber
>
0
)
{
// int
int
digit
=
inputNumber
%
10
;
// }
sumOfDigits
+=
digit
;
inputNumber
/=
10
;
}
System
.
out
.
println
(
"The sum of the digits is "
+
sumOfDigits
);
}
}
}
}
This diff is collapsed.
Click to expand it.
src/main/java/org/example/TableofAndNumeric.java
View file @
ebd4d9e2
...
@@ -7,11 +7,9 @@ public class TableofAndNumeric {
...
@@ -7,11 +7,9 @@ public class TableofAndNumeric {
for
(
int
a
=
1
;
a
<=
4
;
a
++)
{
for
(
int
a
=
1
;
a
<=
4
;
a
++)
{
int
a_sq
=
a
*
a
;
int
a_squared
=
a
*
a
;
int
a_cube
=
a
*
a
*
a
;
int
a_cubed
=
a
*
a
*
a
;
System
.
out
.
println
(
a
+
"\t"
+
a_sq
+
"\t"
+
a_cube
);
System
.
out
.
println
(
a
+
"\t"
+
a_squared
+
"\t"
+
a_cubed
);
}
}
}
}
}
}
This diff is collapsed.
Click to expand it.
src/main/java/org/example/TriangleArea.java
View file @
ebd4d9e2
...
@@ -15,8 +15,24 @@ public class TriangleArea {
...
@@ -15,8 +15,24 @@ public class TriangleArea {
double
x3
=
input
.
nextDouble
();
double
x3
=
input
.
nextDouble
();
double
y3
=
input
.
nextDouble
();
double
y3
=
input
.
nextDouble
();
// Calculate side lengths using the distance formula
double
side1
=
calculateSideLength
(
x1
,
y1
,
x2
,
y2
);
double
side2
=
calculateSideLength
(
x2
,
y2
,
x3
,
y3
);
double
side3
=
calculateSideLength
(
x3
,
y3
,
x1
,
y1
);
// Calculate semi-perimeter
double
s
=
(
side1
+
side2
+
side3
)
/
2
;
// Calculate area using Heron's formula
double
area
=
Math
.
sqrt
(
s
*
(
s
-
side1
)
*
(
s
-
side2
)
*
(
s
-
side3
));
System
.
out
.
println
(
"The area of the triangle is "
+
area
);
}
// Helper method to calculate side length using the distance formula
private
static
double
calculateSideLength
(
double
x1
,
double
y1
,
double
x2
,
double
y2
)
{
return
Math
.
sqrt
(
Math
.
pow
(
x2
-
x1
,
2
)
+
Math
.
pow
(
y2
-
y1
,
2
));
}
}
}
}
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment