Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
18 views
5 pages
OOP Tutorial
Java code about arrays
Uploaded by
Devlyn Tagoe
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF, TXT or read online on Scribd
Download
Save
Save OOP Tutorial For Later
Share
0%
0% found this document useful, undefined
0%
, undefined
Print
Embed
Report
0 ratings
0% found this document useful (0 votes)
18 views
5 pages
OOP Tutorial
Java code about arrays
Uploaded by
Devlyn Tagoe
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF, TXT or read online on Scribd
Carousel Previous
Carousel Next
Download
Save
Save OOP Tutorial For Later
Share
0%
0% found this document useful, undefined
0%
, undefined
Print
Embed
Report
Download
Save OOP Tutorial For Later
You are on page 1
/ 5
Search
Fullscreen
Question 1
Question 2
import java.util.Scanner;
public class Numbers {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// Read the number of elements
System.out.print("Enter the number of integers: ");
int n = scanner.nextInt();
int[] numbers = new int[n];
// Read the elements
System.out.println("Enter the integers:");
for (int i = 0; i < n; i++) {
numbers[i] = scanner.nextInt();
}
// Sort the array using selection sort
selectionSort(numbers);
// Print the sorted array
System.out.println("Sorted integers:");
for (int number : numbers) {
System.out.print(number + " ");
}
}
// Selection Sort Algorithm
public static void selectionSort(int[] arr) {
int n = arr.length;
for (int i = 0; i < n - 1; i++) {
int minIndex = i;
for (int j = i + 1; j < n; j++) {
if (arr[j] < arr[minIndex]) {
minIndex = j;
}
}
int temp = arr[minIndex];
arr[minIndex] = arr[i];
arr[i] = temp;
}
}
}
Question 3
import java.util.Scanner;
public class Strings {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// Read the number of elements
System.out.print("Enter the number of strings: ");
int n = scanner.nextInt();
scanner.nextLine(); // Consume newline
String[] strings = new String[n];
// Read the elements
System.out.println("Enter the strings:");
for (int i = 0; i < n; i++) {
strings[i] = scanner.nextLine();
}
// Sort the array using selection sort
selectionSort(strings);
// Print the sorted array
System.out.println("Sorted strings:");
for (String str : strings) {
System.out.print(str + " ");
}
}
// Selection Sort Algorithm
public static void selectionSort(String[] arr) {
int n = arr.length;
for (int i = 0; i < n - 1; i++) {
int minIndex = i;
for (int j = i + 1; j < n; j++) {
if (arr[j].compareTo(arr[minIndex]) < 0) {
minIndex = j;
}
}
String temp = arr[minIndex];
arr[minIndex] = arr[i];
arr[i] = temp;
}
}
}
Question 4
import java.util.Scanner;
public class Numbers {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// Read the number of elements
System.out.print("Enter the number of integers: ");
int n = scanner.nextInt();
int[] numbers = new int[n];
// Read the elements
System.out.println("Enter the integers:");
for (int i = 0; i < n; i++) {
numbers[i] = scanner.nextInt();
}
// Sort the array using insertion sort in descending order
insertionSort(numbers);
// Print the sorted array
System.out.println("Sorted integers in descending order:");
for (int number : numbers) {
System.out.print(number + " ");
}
}
// Insertion Sort Algorithm (Descending Order)
public static void insertionSort(int[] arr) {
int n = arr.length;
for (int i = 1; i < n; i++) {
int key = arr[i];
int j = i - 1;
// Move elements of arr[0..i-1] that are less than key to one
position ahead
// of their current position
while (j >= 0 && arr[j] < key) {
arr[j + 1] = arr[j];
j = j - 1;
}
arr[j + 1] = key;
}
}
}
You might also like
Average Log Per Zone
PDF
No ratings yet
Average Log Per Zone
12 pages
R Programming
PDF
100% (8)
R Programming
60 pages
SAP Library Overview
PDF
No ratings yet
SAP Library Overview
44 pages
Labsheet 2
PDF
No ratings yet
Labsheet 2
6 pages
L27 Quick, Selection Sort
PDF
No ratings yet
L27 Quick, Selection Sort
17 pages
ADS P1 Corrected
PDF
No ratings yet
ADS P1 Corrected
13 pages
Ccl212!18!2 Bsemc 2 Ola f4 Gaila Andrei Lloyd L.
PDF
No ratings yet
Ccl212!18!2 Bsemc 2 Ola f4 Gaila Andrei Lloyd L.
6 pages
Shorting
PDF
No ratings yet
Shorting
4 pages
Practical 1
PDF
No ratings yet
Practical 1
14 pages
Singly Selection List
PDF
No ratings yet
Singly Selection List
10 pages
Ada Assignment
PDF
No ratings yet
Ada Assignment
24 pages
Struktur Data 3.4 Fariel
PDF
No ratings yet
Struktur Data 3.4 Fariel
6 pages
Sorting
PDF
No ratings yet
Sorting
12 pages
M Labexer5 Sacasas Elizalde
PDF
No ratings yet
M Labexer5 Sacasas Elizalde
13 pages
Youcantcatchme
PDF
No ratings yet
Youcantcatchme
4 pages
Java Lecture 10
PDF
No ratings yet
Java Lecture 10
5 pages
Lab 8 - Sorting
PDF
No ratings yet
Lab 8 - Sorting
12 pages
Selection Sort Sda
PDF
100% (1)
Selection Sort Sda
4 pages
Daa Final - 250203 - 162142
PDF
No ratings yet
Daa Final - 250203 - 162142
69 pages
DSA Assignment 4
PDF
No ratings yet
DSA Assignment 4
12 pages
Arrays Theory & Sorting
PDF
No ratings yet
Arrays Theory & Sorting
11 pages
Daa Lab Manual - Final
PDF
No ratings yet
Daa Lab Manual - Final
21 pages
JAVA3RDEX
PDF
No ratings yet
JAVA3RDEX
9 pages
Daa 1
PDF
No ratings yet
Daa 1
5 pages
Bubble Sort & Char and String Array
PDF
No ratings yet
Bubble Sort & Char and String Array
11 pages
Valencia, Gian Kurt D. CEIT-37-302-A: Code
PDF
No ratings yet
Valencia, Gian Kurt D. CEIT-37-302-A: Code
8 pages
1-D Array Part 2
PDF
No ratings yet
1-D Array Part 2
12 pages
Experiment 2
PDF
No ratings yet
Experiment 2
6 pages
Bubble Sort in Java Array
PDF
No ratings yet
Bubble Sort in Java Array
12 pages
w13 Cpe121
PDF
No ratings yet
w13 Cpe121
11 pages
9629 Aoaexp1
PDF
No ratings yet
9629 Aoaexp1
6 pages
Sorting Algorithms
PDF
No ratings yet
Sorting Algorithms
13 pages
Sorting and Searching in Arrays Class X
PDF
No ratings yet
Sorting and Searching in Arrays Class X
5 pages
1-D Array Part 2
PDF
No ratings yet
1-D Array Part 2
12 pages
Java Assignment8
PDF
No ratings yet
Java Assignment8
3 pages
Array Index or Key. An Array Is Stored Such That The Position of Each Element Can Be Computed From Its Index Tuple by
PDF
No ratings yet
Array Index or Key. An Array Is Stored Such That The Position of Each Element Can Be Computed From Its Index Tuple by
5 pages
Grade10 UT2 AK
PDF
No ratings yet
Grade10 UT2 AK
3 pages
Vinay (06919051624)
PDF
No ratings yet
Vinay (06919051624)
11 pages
Design and Analysis of Algorithm
PDF
No ratings yet
Design and Analysis of Algorithm
34 pages
Arrays& Library Classes - Address Calculation
PDF
No ratings yet
Arrays& Library Classes - Address Calculation
22 pages
String Operations
PDF
No ratings yet
String Operations
6 pages
Notability Notes
PDF
No ratings yet
Notability Notes
40 pages
Sorting (Bubble, Selection, Insertion, Shell, Quick)
PDF
No ratings yet
Sorting (Bubble, Selection, Insertion, Shell, Quick)
33 pages
DS Unit-4
PDF
No ratings yet
DS Unit-4
48 pages
Comp and Bio
PDF
No ratings yet
Comp and Bio
3 pages
PracticeSet DS Solved
PDF
No ratings yet
PracticeSet DS Solved
19 pages
Prashant Oops Quiz
PDF
No ratings yet
Prashant Oops Quiz
11 pages
Searching and Sorting Algorithm Programs
PDF
No ratings yet
Searching and Sorting Algorithm Programs
6 pages
Assignment 4 Name: Subham Mukherjee Sec: B Roll No: 56 Enrolment No: 12019009002101
PDF
No ratings yet
Assignment 4 Name: Subham Mukherjee Sec: B Roll No: 56 Enrolment No: 12019009002101
13 pages
Week-11 Assignment - July - 2024
PDF
No ratings yet
Week-11 Assignment - July - 2024
8 pages
Daa Practical File
PDF
No ratings yet
Daa Practical File
16 pages
OOPS Manual Updated-2
PDF
No ratings yet
OOPS Manual Updated-2
42 pages
Lab Manual
PDF
No ratings yet
Lab Manual
59 pages
Sorting Algorithms: College of Computer Engineering Requirements For The Performance Innovative Task BSCPE-2C
PDF
No ratings yet
Sorting Algorithms: College of Computer Engineering Requirements For The Performance Innovative Task BSCPE-2C
13 pages
555
PDF
No ratings yet
555
4 pages
Lab 5,6,7
PDF
No ratings yet
Lab 5,6,7
18 pages
CS3381 Oop Manual Cse
PDF
No ratings yet
CS3381 Oop Manual Cse
52 pages
Adapdf
PDF
No ratings yet
Adapdf
43 pages
Sorting
PDF
No ratings yet
Sorting
9 pages
Untitled Document
PDF
No ratings yet
Untitled Document
11 pages
Chapter 3 Sorting Part 1
PDF
No ratings yet
Chapter 3 Sorting Part 1
66 pages
Basic Sorting Algorithms
PDF
No ratings yet
Basic Sorting Algorithms
16 pages
Advanced C Concepts and Programming: First Edition
From Everand
Advanced C Concepts and Programming: First Edition
Gayatri
3/5 (1)
Emerging Issues in Communication Research
PDF
No ratings yet
Emerging Issues in Communication Research
18 pages
Class XII Computer Science HHW Project
PDF
No ratings yet
Class XII Computer Science HHW Project
3 pages
Polarfox Firstlook
PDF
100% (1)
Polarfox Firstlook
14 pages
Digital Signal Processing: Instructor: Jen-Hui Chuang Instructor: Jen-Hui Chuang
PDF
No ratings yet
Digital Signal Processing: Instructor: Jen-Hui Chuang Instructor: Jen-Hui Chuang
31 pages
Real Estate Project Status Report
PDF
No ratings yet
Real Estate Project Status Report
2 pages
Optimized Sectorization
PDF
No ratings yet
Optimized Sectorization
11 pages
Pragma Solidity
PDF
No ratings yet
Pragma Solidity
43 pages
Goldengate On ASM Using DBLOGREADER
PDF
No ratings yet
Goldengate On ASM Using DBLOGREADER
5 pages
Wolaita Sodo University School of Informatics Department of Information Systems
PDF
No ratings yet
Wolaita Sodo University School of Informatics Department of Information Systems
165 pages
Components para Impressora, Com Cabeças XAAR1001
PDF
No ratings yet
Components para Impressora, Com Cabeças XAAR1001
2 pages
Egranger Version 1 Code
PDF
No ratings yet
Egranger Version 1 Code
7 pages
Log4j Example Code - Tutorialspoint Examples
PDF
No ratings yet
Log4j Example Code - Tutorialspoint Examples
2 pages
Understanding Linux Malware
PDF
No ratings yet
Understanding Linux Malware
15 pages
Linux: Linux Kernel Linux (Disambiguation)
PDF
No ratings yet
Linux: Linux Kernel Linux (Disambiguation)
3 pages
Structural Health Monitoring
PDF
No ratings yet
Structural Health Monitoring
10 pages
Customer Data
PDF
No ratings yet
Customer Data
18 pages
Tariq Aziz: Civil Engineer (PEC Reg)
PDF
No ratings yet
Tariq Aziz: Civil Engineer (PEC Reg)
1 page
I-Wish-I-Knew-How-It-Would-Feel-To-Be-Free.p : Search
PDF
No ratings yet
I-Wish-I-Knew-How-It-Would-Feel-To-Be-Free.p : Search
2 pages
Final Java Lab
PDF
No ratings yet
Final Java Lab
32 pages
Sources of Innovation: Topic 6
PDF
100% (1)
Sources of Innovation: Topic 6
36 pages
How To Remove The .Ink Virus File
PDF
No ratings yet
How To Remove The .Ink Virus File
5 pages
Stability
PDF
No ratings yet
Stability
66 pages
Code Blocks
PDF
No ratings yet
Code Blocks
5 pages
Carl Friedrich Gauss Werke 8
PDF
No ratings yet
Carl Friedrich Gauss Werke 8
472 pages
Manual Capella-Scan V.8
PDF
No ratings yet
Manual Capella-Scan V.8
103 pages
EFDC DSI Lagrangian Particle Tracking PDF
PDF
No ratings yet
EFDC DSI Lagrangian Particle Tracking PDF
24 pages
Effective Use of NCD LCD and Ncci Edits For Clean Claims
PDF
No ratings yet
Effective Use of NCD LCD and Ncci Edits For Clean Claims
20 pages