SlideShare a Scribd company logo
1 of 4
//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

What's hot

Practice programs
Practice programsPractice programs
Practice programs
Abbott
 
Mouse programming in c
Mouse programming in cMouse programming in c
Mouse programming in c
gkgaur1987
 
Coherence SIG: Advanced usage of indexes in coherence
Coherence SIG: Advanced usage of indexes in coherenceCoherence SIG: Advanced usage of indexes in coherence
Coherence SIG: Advanced usage of indexes in coherence
aragozin
 

What's hot (20)

Oot practical
Oot practicalOot practical
Oot practical
 
Hashing endereçamento aberto - main
Hashing endereçamento aberto - mainHashing endereçamento aberto - main
Hashing endereçamento aberto - main
 
Empolyee deatils in java
Empolyee deatils in javaEmpolyee deatils in java
Empolyee deatils in java
 
The Ring programming language version 1.5.2 book - Part 21 of 181
The Ring programming language version 1.5.2 book - Part 21 of 181The Ring programming language version 1.5.2 book - Part 21 of 181
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
The Ring programming language version 1.6 book - Part 44 of 189The Ring programming language version 1.6 book - Part 44 of 189
The Ring programming language version 1.6 book - Part 44 of 189
 
Document
DocumentDocument
Document
 
Basic data structures in python
Basic data structures in pythonBasic data structures in python
Basic data structures in python
 
BingoConsoleApp
BingoConsoleAppBingoConsoleApp
BingoConsoleApp
 
Security Events correlation with ESPER
Security Events correlation with ESPERSecurity Events correlation with ESPER
Security Events correlation with ESPER
 
กลุ่ม6
กลุ่ม6กลุ่ม6
กลุ่ม6
 
C sharp 8
C sharp 8C sharp 8
C sharp 8
 
The Ring programming language version 1.5.4 book - Part 23 of 185
The Ring programming language version 1.5.4 book - Part 23 of 185The Ring programming language version 1.5.4 book - Part 23 of 185
The Ring programming language version 1.5.4 book - Part 23 of 185
 
Circular linked list
Circular linked listCircular linked list
Circular linked list
 
Practice programs
Practice programsPractice programs
Practice programs
 
Python bokeh cheat_sheet
Python bokeh cheat_sheet Python bokeh cheat_sheet
Python bokeh cheat_sheet
 
Mouse programming in c
Mouse programming in cMouse programming in c
Mouse programming in c
 
Coherence SIG: Advanced usage of indexes in coherence
Coherence SIG: Advanced usage of indexes in coherenceCoherence SIG: Advanced usage of indexes in coherence
Coherence SIG: Advanced usage of indexes in coherence
 
Mozilla とブラウザゲーム
Mozilla とブラウザゲームMozilla とブラウザゲーム
Mozilla とブラウザゲーム
 
Single linked list
Single linked listSingle linked list
Single linked list
 
week-13x
week-13xweek-13x
week-13x
 

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

ArrayTest.java import java.util.Arrays; import java.util.Scann.pdf
ArrayTest.java import java.util.Arrays; import java.util.Scann.pdfArrayTest.java import java.util.Arrays; import java.util.Scann.pdf
ArrayTest.java import java.util.Arrays; import java.util.Scann.pdf
deepua8
 
Chapter 7.1
Chapter 7.1Chapter 7.1
Chapter 7.1
sotlsoc
 
import java.util.ArrayList; import java.util.Scanner;public clas.pdf
import java.util.ArrayList; import java.util.Scanner;public clas.pdfimport java.util.ArrayList; import java.util.Scanner;public clas.pdf
import java.util.ArrayList; import java.util.Scanner;public clas.pdf
shettysachin2005
 
import java.uti-WPS Office.docx
import java.uti-WPS Office.docximport java.uti-WPS Office.docx
import java.uti-WPS Office.docx
Katecate1
 
Write a program that obtains the execution time of selection sort, bu.pdf
Write a program that obtains the execution time of selection sort, bu.pdfWrite a program that obtains the execution time of selection sort, bu.pdf
Write a program that obtains the execution time of selection sort, bu.pdf
arri2009av
 
CountPositiveNumbersInArray.javapackage org.students;import java.pdf
CountPositiveNumbersInArray.javapackage org.students;import java.pdfCountPositiveNumbersInArray.javapackage org.students;import java.pdf
CountPositiveNumbersInArray.javapackage org.students;import java.pdf
aparnatiwari291
 
Program 1The following program manipulates array of inte.docx
Program 1The following program manipulates array of inte.docxProgram 1The following program manipulates array of inte.docx
Program 1The following program manipulates array of inte.docx
briancrawford30935
 
Create a menu-driven program that will accept a collection of non-ne.pdf
Create a menu-driven program that will accept a collection of non-ne.pdfCreate a menu-driven program that will accept a collection of non-ne.pdf
Create a menu-driven program that will accept a collection of non-ne.pdf
rajeshjangid1865
 
Java programs - bubble sort, iterator, linked list, hash set, reverse string,...
Java programs - bubble sort, iterator, linked list, hash set, reverse string,...Java programs - bubble sort, iterator, linked list, hash set, reverse string,...
Java programs - bubble sort, iterator, linked list, hash set, reverse string,...
Sunil Kumar Gunasekaran
 
Multi dimensional arrays
Multi dimensional arraysMulti dimensional arrays
Multi dimensional arrays
Aseelhalees
 

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

ArrayTest.java import java.util.Arrays; import java.util.Scann.pdf
ArrayTest.java import java.util.Arrays; import java.util.Scann.pdfArrayTest.java import java.util.Arrays; import java.util.Scann.pdf
ArrayTest.java import java.util.Arrays; import java.util.Scann.pdf
 
Chapter 7.1
Chapter 7.1Chapter 7.1
Chapter 7.1
 
Array in Java
Array in JavaArray in Java
Array in Java
 
6_Array.pptx
6_Array.pptx6_Array.pptx
6_Array.pptx
 
07. Java Array, Set and Maps
07.  Java Array, Set and Maps07.  Java Array, Set and Maps
07. Java Array, Set and Maps
 
import java.util.ArrayList; import java.util.Scanner;public clas.pdf
import java.util.ArrayList; import java.util.Scanner;public clas.pdfimport java.util.ArrayList; import java.util.Scanner;public clas.pdf
import java.util.ArrayList; import java.util.Scanner;public clas.pdf
 
Write an application that stores 12 integers in an array. Display the.docx
 Write an application that stores 12 integers in an array. Display the.docx Write an application that stores 12 integers in an array. Display the.docx
Write an application that stores 12 integers in an array. Display the.docx
 
import java.uti-WPS Office.docx
import java.uti-WPS Office.docximport java.uti-WPS Office.docx
import java.uti-WPS Office.docx
 
Write a program that obtains the execution time of selection sort, bu.pdf
Write a program that obtains the execution time of selection sort, bu.pdfWrite a program that obtains the execution time of selection sort, bu.pdf
Write a program that obtains the execution time of selection sort, bu.pdf
 
CountPositiveNumbersInArray.javapackage org.students;import java.pdf
CountPositiveNumbersInArray.javapackage org.students;import java.pdfCountPositiveNumbersInArray.javapackage org.students;import java.pdf
CountPositiveNumbersInArray.javapackage org.students;import java.pdf
 
Unit-2.Arrays and Strings.pptx.................
Unit-2.Arrays and Strings.pptx.................Unit-2.Arrays and Strings.pptx.................
Unit-2.Arrays and Strings.pptx.................
 
Program 1The following program manipulates array of inte.docx
Program 1The following program manipulates array of inte.docxProgram 1The following program manipulates array of inte.docx
Program 1The following program manipulates array of inte.docx
 
Arrays
ArraysArrays
Arrays
 
Write a program that will test a name) method no sorting routine from.docx
 Write a program that will test a name) method no sorting routine from.docx Write a program that will test a name) method no sorting routine from.docx
Write a program that will test a name) method no sorting routine from.docx
 
Java file
Java fileJava file
Java file
 
Java file
Java fileJava file
Java file
 
Create a menu-driven program that will accept a collection of non-ne.pdf
Create a menu-driven program that will accept a collection of non-ne.pdfCreate a menu-driven program that will accept a collection of non-ne.pdf
Create a menu-driven program that will accept a collection of non-ne.pdf
 
Lecture 6
Lecture 6Lecture 6
Lecture 6
 
Java programs - bubble sort, iterator, linked list, hash set, reverse string,...
Java programs - bubble sort, iterator, linked list, hash set, reverse string,...Java programs - bubble sort, iterator, linked list, hash set, reverse string,...
Java programs - bubble sort, iterator, linked list, hash set, reverse string,...
 
Multi dimensional arrays
Multi dimensional arraysMulti dimensional arrays
Multi dimensional arrays
 

More from One97 Communications Limited

More from One97 Communications Limited (20)

Er. Model Of Hospital Management
Er. Model Of Hospital ManagementEr. Model Of Hospital Management
Er. Model Of Hospital Management
 
Financial
FinancialFinancial
Financial
 
Railway
RailwayRailway
Railway
 
Library
LibraryLibrary
Library
 
Fcfs Cpu Scheduling With Gantt Chart
Fcfs Cpu Scheduling With Gantt ChartFcfs Cpu Scheduling With Gantt Chart
Fcfs Cpu Scheduling With Gantt Chart
 
Neural Interfacing
Neural Interfacing Neural Interfacing
Neural Interfacing
 
Blue eye technology
Blue eye technology Blue eye technology
Blue eye technology
 
Computer Forensics
Computer ForensicsComputer Forensics
Computer Forensics
 
Backtrack
BacktrackBacktrack
Backtrack
 
Protect Folders without using any Software
Protect Folders without using any SoftwareProtect Folders without using any Software
Protect Folders without using any Software
 
Introduction to Java Programming
Introduction to Java ProgrammingIntroduction to Java Programming
Introduction to Java Programming
 
Topology
TopologyTopology
Topology
 
WAP to invoke constructors using super keyword in java
WAP to invoke constructors using super keyword in javaWAP to invoke constructors using super keyword in java
WAP to invoke constructors using super keyword in java
 
WAP to find out whether the number is prime or not in java
WAP to find out whether the number is prime or not in javaWAP to find out whether the number is prime or not in java
WAP to find out whether the number is prime or not in java
 
Overriding abstract in java
Overriding abstract in javaOverriding abstract in java
Overriding abstract in java
 
How to achieve multiple inheritances by using interface in java
How to achieve multiple inheritances by using interface in java How to achieve multiple inheritances by using interface in java
How to achieve multiple inheritances by using interface in java
 
Method overriding in java
Method overriding in javaMethod overriding in java
Method overriding in java
 
WAP to implement inheritance and overloading methods in java
WAP to implement inheritance and overloading methods in javaWAP to implement inheritance and overloading methods in java
WAP to implement inheritance and overloading methods in java
 
program on Function overloading in java
program on  Function overloading in javaprogram on  Function overloading in java
program on Function overloading in java
 
Program on usage of Final keyword in java
Program on usage of  Final keyword in javaProgram on usage of  Final keyword in java
Program on usage of Final keyword in java
 

Recently uploaded

Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
heathfieldcps1
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
negromaestrong
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdf
SanaAli374401
 

Recently uploaded (20)

fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdf
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 

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(); } }