[Go to site: main page, start]

0% found this document useful (0 votes)
2 views3 pages

Java Lab Solutions

I would like to avail my LADP (Liquid & Accidental Damage Protection) coverage for the keyboard replacement. Kindly process my repair request under the LADP policy instead of the paid quotation.

Uploaded by

kaustubh250306
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
0% found this document useful (0 votes)
2 views3 pages

Java Lab Solutions

I would like to avail my LADP (Liquid & Accidental Damage Protection) coverage for the keyboard replacement. Kindly process my repair request under the LADP policy instead of the paid quotation.

Uploaded by

kaustubh250306
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

Java Programming Lab Solutions

Q1. Group Anagrams

import [Link].*;

class AnagramGrouper {

public static List<List<String>> groupAnagrams(String[] words) {

Map<String, List<String>> map = new HashMap<>();

for (String word : words) {

char[] chars = [Link]();


[Link](chars);

String key = new String(chars);

if (![Link](key)) {
[Link](key, new ArrayList<>());
}

[Link](key).add(word);
}

List<List<String>> result = new ArrayList<>([Link]());

for (List<String> group : result) {


[Link](group);
}

[Link](result,
(a, b) -> [Link](0).compareTo([Link](0)));

return result;
}
}

public class Main {

public static void main(String[] args) {

Scanner scanner = new Scanner([Link]);

int N = [Link]();

String[] words = new String[N];

for (int i = 0; i < N; i++) {


words[i] = [Link]();
}

List<List<String>> result =
[Link](words);

for (List<String> group : result) {

for (int i = 0; i < [Link](); i++) {

if (i > 0) {
[Link](" ");
}

[Link]([Link](i));
}

[Link]();
}

[Link]();
}
}

====================================================

Q2. Task Sorting using Comparable

import [Link].*;
import [Link].*;

class Task implements Comparable<Task> {

String name;
Date deadline;
int priority;

private static final SimpleDateFormat dateFormat =


new SimpleDateFormat("yyyy-MM-dd");

public Task(String name, String deadline, int priority) {

[Link] = name;
[Link] =
[Link](deadline, new ParsePosition(0));
[Link] = priority;
}

public int compareTo(Task other) {

int dateComparison =
[Link]([Link]);

if (dateComparison != 0) {
return dateComparison;
}

return [Link]([Link], [Link]);


}

public String toString() {

return name + " " +


[Link](deadline) +
" " + priority;
}
}

====================================================

Q3. Count Rotations using ArrayList

import [Link].*;

class RotationCounter {

public int countRotations(ArrayList<Integer> arr) {

int low = 0;
int high = [Link]() - 1;

int n = [Link]();

while (low <= high) {

if ([Link](low) <= [Link](high)) {


return low;
}

int mid = (low + high) / 2;

int next = (mid + 1) % n;


int prev = (mid + n - 1) % n;

if ([Link](mid) <= [Link](next)


&& [Link](mid) <= [Link](prev)) {

return mid;
}

if ([Link](mid) <= [Link](high)) {

high = mid - 1;

} else if ([Link](mid) >= [Link](low)) {

low = mid + 1;
}
}
return -1;
}
}

====================================================

Q4. JDBC Inventory Management System

Contains:
- Add Item
- Restock Item
- Reduce Stock
- Display Inventory
- JDBC MySQL Connection

====================================================

Q5. JDBC School Management System

Contains:
- Add Student
- Update GPA
- Display Students
- JDBC MySQL Connection

You might also like