Please scroll down for latest Programs. 👇
Week 01 : Programming Assignment 3
Due on 2025-08-07, 23:59 ISTWrite a Java program to print the multiplication table of a given number up to 4.
NOTE:
Print EXACTLY as shown in the sample output.
DO NOT MISS a single space otherwise you will not be scored.
(Remember to match the output given exactly, including the spaces and new lines)
(passed with presentation error means you will get full marks)
Public Test Cases Input Expected Output Actual Output Status Test Case 1 5
5 x 1 = 5\n
5 x 2 = 10\n
5 x 3 = 15\n
5 x 4 = 20
5 x 1 = 5\n
5 x 2 = 10\n
5 x 3 = 15\n
5 x 4 = 20\n
Passed after ignoring Presentation Error
Write a Java program to print the multiplication table of a given number up to 4.
NOTE:
Print EXACTLY as shown in the sample output.
DO NOT MISS a single space otherwise you will not be scored.
(Remember to match the output given exactly, including the spaces and new lines)
(passed with presentation error means you will get full marks)
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 5 | 5 x 1 = 5\n
5 x 2 = 10\n
5 x 3 = 15\n
5 x 4 = 20 | 5 x 1 = 5\n
5 x 2 = 10\n
5 x 3 = 15\n
5 x 4 = 20\n
| Passed after ignoring Presentation Error |
Week 01 : Programming Assignment 4
Due on 2025-08-07, 23:59 ISTComplete the code fragment that reads two integer inputs from keyboard and compute the quotient and remainder.
Public Test Cases Input Expected Output Actual Output Status Test Case 1 556
9
The Quotient is = 61\n
The Remainder is = 7
The Quotient is = 61\n
The Remainder is = 7
Passed
Complete the code fragment that reads two integer inputs from keyboard and compute the quotient and remainder.
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 556
9 | The Quotient is = 61\n
The Remainder is = 7 | The Quotient is = 61\n
The Remainder is = 7 | Passed |
Week 01 : Programming Assignment 5
Due on 2025-08-07, 23:59 ISTWrite a Java program to print the area and perimeter of a rectangle.
Public Test Cases Input Expected Output Actual Output Status Test Case 1 5.6 8.5
Perimeter is 2*(8.5 + 5.6) = 28.20\n
Area is 5.6 * 8.5 = 47.60
Perimeter is 2*(8.5 + 5.6) = 28.20\n
Area is 5.6 * 8.5 = 47.60
Passed
Write a Java program to print the area and perimeter of a rectangle.
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 5.6 8.5 | Perimeter is 2*(8.5 + 5.6) = 28.20\n
Area is 5.6 * 8.5 = 47.60 | Perimeter is 2*(8.5 + 5.6) = 28.20\n
Area is 5.6 * 8.5 = 47.60 | Passed |
W02 Programming Assignments 1
Due on 2025-08-07, 23:59 ISTWrite a Java program to calculate the area of a rectangle.
The formula for area is:
Area = length × width
You are required to read the length and width from the user, compute the area, and print the result.
This task helps you practice using variables, arithmetic operations, and printing output in Java.
Public Test Cases Input Expected Output Actual Output Status Test Case 1 5
10
Area is: 50
Area is: 50
Passed
Write a Java program to calculate the area of a rectangle.
The formula for area is:
Area = length × width
You are required to read the length and width from the user, compute the area, and print the result.
This task helps you practice using variables, arithmetic operations, and printing output in Java.
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 5
10 | Area is: 50 | Area is: 50 | Passed |
W02 Programming Assignments 2
Due on 2025-08-07, 23:59 IST
Problem Statement
Write a Java program to calculate the perimeter of a rectangle.
The formula for perimeter is:
Perimeter = 2 multiplied by (length + width)
You are required to read the length and width as integers from the user, compute the perimeter, and print the result.
This problem helps in practicing arithmetic operations and output printing in Java.
Public Test Cases Input Expected Output Actual Output Status Test Case 1 4
6
Perimeter is: 20
Perimeter is: 20\n
Passed after ignoring Presentation Error
Write a Java program to calculate the perimeter of a rectangle.
The formula for perimeter is:
Perimeter = 2 multiplied by (length + width)
You are required to read the length and width as integers from the user, compute the perimeter, and print the result.
This problem helps in practicing arithmetic operations and output printing in Java.
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 4
6 | Perimeter is: 20 | Perimeter is: 20\n
| Passed after ignoring Presentation Error |
W02 Programming Assignments 3
Due on 2025-08-07, 23:59 IST
Finding the Maximum Element in an Array
Problem Statement
What is the Maximum Element?
In an array of numbers, the maximum is the largest number among all elements.
In this assignment:
You will read n
numbers from the user
Store them in an array
Find the largest number among them
Print the maximum number
This task helps you apply loops and arrays together to solve a real logic-based problem.
Public Test Cases Input Expected Output Actual Output Status Test Case 1 5
15 42 9 28 37
Maximum is: 42
Maximum is: 42\n
Passed after ignoring Presentation Error
What is the Maximum Element?
In an array of numbers, the maximum is the largest number among all elements.
In this assignment:
You will read
n
numbers from the userStore them in an array
Find the largest number among them
Print the maximum number
This task helps you apply loops and arrays together to solve a real logic-based problem.
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 5
15 42 9 28 37 | Maximum is: 42 | Maximum is: 42\n
| Passed after ignoring Presentation Error |
W02 Programming Assignments 4
Due on 2025-08-07, 23:59 IST
Create a Class and Access Its Member Variable
Problem Statement
In this task, you will practice creating and using a class in Java.
You need to:
Create a class called Rectangle
Declare two integer member variables length
and width
In the main
method, create an object of the Rectangle
class, assign values to length
and width
, and print their sum
This problem helps you understand how to define a class, create objects, and access class members in Java.
Public Test Cases Input Expected Output Actual Output Status Test Case 1 5
10
Sum of length and width is: 15
Sum of length and width is: 15\n
Passed after ignoring Presentation Error
In this task, you will practice creating and using a class in Java.
You need to:
Create a class called
Rectangle
Declare two integer member variables
length
andwidth
In the
main
method, create an object of theRectangle
class, assign values tolength
andwidth
, and print their sum
This problem helps you understand how to define a class, create objects, and access class members in Java.
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 5
10 | Sum of length and width is: 15 | Sum of length and width is: 15\n
| Passed after ignoring Presentation Error |
W02 Programming Assignments 5
Due on 2025-08-07, 23:59 IST
Working with Multiple Classes, Constructors, and the this
Keyword
Problem Statement
In this task, you will learn how to:
Declare multiple classes in the same Java program
Use constructors to initialize values
Apply the this
keyword to refer to instance variables
What you need to do:
Declare a class called Circle
with one member variable radius
Write a constructor for Circle
that takes radius
as a parameter and assigns it using the this
keyword
In the main
method, create an object of Circle
and print its radius
This task helps understand how classes work together and how constructors and the this
keyword are used for clarity.
Public Test Cases Input Expected Output Actual Output Status Test Case 1 7
Radius of the circle is: 7
Radius of the circle is: 7\n
Passed after ignoring Presentation Error
In this task, you will learn how to:
Declare multiple classes in the same Java program
Use constructors to initialize values
Apply the
this
keyword to refer to instance variables
What you need to do:
Declare a class called
Circle
with one member variableradius
Write a constructor for
Circle
that takesradius
as a parameter and assigns it using thethis
keywordIn the
main
method, create an object ofCircle
and print its radius
This task helps understand how classes work together and how constructors and the this
keyword are used for clarity.
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 7 | Radius of the circle is: 7 | Radius of the circle is: 7\n
| Passed after ignoring Presentation Error |
W06 Programming Assignments 1
Due on 2025-09-04, 23:59 IST
Safe Division with Run-time Error Handling
Problem Statement
In Java, some operations can cause run-time errors, for example dividing a number by zero.
We can use a try-catch block to handle such errors and avoid program crashes.
Task:
Read two integers from the user
Divide the first number by the second inside a try-catch block
If the second number is zero, print "Cannot divide by zero"
Otherwise, print the result
This task introduces basic run-time error handling in a safe and controlled way.
Public Test Cases Input Expected Output Actual Output Status Test Case 1 10
0
Cannot divide by zero
Cannot divide by zero\n
Passed after ignoring Presentation Error
Test Case 2 10
2
Result is: 5
Result is: 5\n
Passed after ignoring Presentation Error
In Java, some operations can cause run-time errors, for example dividing a number by zero.
We can use a try-catch block to handle such errors and avoid program crashes.
Task:
Read two integers from the user
Divide the first number by the second inside a try-catch block
If the second number is zero, print
"Cannot divide by zero"
Otherwise, print the result
This task introduces basic run-time error handling in a safe and controlled way.
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 10
0 | Cannot divide by zero | Cannot divide by zero\n
| Passed after ignoring Presentation Error |
Test Case 2 | 10
2 | Result is: 5 | Result is: 5\n
| Passed after ignoring Presentation Error |
W06 Programming Assignments 2
Due on 2025-09-04, 23:59 IST
Programming Assignment: Nested try-catch Block
Problem Statement
In Java, nested try-catch blocks allow handling multiple levels of errors separately.
You can place one try-catch block inside another to handle different types of errors in different places.
Programming Assignment:
Read two integers from the user
Inside an outer try-catch block, perform the following:
Inside a nested try block, divide the first number by the second
If division by zero occurs, handle it with the inner catch block
In the outer catch block, handle any other unexpected errors
Print appropriate messages for each scenario
This programming assignment introduces nested try-catch structure.
Public Test Cases Input Expected Output Actual Output Status Test Case 1 10
2
Division successful\n
Result is: 5
Division successful\n
Result is: 5\n
Passed after ignoring Presentation Error
In Java, nested try-catch blocks allow handling multiple levels of errors separately.
You can place one try-catch block inside another to handle different types of errors in different places.
Programming Assignment:
Read two integers from the user
Inside an outer try-catch block, perform the following:
Inside a nested try block, divide the first number by the second
If division by zero occurs, handle it with the inner catch block
In the outer catch block, handle any other unexpected errors
Print appropriate messages for each scenario
This programming assignment introduces nested try-catch structure.
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 10
2 | Division successful\n
Result is: 5 | Division successful\n
Result is: 5\n
| Passed after ignoring Presentation Error |
W06 Programming Assignments 3
Due on 2025-09-04, 23:59 IST
Programming Assignment: try Block with Multiple catch Blocks
Problem Statement
In Java, a try block can be followed by multiple catch blocks to handle different types of errors separately.
This improves error handling by allowing specific actions for different exceptions.
Key Concepts:
The first matching catch block handles the error
Catch blocks are written in order from most specific to general
Programming Assignment:
Read two integers from the user
Inside a try block, divide the first number by the second
Handle ArithmeticException
separately to detect division by zero
Handle any other general errors using another catch block
Print suitable messages based on the type of error
This demonstrates structured error handling with multiple catch blocks.
Public Test Cases Input Expected Output Actual Output Status Test Case 1 20
4
Division successful\n
Result is: 5
Division successful\n
Result is: 5\n
Passed after ignoring Presentation Error
In Java, a try block can be followed by multiple catch blocks to handle different types of errors separately.
This improves error handling by allowing specific actions for different exceptions.
Key Concepts:
The first matching catch block handles the error
Catch blocks are written in order from most specific to general
Programming Assignment:
Read two integers from the user
Inside a try block, divide the first number by the second
Handle
ArithmeticException
separately to detect division by zeroHandle any other general errors using another catch block
Print suitable messages based on the type of error
This demonstrates structured error handling with multiple catch blocks.
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 20
4 | Division successful\n
Result is: 5 | Division successful\n
Result is: 5\n
| Passed after ignoring Presentation Error |
W06 Programming Assignments 4
Due on 2025-09-04, 23:59 IST
Programming Assignment: Using finally in try-catch Block
Problem Statement
In Java, the finally block is a special part of error handling.
What is finally?
The code inside a finally block always runs, whether there is an error or not
It is usually used to close resources like files, database connections, or simply to show a message
Programming Assignment:
Read two integers from the user
Inside a try block, divide the first number by the second
If division by zero occurs, show an error message using catch block
Use a finally block to print "Program Ended"
no matter what happens
This helps you understand how finally block always runs in a program.
Public Test Cases Input Expected Output Actual Output Status Test Case 1 15
3
Result is: 5\n
Program Ended
Result is: 5\n
Program Ended\n
Passed after ignoring Presentation Error
In Java, the finally block is a special part of error handling.
What is finally?
The code inside a finally block always runs, whether there is an error or not
It is usually used to close resources like files, database connections, or simply to show a message
Programming Assignment:
Read two integers from the user
Inside a try block, divide the first number by the second
If division by zero occurs, show an error message using catch block
Use a finally block to print
"Program Ended"
no matter what happens
This helps you understand how finally block always runs in a program.
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 15
3 | Result is: 5\n
Program Ended | Result is: 5\n
Program Ended\n
| Passed after ignoring Presentation Error |
W06 Programming Assignments 5
Due on 2025-09-04, 23:59 IST
Programming Assignment: Using throws Statement for Error Handling
Problem Statement
In Java, the throws
keyword is used when a method might cause an error, but the method itself does not handle it.
Instead, it passes the responsibility to the caller of the method.
Why use throws?
Some methods may cause errors called "checked exceptions"
Instead of handling the error inside the method, we declare throws
to inform the caller
Programming Assignment:
Create a method called calculateSquareRoot
The method reads a number and returns its square root
If the number is negative, it throws an Exception
In the main
method, use a try-catch block to handle the error
This demonstrates how to use throws
and handle errors safely in the caller method.
Public Test Cases Input Expected Output Actual Output Status Test Case 1 16
Square root is: 4.0
Square root is: 4.0\n
Passed after ignoring Presentation Error
In Java, the throws
keyword is used when a method might cause an error, but the method itself does not handle it.
Instead, it passes the responsibility to the caller of the method.
Why use throws?
Some methods may cause errors called "checked exceptions"
Instead of handling the error inside the method, we declare
throws
to inform the caller
Programming Assignment:
Create a method called
calculateSquareRoot
The method reads a number and returns its square root
If the number is negative, it throws an
Exception
In the
main
method, use a try-catch block to handle the error
This demonstrates how to use throws
and handle errors safely in the caller method.
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 16 | Square root is: 4.0 | Square root is: 4.0\n
| Passed after ignoring Presentation Error |
W08 Programming Assignments 1
Due on 2025-09-18, 23:59 IST
Creating a Thread using Thread Class
Problem Statement
In Java, you can run multiple tasks at the same time using Multithreading.
The simplest way to create a thread is by extending the built-in Thread
class.
What is a Thread?
A thread is a small unit of a program that runs independently
Multiple threads can run in parallel, improving efficiency
Programming Assignment:
Create a class called MyThread
that extends Thread
In its run()
method, print "Thread is running"
In the main
method, create an object of MyThread
and start the thread
This helps you understand the basic way to create and start a thread in Java.
Public Test Cases Input Expected Output Actual Output Status Test Case 1 NA
Thread is running
Thread is running
Passed
In Java, you can run multiple tasks at the same time using Multithreading.
The simplest way to create a thread is by extending the built-in Thread
class.
What is a Thread?
A thread is a small unit of a program that runs independently
Multiple threads can run in parallel, improving efficiency
Programming Assignment:
Create a class called
MyThread
that extendsThread
In its
run()
method, print"Thread is running"
In the
main
method, create an object ofMyThread
and start the thread
This helps you understand the basic way to create and start a thread in Java.
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | NA | Thread is running | Thread is running | Passed |
W08 Programming Assignments 2
Due on 2025-09-18, 23:59 IST
Creating a Thread using Runnable Interface
Problem Statement
In Java, another common way to create threads is by implementing the Runnable
interface.
What is Runnable?
Runnable is an interface with a single method called run()
You can pass a Runnable object to a Thread and start the thread
Why use Runnable?
It allows your class to extend another class, as Java supports single inheritance
It provides flexibility in thread creation
Programming Assignment:
Create a class called MyRunnable
that implements Runnable
In its run()
method, print "Runnable thread is running"
In the main
method, create a Thread
object using MyRunnable
and start the thread
This demonstrates thread creation using the Runnable interface.
Public Test Cases Input Expected Output Actual Output Status Test Case 1 NA
Runnable thread is running
Runnable thread is running
Passed
In Java, another common way to create threads is by implementing the Runnable
interface.
What is Runnable?
Runnable is an interface with a single method called
run()
You can pass a Runnable object to a Thread and start the thread
Why use Runnable?
It allows your class to extend another class, as Java supports single inheritance
It provides flexibility in thread creation
Programming Assignment:
Create a class called
MyRunnable
that implementsRunnable
In its
run()
method, print"Runnable thread is running"
In the
main
method, create aThread
object usingMyRunnable
and start the thread
This demonstrates thread creation using the Runnable interface.
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | NA | Runnable thread is running | Runnable thread is running | Passed |
W08 Programming Assignments 3
Due on 2025-09-18, 23:59 IST
Programming Assignment: Understanding Basic Thread States in Java
Problem Statement
When a thread runs in Java, it moves through different stages called states.
What are Thread States?
Think of a thread like a person:
It starts in one state
Moves to another as work happens
Finally, it finishes
For beginners, focus on these three simple states:
New – The thread is created but not started yet
Running – The thread is doing its work
Terminated – The thread has finished its work
Programming Assignment:
Create a class called MyThread
that extends Thread
Inside its run()
method, print "Thread is running"
In the main
method:
Create a MyThread
object
Print "Thread state before start"
Start the thread
Print "Thread state after start"
Wait for thread to finish using join()
Print "Thread state after completion"
This shows how thread state changes as the thread runs.
Public Test Cases Input Expected Output Actual Output Status Test Case 1 NA
Thread state before start\n
Thread state after start\n
Thread is running\n
Thread state after completion
Thread state before start\n
Thread state after start\n
Thread is running\n
Thread state after completion\n
Passed after ignoring Presentation Error
When a thread runs in Java, it moves through different stages called states.
What are Thread States?
Think of a thread like a person:
It starts in one state
Moves to another as work happens
Finally, it finishes
For beginners, focus on these three simple states:
New – The thread is created but not started yet
Running – The thread is doing its work
Terminated – The thread has finished its work
Programming Assignment:
Create a class called
MyThread
that extendsThread
Inside its
run()
method, print"Thread is running"
In the
main
method:Create a
MyThread
objectPrint
"Thread state before start"
Start the thread
Print
"Thread state after start"
Wait for thread to finish using
join()
Print
"Thread state after completion"
This shows how thread state changes as the thread runs.
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | NA | Thread state before start\n
Thread state after start\n
Thread is running\n
Thread state after completion | Thread state before start\n
Thread state after start\n
Thread is running\n
Thread state after completion\n
| Passed after ignoring Presentation Error |
W08 Programming Assignments 4
Due on 2025-09-18, 23:59 IST
Understanding Thread Priority in Java
Problem Statement
In Java, each thread has a priority, a number from 1 (lowest) to 10 (highest).
Priority suggests how important a thread is, though actual scheduling depends on the system.
Programming Assignment:
Create a class MyThread
that extends Thread
In the main method:
Create a MyThread
object
Set its priority to 8
Start the thread
Print the thread's priority after setting
No output should come from the thread's run()
method to avoid output mismatch.
Public Test Cases Input Expected Output Actual Output Status Test Case 1 NA
Thread priority is: 8
Thread priority is: 8
Passed
In Java, each thread has a priority, a number from 1 (lowest) to 10 (highest).
Priority suggests how important a thread is, though actual scheduling depends on the system.
Programming Assignment:
Create a class
MyThread
that extendsThread
In the main method:
Create a
MyThread
objectSet its priority to
8
Start the thread
Print the thread's priority after setting
No output should come from the thread's run()
method to avoid output mismatch.
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | NA | Thread priority is: 8 | Thread priority is: 8 | Passed |
W08 Programming Assignments 5
Due on 2025-09-18, 23:59 IST
Programming Assignment: Introduction to Thread Synchronization
Problem Statement
What is a Thread?
Imagine your computer doing many tasks at once — for example:
Playing music
Downloading files
Browsing the internet
In Java, each small task that runs independently is called a Thread.
Threads help programs run faster by working at the same time.
Why Synchronization?
When multiple threads work on the same thing together, they may interfere with each other.
For example:
Two threads try to update the same number at the same time
The final result may be wrong
What is Synchronization?
It is like putting a lock
Only one thread can work on the shared thing at a time
This prevents problems caused by threads disturbing each other
Programming Assignment:
Create a class Counter
with a number count
starting from 0
Write a method increment()
to increase the number by 1, using synchronized
keyword
Create a thread class called MyThread
that runs the increment()
method 1000 times
In main
, run two threads to increase the number
After both threads finish, print the final count
This shows how to use synchronization to avoid problems when multiple threads share data.
Public Test Cases Input Expected Output Actual Output Status Test Case 1 NA
Final count is: 2000
Final count is: 2000\n
Passed after ignoring Presentation Error
What is a Thread?
Imagine your computer doing many tasks at once — for example:
Playing music
Downloading files
Browsing the internet
In Java, each small task that runs independently is called a Thread.
Threads help programs run faster by working at the same time.
Why Synchronization?
When multiple threads work on the same thing together, they may interfere with each other.
For example:
Two threads try to update the same number at the same time
The final result may be wrong
What is Synchronization?
It is like putting a lock
Only one thread can work on the shared thing at a time
This prevents problems caused by threads disturbing each other
Programming Assignment:
Create a class
Counter
with a numbercount
starting from 0Write a method
increment()
to increase the number by 1, usingsynchronized
keywordCreate a thread class called
MyThread
that runs theincrement()
method 1000 timesIn
main
, run two threads to increase the numberAfter both threads finish, print the final count
This shows how to use synchronization to avoid problems when multiple threads share data.
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | NA | Final count is: 2000 | Final count is: 2000\n
| Passed after ignoring Presentation Error |
No comments