Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
tutorial_repo
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Syed Naqvi
tutorial_repo
Commits
db3a7bcc
Commit
db3a7bcc
authored
2 months ago
by
Syed Naqvi
Browse files
Options
Downloads
Patches
Plain Diff
Solutoin file 1
parent
decede86
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
.DS_Store
+0
-0
0 additions, 0 deletions
.DS_Store
solutions/ArrayFindingMax.java
+38
-0
38 additions, 0 deletions
solutions/ArrayFindingMax.java
with
38 additions
and
0 deletions
.DS_Store
0 → 100644
+
0
−
0
View file @
db3a7bcc
File added
This diff is collapsed.
Click to expand it.
solutions/ArrayFindingMax.java
0 → 100644
+
38
−
0
View file @
db3a7bcc
// Import the Scanner class to take user input
import
java.util.Scanner
;
public
class
ArrayFindingMax
{
public
static
void
main
(
String
[]
args
)
{
// Create a Scanner object to take input from the user
Scanner
scanner
=
new
Scanner
(
System
.
in
);
// Prompt the user to enter the number of elements in the array
System
.
out
.
print
(
"Enter the number of elements: "
);
int
N
=
scanner
.
nextInt
();
// Read user input and store it in variable 'N'
// Declare an array of size 'N' to store numbers entered by the user
int
[]
numbers
=
new
int
[
N
];
// Ask the user to enter 'N' numbers
System
.
out
.
println
(
"Enter "
+
N
+
" numbers:"
);
for
(
int
i
=
0
;
i
<
N
;
i
++)
{
// Loop runs from 0 to N-1
numbers
[
i
]
=
scanner
.
nextInt
();
// Store user input in the array
}
// Assume the first element is the largest (initial max value)
int
max
=
numbers
[
0
];
// Loop through the array starting from the second element (index 1)
for
(
int
i
=
1
;
i
<
N
;
i
++)
{
if
(
numbers
[
i
]
>
max
)
{
// If the current element is greater than 'max'
max
=
numbers
[
i
];
// Update 'max' with the current element
}
}
// Print the largest number found in the array
System
.
out
.
println
(
"The largest number is: "
+
max
);
// Close the scanner to prevent resource leaks
scanner
.
close
();
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment