JAVA ASSIGNMENT
1.Write a program that accept string as command line argument and generate the output in
specific way Example if two command line argument are wipro and bangolre then the ouput
generated should be Wipro technology Banglore. If the argument are ABC and Mumbai then
output should be ABC technology Mumbai.
SOL: package ASSIGN3;
import java.util.Scanner;
public class QUESTION1 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
if (args.length < 2) {
System.out.println("Please provide two command line arguments.");
} else {
String output = args[0] + " technology " + args[1];
System.out.println("Output: " + output);
sc.close();
OUTPUT: Output: Wipro technology Bangalore
2.Write a function that takes three argument from user and return their greater number out
of them to the calling program.
SOL: package ASSIGN3;
import java.util.Scanner;
public class QUESTION2 {
public static int findGreatest(int a, int b, int c) {
return (a > b && a > c) ? a : (b > c ? b : c);
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter first number: ");
int x = sc.nextInt();
System.out.print("Enter second number: ");
int y = sc.nextInt();
System.out.print("Enter third number: ");
int z = sc.nextInt();
int result = findGreatest(x, y, z);
System.out.println("Greatest number is: " + result);
sc.close();
OUTPUT: Enter first number: 25
Enter second number: 52
Enter third number: 45
Greatest number is: 52
3.Check if string contains valid number example.
SOL: package ASSIGN3;
import java.util.Scanner;
public class QUESTION3 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter a string: ");
String input = sc.nextLine();
try {
Double.parseDouble(input);
System.out.println("Valid number.");
} catch (NumberFormatException e) {
System.out.println("Invalid number.");
sc.close();
OUTPUT: Enter a string: 1111
Valid number.
4.Convert Java String Object to Boolean Object.
SOL: package ASSIGN3;
import java.util.Scanner;
public class QUESTION4 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter true or false: ");
String input = sc.nextLine();
Boolean bool = Boolean.valueOf(input);
System.out.println("Converted Boolean: " + bool);
sc.close();
OUTPUT: Enter true or false: TRUE
Converted Boolean: true
5.Find maximum of two numbers using Math.max
SOL: package ASSIGN3;
import java.util.Scanner;
public class QUESTION5 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter first number: ");
int a = sc.nextInt();
System.out.print("Enter second number: ");
int b = sc.nextInt();
int max = Math.max(a, b);
System.out.println("Maximum is: " + max);
sc.close();
OUTPUT: Enter first number: 10
Enter second number: 11
Maximum is: 11
6.Create a class student1 which has fields name, age, marks . Initialize the variable using
parameterized constructor. Print all the data of a student inside show method of class record
student using message passing. Call show method is main.
SOL: package ASSIGN3;
import java.util.Scanner;
class student1 {
String name;
int age;
double marks;
student1(String name, int age, double marks) {
this.name = name;
this.age = age;
this.marks = marks;
}
class recordstudent {
void show(student1 s) {
System.out.println("Name: " + s.name);
System.out.println("Age: " + s.age);
System.out.println("Marks: " + s.marks);
public class QUESTION6 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter name: ");
String name = sc.nextLine();
System.out.print("Enter age: ");
int age = sc.nextInt();
System.out.print("Enter marks: ");
double marks = sc.nextDouble();
student1 s = new student1(name, age, marks);
recordstudent rs = new recordstudent();
rs.show(s);
sc.close();
OUTPUT: Enter name: VIRAT
Enter age: 35
Enter marks: 75
Name: VIRAT
Age: 35
Marks: 75.0
7.Demonstrate singleton class.
SOL: package ASSIGN3;
class Singleton {
private static Singleton instance;
private Singleton() {
System.out.println("Singleton class created.");
public static Singleton getInstance() {
if (instance == null) {
instance = new Singleton();
return instance;
public void showMessage() {
System.out.println("Hello from Singleton class!");
public class QUESTION7 {
public static void main(String[] args) {
Singleton s1 = Singleton.getInstance();
Singleton s2 = Singleton.getInstance();
System.out.println("Are both classes same? " + (s1 == s2));
s1.showMessage();
OUTPUT: Singleton class created.
Are both classes same? true
Hello from Singleton class!
8. Write a program to display all the prime numbers from 1 to 20.
SOL: package ASSIGN3;
import java.util.Scanner;
public class QUESTION8 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Prime numbers between 1 and 20:");
for (int i = 2; i <= 20; i++) {
boolean prime = true;
for (int j = 2; j <= i / 2; j++) {
if (i % j == 0) {
prime = false;
break;
if (prime)
System.out.print(i + " ");
}
sc.close();
OUTPUT: Prime numbers between 1 and 20:
2 3 5 7 11 13 17 19
9. Kiwi Inc. is a leading software development company in the US. The top management of
the organization has found that the Help Desk division does not handle queries or issues of
the employees on a priority basis. For this, the top management has decided to automate
the tasks of the Help Desk division. Therefore, the management has assigned this task to the
development team to create an application that has the following functionalities:
Application must enable employees to log their requests or issues. Application must enable
the team of the Help Desk division to handle queries on the first come first served basis. The
development team has assigned the task to John, the Senior Software Developer. However,
in the initial phase of development, John needs to create the user interface and create the
application only for a single user. Help John to achieve the preceding requirement.
SOL: package ASSIGN3;
import java.util.Scanner;
class HelpDesk {
String[] requests = new String[5];
int front = 0, rear = 0;
public void logRequest(String request) {
if (rear < requests.length) {
requests[rear] = request;
rear++;
System.out.println("Request logged successfully.");
} else {
System.out.println("Request queue is full. Please process existing requests.");
}
}
public void processRequest() {
if (front < rear) {
System.out.println("Processing request: " + requests[front]);
front++;
} else {
System.out.println("No requests to process.");
public class QUESTION10 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
HelpDesk helpDesk = new HelpDesk();
System.out.println("Welcome to Kiwi Inc.");
while (true) {
System.out.println("\nChoose an option:");
System.out.println("1. Log a new request");
System.out.println("2. Process next request");
System.out.println("3. Exit");
System.out.print("Your choice: ");
int choice = sc.nextInt();
sc.nextLine();
switch (choice) {
case 1:
System.out.print("Enter your request: ");
String req = sc.nextLine();
helpDesk.logRequest(req);
break;
case 2:
helpDesk.processRequest();
break;
case 3:
System.out.println("Exiting Help Desk. Goodbye!");
return;
default:
System.out.println("Invalid choice. Try again.");
OUTPUT: Welcome to Kiwi Inc.
Choose an option:
1. Log a new request
2. Process next request
3. Exit
Your choice: 1
Enter your request: ASSIGNMENT
Request logged successfully.
Choose an option:
1. Log a new request
2. Process next request
3. Exit
Your choice: