SlideShare a Scribd company logo
//Ques. 5 WAP to store 10 numbers in an array and find out the largest and
the smallest element of the array.

import java.util.Scanner;
public class main {
public static void main(String[] args)
{
final int ARRAY_SIZE = 10;
int[] numbers = new int[ARRAY_SIZE];
getValues(numbers);

System.out.print("n Here are the numbers that you entered: ");

showArray(numbers);
smallestValue(numbers);
largestValue(numbers);
}

private static void getValues(int[] array)
{
Scanner keyboard = new Scanner(System.in);
System.out.println("n Enter a series of " + array.length + " numbers.n ");

for (int index = 0; index < array.length; index++)
{
System.out.print(" Enter Number " + (index + 1) + ": ");
array[index] = keyboard.nextInt();
}
int[] numbers = new int[8];
int largest = numbers[0];
for (int index = 0; index < numbers.length; index++)
{
if (numbers[index] > largest)
{
largest = numbers[index];
}
}

int smallest = numbers[0];
for (int index = 1; index < numbers.length; index++)
{
if (numbers[index] > smallest)
{
smallest = numbers[index];
}
}
}

private static void showArray(int[] array)
{

for (int index = 0; index < array.length; index++)
{
System.out.print(array[index] + " ");
}
}
private static void smallestValue(int[] numbers)
{
int smallest = numbers[0];
for (int index = 1; index < numbers.length; index++)
{
if (numbers[index] < smallest)
{
smallest = numbers[index];
}
}
System.out.print("n The smallest is: " + smallest);
}

private static void largestValue(int[] numbers)
{
int largest = numbers[0];
for (int index = 0; index < numbers.length; index++)
{
if (numbers[index] > largest)
{
largest = numbers[index];
}
}
System.out.print("n The largest is: " + largest);
System.out.println();
}
}
OUTPUT:-

More Related Content

DOCX
2 a networkflow
PPT
Collection Core Concept
PPT
Networking Core Concept
PDF
Core Java Programming Language (JSE) : Chapter V - Arrays
DOCX
PPTX
Queue Implementation Using Array & Linked List
TXT
TXT
Code javascript
2 a networkflow
Collection Core Concept
Networking Core Concept
Core Java Programming Language (JSE) : Chapter V - Arrays
Queue Implementation Using Array & Linked List
Code javascript

What's hot (20)

PDF
Oot practical
PDF
Hashing endereçamento aberto - main
TXT
Empolyee deatils in java
PDF
The Ring programming language version 1.5.2 book - Part 21 of 181
PDF
The Ring programming language version 1.6 book - Part 44 of 189
DOCX
Document
PDF
Basic data structures in python
DOC
BingoConsoleApp
PPTX
Security Events correlation with ESPER
PPTX
กลุ่ม6
PPTX
C sharp 8
PDF
The Ring programming language version 1.5.4 book - Part 23 of 185
PPTX
Circular linked list
PDF
Practice programs
PDF
Python bokeh cheat_sheet
DOCX
Mouse programming in c
PPT
Coherence SIG: Advanced usage of indexes in coherence
PDF
Mozilla とブラウザゲーム
PPTX
Single linked list
Oot practical
Hashing endereçamento aberto - main
Empolyee deatils in java
The Ring programming language version 1.5.2 book - Part 21 of 181
The Ring programming language version 1.6 book - Part 44 of 189
Document
Basic data structures in python
BingoConsoleApp
Security Events correlation with ESPER
กลุ่ม6
C sharp 8
The Ring programming language version 1.5.4 book - Part 23 of 185
Circular linked list
Practice programs
Python bokeh cheat_sheet
Mouse programming in c
Coherence SIG: Advanced usage of indexes in coherence
Mozilla とブラウザゲーム
Single linked list
Ad

More from One97 Communications Limited (20)

DOCX
Er. Model Of Hospital Management
DOCX
Fcfs Cpu Scheduling With Gantt Chart
PPTX
Neural Interfacing
PPT
Blue eye technology
PPTX
Computer Forensics
PPTX
Protect Folders without using any Software
PPTX
Introduction to Java Programming
DOCX
WAP to invoke constructors using super keyword in java
DOCX
WAP to find out whether the number is prime or not in java
DOCX
Overriding abstract in java
DOCX
How to achieve multiple inheritances by using interface in java
DOCX
Method overriding in java
DOCX
WAP to implement inheritance and overloading methods in java
DOCX
program on Function overloading in java
DOCX
Program on usage of Final keyword in java
Er. Model Of Hospital Management
Fcfs Cpu Scheduling With Gantt Chart
Neural Interfacing
Blue eye technology
Computer Forensics
Protect Folders without using any Software
Introduction to Java Programming
WAP to invoke constructors using super keyword in java
WAP to find out whether the number is prime or not in java
Overriding abstract in java
How to achieve multiple inheritances by using interface in java
Method overriding in java
WAP to implement inheritance and overloading methods in java
program on Function overloading in java
Program on usage of Final keyword in java
Ad

Recently uploaded (20)

PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
Basic Mud Logging Guide for educational purpose
PPTX
Week 4 Term 3 Study Techniques revisited.pptx
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
Business Ethics Teaching Materials for college
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
01-Introduction-to-Information-Management.pdf
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
VCE English Exam - Section C Student Revision Booklet
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
Microbial disease of the cardiovascular and lymphatic systems
PPTX
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
PPTX
master seminar digital applications in india
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PDF
RMMM.pdf make it easy to upload and study
PPTX
PPH.pptx obstetrics and gynecology in nursing
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
STATICS OF THE RIGID BODIES Hibbelers.pdf
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Basic Mud Logging Guide for educational purpose
Week 4 Term 3 Study Techniques revisited.pptx
102 student loan defaulters named and shamed – Is someone you know on the list?
Business Ethics Teaching Materials for college
O7-L3 Supply Chain Operations - ICLT Program
01-Introduction-to-Information-Management.pdf
2.FourierTransform-ShortQuestionswithAnswers.pdf
VCE English Exam - Section C Student Revision Booklet
Final Presentation General Medicine 03-08-2024.pptx
Microbial disease of the cardiovascular and lymphatic systems
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
master seminar digital applications in india
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
RMMM.pdf make it easy to upload and study
PPH.pptx obstetrics and gynecology in nursing
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Module 4: Burden of Disease Tutorial Slides S2 2025

WAP to store 10 numbers in an array and find out the largest and the smallest element of the array in java

  • 1. //Ques. 5 WAP to store 10 numbers in an array and find out the largest and the smallest element of the array. import java.util.Scanner; public class main { public static void main(String[] args) { final int ARRAY_SIZE = 10; int[] numbers = new int[ARRAY_SIZE]; getValues(numbers); System.out.print("n Here are the numbers that you entered: "); showArray(numbers); smallestValue(numbers); largestValue(numbers); } private static void getValues(int[] array) { Scanner keyboard = new Scanner(System.in); System.out.println("n Enter a series of " + array.length + " numbers.n "); for (int index = 0; index < array.length; index++) { System.out.print(" Enter Number " + (index + 1) + ": "); array[index] = keyboard.nextInt(); }
  • 2. int[] numbers = new int[8]; int largest = numbers[0]; for (int index = 0; index < numbers.length; index++) { if (numbers[index] > largest) { largest = numbers[index]; } } int smallest = numbers[0]; for (int index = 1; index < numbers.length; index++) { if (numbers[index] > smallest) { smallest = numbers[index]; } } } private static void showArray(int[] array) { for (int index = 0; index < array.length; index++) { System.out.print(array[index] + " "); } }
  • 3. private static void smallestValue(int[] numbers) { int smallest = numbers[0]; for (int index = 1; index < numbers.length; index++) { if (numbers[index] < smallest) { smallest = numbers[index]; } } System.out.print("n The smallest is: " + smallest); } private static void largestValue(int[] numbers) { int largest = numbers[0]; for (int index = 0; index < numbers.length; index++) { if (numbers[index] > largest) { largest = numbers[index]; } } System.out.print("n The largest is: " + largest); System.out.println(); } }