SlideShare a Scribd company logo
1 of 6
Download to read offline
import java.util.LinkedList;
import java.util.Random;
import java.util.Scanner;
/**
* author
*
*/
public class LinkedListTest {
/**
* param args
*/
public static void main(String[] args) {
int M, N, Lower, Upper;
Scanner scanner = null;
try {
LinkedList list1 = new LinkedList();
LinkedList list2 = new LinkedList();
LinkedList list3 = new LinkedList();
Random random = new Random();
scanner = new Scanner(System.in);
System.out.print("Enter the Lower and Upper bounds:");
Lower = scanner.nextInt();
Upper = scanner.nextInt();
System.out.print("Enter the N value to Insert list1:");
N = scanner.nextInt();
System.out.print("Enter the M value to Insert list2:");
M = scanner.nextInt();
for (int i = 1; i <= N; i++) {
list1.add(random.nextInt((Upper - Lower) + 1) + Lower);
}
for (int i = 1; i <= M; i++) {
list2.add(random.nextInt((Upper - Lower) + 1) + Lower);
}
System.out.println("list1: " + list1);
System.out.println("list2: " + list2);
System.out.println("Minimum elelment in list1 :" + getMin(list1));
System.out.println("Minimum elelment in list2 :" + getMin(list2));
System.out
.println("Count Divisibles by 3 and 5 elelment in list1 :"
+ countDivisibles(list1));
System.out
.println("Count Divisibles by 3 and 5 elelment in list2 :"
+ countDivisibles(list2));
System.out.println("Common Elements From list1 and list2:"
+ getCommonList(list1, list2));
} catch (Exception e) {
// TODO: handle exception
}
}
/**
* param list
* return
*/
public static int getMin(LinkedList list) {
int min = list.get(0);
for (Integer integer : list) {
if (min > integer) {
min = integer;
}
}
return min;
}
/**
* param list
* return
*/
public static int countDivisibles(LinkedList list) {
int count = 0;
for (Integer integer : list) {
if (integer % 3 == 0 && integer % 5 == 0) {
count++;
}
}
return count;
}
/**
* param list1
* param list2
* return
*/
public static LinkedList getCommonList(LinkedList list1,
LinkedList list2) {
LinkedList list = new LinkedList();
LinkedList listCommon = new LinkedList();
list = (list1.size() > list2.size()) ? list1 : list2;
for (int i = 0; i < list.size(); i++) {
Integer number = list.get(i);
if (list2.contains(number) && list1.contains(number)) {
listCommon.add(number);
}
}
return listCommon;
}
}
OUTPUT:
Enter the Lower and Upper bounds:1 10
Enter the N value to Insert list1:10
Enter the M value to Insert list2:20
list1: [1, 4, 4, 6, 9, 4, 9, 5, 8, 5]
list2: [5, 10, 10, 2, 1, 10, 8, 8, 8, 2, 6, 10, 6, 2, 5, 9, 6, 9, 6, 2]
Minimum elelment in list1 :1
Minimum elelment in list2 :1
Count Divisibles by 3 and 5 elelment in list1 :0
Count Divisibles by 3 and 5 elelment in list2 :0
Common Elements From list1 and list2:[5, 1, 8, 8, 8, 6, 6, 5, 9, 6, 9, 6]
Solution
import java.util.LinkedList;
import java.util.Random;
import java.util.Scanner;
/**
* author
*
*/
public class LinkedListTest {
/**
* param args
*/
public static void main(String[] args) {
int M, N, Lower, Upper;
Scanner scanner = null;
try {
LinkedList list1 = new LinkedList();
LinkedList list2 = new LinkedList();
LinkedList list3 = new LinkedList();
Random random = new Random();
scanner = new Scanner(System.in);
System.out.print("Enter the Lower and Upper bounds:");
Lower = scanner.nextInt();
Upper = scanner.nextInt();
System.out.print("Enter the N value to Insert list1:");
N = scanner.nextInt();
System.out.print("Enter the M value to Insert list2:");
M = scanner.nextInt();
for (int i = 1; i <= N; i++) {
list1.add(random.nextInt((Upper - Lower) + 1) + Lower);
}
for (int i = 1; i <= M; i++) {
list2.add(random.nextInt((Upper - Lower) + 1) + Lower);
}
System.out.println("list1: " + list1);
System.out.println("list2: " + list2);
System.out.println("Minimum elelment in list1 :" + getMin(list1));
System.out.println("Minimum elelment in list2 :" + getMin(list2));
System.out
.println("Count Divisibles by 3 and 5 elelment in list1 :"
+ countDivisibles(list1));
System.out
.println("Count Divisibles by 3 and 5 elelment in list2 :"
+ countDivisibles(list2));
System.out.println("Common Elements From list1 and list2:"
+ getCommonList(list1, list2));
} catch (Exception e) {
// TODO: handle exception
}
}
/**
* param list
* return
*/
public static int getMin(LinkedList list) {
int min = list.get(0);
for (Integer integer : list) {
if (min > integer) {
min = integer;
}
}
return min;
}
/**
* param list
* return
*/
public static int countDivisibles(LinkedList list) {
int count = 0;
for (Integer integer : list) {
if (integer % 3 == 0 && integer % 5 == 0) {
count++;
}
}
return count;
}
/**
* param list1
* param list2
* return
*/
public static LinkedList getCommonList(LinkedList list1,
LinkedList list2) {
LinkedList list = new LinkedList();
LinkedList listCommon = new LinkedList();
list = (list1.size() > list2.size()) ? list1 : list2;
for (int i = 0; i < list.size(); i++) {
Integer number = list.get(i);
if (list2.contains(number) && list1.contains(number)) {
listCommon.add(number);
}
}
return listCommon;
}
}
OUTPUT:
Enter the Lower and Upper bounds:1 10
Enter the N value to Insert list1:10
Enter the M value to Insert list2:20
list1: [1, 4, 4, 6, 9, 4, 9, 5, 8, 5]
list2: [5, 10, 10, 2, 1, 10, 8, 8, 8, 2, 6, 10, 6, 2, 5, 9, 6, 9, 6, 2]
Minimum elelment in list1 :1
Minimum elelment in list2 :1
Count Divisibles by 3 and 5 elelment in list1 :0
Count Divisibles by 3 and 5 elelment in list2 :0
Common Elements From list1 and list2:[5, 1, 8, 8, 8, 6, 6, 5, 9, 6, 9, 6]

More Related Content

Similar to import java.util.LinkedList; import java.util.Random; import jav.pdf

Refer to my progress on this assignment belowIn this problem you w.pdf
Refer to my progress on this assignment belowIn this problem you w.pdfRefer to my progress on this assignment belowIn this problem you w.pdf
Refer to my progress on this assignment belowIn this problem you w.pdf
arishmarketing21
 
In this homework- you will write a program modify program you wrote in.pdf
In this homework- you will write a program modify program you wrote in.pdfIn this homework- you will write a program modify program you wrote in.pdf
In this homework- you will write a program modify program you wrote in.pdf
EvanpZjSandersony
 
I am stuck on parts E and FExercise 1      NumberListTester.java.pdf
I am stuck on parts E and FExercise 1      NumberListTester.java.pdfI am stuck on parts E and FExercise 1      NumberListTester.java.pdf
I am stuck on parts E and FExercise 1      NumberListTester.java.pdf
RAJATCHUGH12
 
Hi,I have added the methods and main class as per your requirement.pdf
Hi,I have added the methods and main class as per your requirement.pdfHi,I have added the methods and main class as per your requirement.pdf
Hi,I have added the methods and main class as per your requirement.pdf
annaelctronics
 
Need to be done in C++ Please Sorted number list implementation wit.pdf
Need to be done in C++  Please   Sorted number list implementation wit.pdfNeed to be done in C++  Please   Sorted number list implementation wit.pdf
Need to be done in C++ Please Sorted number list implementation wit.pdf
aathiauto
 
I only need help with four methods in the EmployeeManager class the .pdf
I only need help with four methods in the EmployeeManager class the .pdfI only need help with four methods in the EmployeeManager class the .pdf
I only need help with four methods in the EmployeeManager class the .pdf
arpitcomputronics
 
Python Unit 5 Questions n Notes.pdf
Python Unit 5 Questions n Notes.pdfPython Unit 5 Questions n Notes.pdf
Python Unit 5 Questions n Notes.pdf
MCCMOTOR
 
c++ program I need to sort arrays using an insertion sort and a mer.pdf
c++ program I need to sort arrays using an insertion sort and a mer.pdfc++ program I need to sort arrays using an insertion sort and a mer.pdf
c++ program I need to sort arrays using an insertion sort and a mer.pdf
dhavalbl38
 
Write a function which return a list of all of the n element subset .pdf
Write a function which return a list of all of the n element subset .pdfWrite a function which return a list of all of the n element subset .pdf
Write a function which return a list of all of the n element subset .pdf
hardjasonoco14599
 
Need to be done in C Please Sorted number list implementation with.pdf
Need to be done in C  Please   Sorted number list implementation with.pdfNeed to be done in C  Please   Sorted number list implementation with.pdf
Need to be done in C Please Sorted number list implementation with.pdf
aathmaproducts
 

Similar to import java.util.LinkedList; import java.util.Random; import jav.pdf (20)

C programs
C programsC programs
C programs
 
Unit 4 python -list methods
Unit 4   python -list methodsUnit 4   python -list methods
Unit 4 python -list methods
 
Refer to my progress on this assignment belowIn this problem you w.pdf
Refer to my progress on this assignment belowIn this problem you w.pdfRefer to my progress on this assignment belowIn this problem you w.pdf
Refer to my progress on this assignment belowIn this problem you w.pdf
 
Python programming workshop session 3
Python programming workshop session 3Python programming workshop session 3
Python programming workshop session 3
 
In this homework- you will write a program modify program you wrote in.pdf
In this homework- you will write a program modify program you wrote in.pdfIn this homework- you will write a program modify program you wrote in.pdf
In this homework- you will write a program modify program you wrote in.pdf
 
6_Array.pptx
6_Array.pptx6_Array.pptx
6_Array.pptx
 
I am stuck on parts E and FExercise 1      NumberListTester.java.pdf
I am stuck on parts E and FExercise 1      NumberListTester.java.pdfI am stuck on parts E and FExercise 1      NumberListTester.java.pdf
I am stuck on parts E and FExercise 1      NumberListTester.java.pdf
 
Hi,I have added the methods and main class as per your requirement.pdf
Hi,I have added the methods and main class as per your requirement.pdfHi,I have added the methods and main class as per your requirement.pdf
Hi,I have added the methods and main class as per your requirement.pdf
 
DS LAB RECORD.docx
DS LAB RECORD.docxDS LAB RECORD.docx
DS LAB RECORD.docx
 
Need to be done in C++ Please Sorted number list implementation wit.pdf
Need to be done in C++  Please   Sorted number list implementation wit.pdfNeed to be done in C++  Please   Sorted number list implementation wit.pdf
Need to be done in C++ Please Sorted number list implementation wit.pdf
 
I only need help with four methods in the EmployeeManager class the .pdf
I only need help with four methods in the EmployeeManager class the .pdfI only need help with four methods in the EmployeeManager class the .pdf
I only need help with four methods in the EmployeeManager class the .pdf
 
Python Unit 5 Questions n Notes.pdf
Python Unit 5 Questions n Notes.pdfPython Unit 5 Questions n Notes.pdf
Python Unit 5 Questions n Notes.pdf
 
c++ program I need to sort arrays using an insertion sort and a mer.pdf
c++ program I need to sort arrays using an insertion sort and a mer.pdfc++ program I need to sort arrays using an insertion sort and a mer.pdf
c++ program I need to sort arrays using an insertion sort and a mer.pdf
 
An Introduction to Part of C++ STL
An Introduction to Part of C++ STLAn Introduction to Part of C++ STL
An Introduction to Part of C++ STL
 
Python list
Python listPython list
Python list
 
Python Data Types.pdf
Python Data Types.pdfPython Data Types.pdf
Python Data Types.pdf
 
Python Data Types (1).pdf
Python Data Types (1).pdfPython Data Types (1).pdf
Python Data Types (1).pdf
 
Write a function which return a list of all of the n element subset .pdf
Write a function which return a list of all of the n element subset .pdfWrite a function which return a list of all of the n element subset .pdf
Write a function which return a list of all of the n element subset .pdf
 
Need to be done in C Please Sorted number list implementation with.pdf
Need to be done in C  Please   Sorted number list implementation with.pdfNeed to be done in C  Please   Sorted number list implementation with.pdf
Need to be done in C Please Sorted number list implementation with.pdf
 
Module-2.pptx
Module-2.pptxModule-2.pptx
Module-2.pptx
 

More from aquastore223

1. How new modern materials prompted changes in architecture in the .pdf
1. How new modern materials prompted changes in architecture in the .pdf1. How new modern materials prompted changes in architecture in the .pdf
1. How new modern materials prompted changes in architecture in the .pdf
aquastore223
 
c++ code for a Median of Integer Stream from Text File program#.pdf
 c++ code for a Median of Integer Stream from Text File program#.pdf c++ code for a Median of Integer Stream from Text File program#.pdf
c++ code for a Median of Integer Stream from Text File program#.pdf
aquastore223
 
Sodium hydroxide, also known as lye and caustic s.pdf
                     Sodium hydroxide, also known as lye and caustic s.pdf                     Sodium hydroxide, also known as lye and caustic s.pdf
Sodium hydroxide, also known as lye and caustic s.pdf
aquastore223
 
The molecular orbital (MO) theory is a way of loo.pdf
                     The molecular orbital (MO) theory is a way of loo.pdf                     The molecular orbital (MO) theory is a way of loo.pdf
The molecular orbital (MO) theory is a way of loo.pdf
aquastore223
 
Unfortunately several cancers are not predictable with simple tests .pdf
Unfortunately several cancers are not predictable with simple tests .pdfUnfortunately several cancers are not predictable with simple tests .pdf
Unfortunately several cancers are not predictable with simple tests .pdf
aquastore223
 
The van t Hoff factor i (named after J. H. van t Hoff) is a meas.pdf
The van t Hoff factor i (named after J. H. van t Hoff) is a meas.pdfThe van t Hoff factor i (named after J. H. van t Hoff) is a meas.pdf
The van t Hoff factor i (named after J. H. van t Hoff) is a meas.pdf
aquastore223
 
Polar Bonds and Molecular Shape A polar molecule.pdf
                     Polar Bonds and Molecular Shape  A polar molecule.pdf                     Polar Bonds and Molecular Shape  A polar molecule.pdf
Polar Bonds and Molecular Shape A polar molecule.pdf
aquastore223
 
The good functioning of an economy depends on the proper functioning.pdf
The good functioning of an economy depends on the proper functioning.pdfThe good functioning of an economy depends on the proper functioning.pdf
The good functioning of an economy depends on the proper functioning.pdf
aquastore223
 
Stegosaurus dinosaur belonged to the late jurassic period i.e Kimmer.pdf
Stegosaurus dinosaur belonged to the late jurassic period i.e Kimmer.pdfStegosaurus dinosaur belonged to the late jurassic period i.e Kimmer.pdf
Stegosaurus dinosaur belonged to the late jurassic period i.e Kimmer.pdf
aquastore223
 

More from aquastore223 (20)

1. How new modern materials prompted changes in architecture in the .pdf
1. How new modern materials prompted changes in architecture in the .pdf1. How new modern materials prompted changes in architecture in the .pdf
1. How new modern materials prompted changes in architecture in the .pdf
 
c++ code for a Median of Integer Stream from Text File program#.pdf
 c++ code for a Median of Integer Stream from Text File program#.pdf c++ code for a Median of Integer Stream from Text File program#.pdf
c++ code for a Median of Integer Stream from Text File program#.pdf
 
1) cobalt iodide has an intense color, thus this colorless salt cann.pdf
1) cobalt iodide has an intense color, thus this colorless salt cann.pdf1) cobalt iodide has an intense color, thus this colorless salt cann.pdf
1) cobalt iodide has an intense color, thus this colorless salt cann.pdf
 
the hybridisation is sp2 since the electron cloud.pdf
                     the hybridisation is sp2 since the electron cloud.pdf                     the hybridisation is sp2 since the electron cloud.pdf
the hybridisation is sp2 since the electron cloud.pdf
 
Sodium hydroxide, also known as lye and caustic s.pdf
                     Sodium hydroxide, also known as lye and caustic s.pdf                     Sodium hydroxide, also known as lye and caustic s.pdf
Sodium hydroxide, also known as lye and caustic s.pdf
 
Hydrocrbon is the organic compound which containing only the atoms .pdf
   Hydrocrbon is the organic compound which containing only the atoms .pdf   Hydrocrbon is the organic compound which containing only the atoms .pdf
Hydrocrbon is the organic compound which containing only the atoms .pdf
 
No. In order for a substance to conduct electrici.pdf
                     No. In order for a substance to conduct electrici.pdf                     No. In order for a substance to conduct electrici.pdf
No. In order for a substance to conduct electrici.pdf
 
HCHO OS for H is +1, O is -2 there are two Hs o.pdf
                     HCHO OS for H is +1, O is -2 there are two Hs o.pdf                     HCHO OS for H is +1, O is -2 there are two Hs o.pdf
HCHO OS for H is +1, O is -2 there are two Hs o.pdf
 
The molecular orbital (MO) theory is a way of loo.pdf
                     The molecular orbital (MO) theory is a way of loo.pdf                     The molecular orbital (MO) theory is a way of loo.pdf
The molecular orbital (MO) theory is a way of loo.pdf
 
The electrons reach or give off a certain amount of energy and diffe.pdf
  The electrons reach or give off a certain amount of energy and diffe.pdf  The electrons reach or give off a certain amount of energy and diffe.pdf
The electrons reach or give off a certain amount of energy and diffe.pdf
 
Weak London disperision and dipole- dipoleModerate Hydrogen bond.pdf
Weak London disperision and dipole- dipoleModerate Hydrogen bond.pdfWeak London disperision and dipole- dipoleModerate Hydrogen bond.pdf
Weak London disperision and dipole- dipoleModerate Hydrogen bond.pdf
 
var min =0; var max=10; var tab = {}; var name; var score;.pdf
var min =0; var max=10; var tab = {}; var name; var score;.pdfvar min =0; var max=10; var tab = {}; var name; var score;.pdf
var min =0; var max=10; var tab = {}; var name; var score;.pdf
 
Unfortunately several cancers are not predictable with simple tests .pdf
Unfortunately several cancers are not predictable with simple tests .pdfUnfortunately several cancers are not predictable with simple tests .pdf
Unfortunately several cancers are not predictable with simple tests .pdf
 
The van t Hoff factor i (named after J. H. van t Hoff) is a meas.pdf
The van t Hoff factor i (named after J. H. van t Hoff) is a meas.pdfThe van t Hoff factor i (named after J. H. van t Hoff) is a meas.pdf
The van t Hoff factor i (named after J. H. van t Hoff) is a meas.pdf
 
Polar Bonds and Molecular Shape A polar molecule.pdf
                     Polar Bonds and Molecular Shape  A polar molecule.pdf                     Polar Bonds and Molecular Shape  A polar molecule.pdf
Polar Bonds and Molecular Shape A polar molecule.pdf
 
The good functioning of an economy depends on the proper functioning.pdf
The good functioning of an economy depends on the proper functioning.pdfThe good functioning of an economy depends on the proper functioning.pdf
The good functioning of an economy depends on the proper functioning.pdf
 
The answer is Yes, it is a reduction-oxidation reaction2 HNO2 + 2.pdf
The answer is Yes, it is a reduction-oxidation reaction2 HNO2 + 2.pdfThe answer is Yes, it is a reduction-oxidation reaction2 HNO2 + 2.pdf
The answer is Yes, it is a reduction-oxidation reaction2 HNO2 + 2.pdf
 
Stegosaurus dinosaur belonged to the late jurassic period i.e Kimmer.pdf
Stegosaurus dinosaur belonged to the late jurassic period i.e Kimmer.pdfStegosaurus dinosaur belonged to the late jurassic period i.e Kimmer.pdf
Stegosaurus dinosaur belonged to the late jurassic period i.e Kimmer.pdf
 
The answer is d- the hydrogen bonds in iceThe high heat of fusion.pdf
The answer is d- the hydrogen bonds in iceThe high heat of fusion.pdfThe answer is d- the hydrogen bonds in iceThe high heat of fusion.pdf
The answer is d- the hydrogen bonds in iceThe high heat of fusion.pdf
 
SolutionOption (a) will qualify as a database as dictionary is a .pdf
SolutionOption (a) will qualify as a database as dictionary is a .pdfSolutionOption (a) will qualify as a database as dictionary is a .pdf
SolutionOption (a) will qualify as a database as dictionary is a .pdf
 

Recently uploaded

Contoh Aksi Nyata Refleksi Diri ( NUR ).pdf
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdfContoh Aksi Nyata Refleksi Diri ( NUR ).pdf
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdf
cupulin
 
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MysoreMuleSoftMeetup
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
EADTU
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
中 央社
 

Recently uploaded (20)

Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...
 
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdf
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdfContoh Aksi Nyata Refleksi Diri ( NUR ).pdf
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdf
 
Improved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppImproved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio App
 
PSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxPSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptx
 
VAMOS CUIDAR DO NOSSO PLANETA! .
VAMOS CUIDAR DO NOSSO PLANETA!                    .VAMOS CUIDAR DO NOSSO PLANETA!                    .
VAMOS CUIDAR DO NOSSO PLANETA! .
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptx
 
UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024
 
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMDEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.ppt
 
Including Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdfIncluding Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdf
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....
 
Supporting Newcomer Multilingual Learners
Supporting Newcomer  Multilingual LearnersSupporting Newcomer  Multilingual Learners
Supporting Newcomer Multilingual Learners
 
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
 
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
 
Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
 
How to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxHow to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptx
 

import java.util.LinkedList; import java.util.Random; import jav.pdf

  • 1. import java.util.LinkedList; import java.util.Random; import java.util.Scanner; /** * author * */ public class LinkedListTest { /** * param args */ public static void main(String[] args) { int M, N, Lower, Upper; Scanner scanner = null; try { LinkedList list1 = new LinkedList(); LinkedList list2 = new LinkedList(); LinkedList list3 = new LinkedList(); Random random = new Random(); scanner = new Scanner(System.in); System.out.print("Enter the Lower and Upper bounds:"); Lower = scanner.nextInt(); Upper = scanner.nextInt(); System.out.print("Enter the N value to Insert list1:"); N = scanner.nextInt(); System.out.print("Enter the M value to Insert list2:"); M = scanner.nextInt(); for (int i = 1; i <= N; i++) { list1.add(random.nextInt((Upper - Lower) + 1) + Lower); } for (int i = 1; i <= M; i++) { list2.add(random.nextInt((Upper - Lower) + 1) + Lower); } System.out.println("list1: " + list1); System.out.println("list2: " + list2);
  • 2. System.out.println("Minimum elelment in list1 :" + getMin(list1)); System.out.println("Minimum elelment in list2 :" + getMin(list2)); System.out .println("Count Divisibles by 3 and 5 elelment in list1 :" + countDivisibles(list1)); System.out .println("Count Divisibles by 3 and 5 elelment in list2 :" + countDivisibles(list2)); System.out.println("Common Elements From list1 and list2:" + getCommonList(list1, list2)); } catch (Exception e) { // TODO: handle exception } } /** * param list * return */ public static int getMin(LinkedList list) { int min = list.get(0); for (Integer integer : list) { if (min > integer) { min = integer; } } return min; } /** * param list * return */ public static int countDivisibles(LinkedList list) { int count = 0; for (Integer integer : list) { if (integer % 3 == 0 && integer % 5 == 0) { count++;
  • 3. } } return count; } /** * param list1 * param list2 * return */ public static LinkedList getCommonList(LinkedList list1, LinkedList list2) { LinkedList list = new LinkedList(); LinkedList listCommon = new LinkedList(); list = (list1.size() > list2.size()) ? list1 : list2; for (int i = 0; i < list.size(); i++) { Integer number = list.get(i); if (list2.contains(number) && list1.contains(number)) { listCommon.add(number); } } return listCommon; } } OUTPUT: Enter the Lower and Upper bounds:1 10 Enter the N value to Insert list1:10 Enter the M value to Insert list2:20 list1: [1, 4, 4, 6, 9, 4, 9, 5, 8, 5] list2: [5, 10, 10, 2, 1, 10, 8, 8, 8, 2, 6, 10, 6, 2, 5, 9, 6, 9, 6, 2] Minimum elelment in list1 :1 Minimum elelment in list2 :1 Count Divisibles by 3 and 5 elelment in list1 :0 Count Divisibles by 3 and 5 elelment in list2 :0 Common Elements From list1 and list2:[5, 1, 8, 8, 8, 6, 6, 5, 9, 6, 9, 6] Solution
  • 4. import java.util.LinkedList; import java.util.Random; import java.util.Scanner; /** * author * */ public class LinkedListTest { /** * param args */ public static void main(String[] args) { int M, N, Lower, Upper; Scanner scanner = null; try { LinkedList list1 = new LinkedList(); LinkedList list2 = new LinkedList(); LinkedList list3 = new LinkedList(); Random random = new Random(); scanner = new Scanner(System.in); System.out.print("Enter the Lower and Upper bounds:"); Lower = scanner.nextInt(); Upper = scanner.nextInt(); System.out.print("Enter the N value to Insert list1:"); N = scanner.nextInt(); System.out.print("Enter the M value to Insert list2:"); M = scanner.nextInt(); for (int i = 1; i <= N; i++) { list1.add(random.nextInt((Upper - Lower) + 1) + Lower); } for (int i = 1; i <= M; i++) { list2.add(random.nextInt((Upper - Lower) + 1) + Lower); } System.out.println("list1: " + list1); System.out.println("list2: " + list2);
  • 5. System.out.println("Minimum elelment in list1 :" + getMin(list1)); System.out.println("Minimum elelment in list2 :" + getMin(list2)); System.out .println("Count Divisibles by 3 and 5 elelment in list1 :" + countDivisibles(list1)); System.out .println("Count Divisibles by 3 and 5 elelment in list2 :" + countDivisibles(list2)); System.out.println("Common Elements From list1 and list2:" + getCommonList(list1, list2)); } catch (Exception e) { // TODO: handle exception } } /** * param list * return */ public static int getMin(LinkedList list) { int min = list.get(0); for (Integer integer : list) { if (min > integer) { min = integer; } } return min; } /** * param list * return */ public static int countDivisibles(LinkedList list) { int count = 0; for (Integer integer : list) { if (integer % 3 == 0 && integer % 5 == 0) { count++;
  • 6. } } return count; } /** * param list1 * param list2 * return */ public static LinkedList getCommonList(LinkedList list1, LinkedList list2) { LinkedList list = new LinkedList(); LinkedList listCommon = new LinkedList(); list = (list1.size() > list2.size()) ? list1 : list2; for (int i = 0; i < list.size(); i++) { Integer number = list.get(i); if (list2.contains(number) && list1.contains(number)) { listCommon.add(number); } } return listCommon; } } OUTPUT: Enter the Lower and Upper bounds:1 10 Enter the N value to Insert list1:10 Enter the M value to Insert list2:20 list1: [1, 4, 4, 6, 9, 4, 9, 5, 8, 5] list2: [5, 10, 10, 2, 1, 10, 8, 8, 8, 2, 6, 10, 6, 2, 5, 9, 6, 9, 6, 2] Minimum elelment in list1 :1 Minimum elelment in list2 :1 Count Divisibles by 3 and 5 elelment in list1 :0 Count Divisibles by 3 and 5 elelment in list2 :0 Common Elements From list1 and list2:[5, 1, 8, 8, 8, 6, 6, 5, 9, 6, 9, 6]