Please scroll down for latest Programs. 👇
Week 01 : Programming Assignment 1
Write a Java program to check if a given integer is “Positive” or “Negative”.
(0 (Zero) should be considered positive by this program.)
NOTE:
The code you see is not complete.
Your task is to complete the code as per the question.
Think of it like a programming puzzle.
(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 | 4 | Positive | Positive | Passed |
Test Case 2 | -3 | Negative | Negative | Passed |
Week 01 : Programming Assignment 2
Write a Java program to calculate the volume of a cylinder given its radius and height.
Formula:
You can use Math.PI for the computation.
NOTE:
The code you see is not complete.
Your task is to complete the code as per the question.
Think of it like a programming puzzle.
(This question can be solved in just one line of code)
| Public Test Cases | Input | Expected Output | Actual Output | Status |
|---|---|---|---|---|
Test Case 1 | 3.5
5.0 | Volume is: 192.42 | Volume is: 192.42 | Passed |
Week 01 : Programming Assignment 3
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
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
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
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
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 |
W02 Programming Assignments 3
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
nnumbers 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
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
RectangleDeclare two integer member variables
lengthandwidthIn the
mainmethod, create an object of theRectangleclass, assign values tolengthandwidth, 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
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
thiskeyword to refer to instance variables
What you need to do:
Declare a class called
Circlewith one member variableradiusWrite a constructor for
Circlethat takesradiusas a parameter and assigns it using thethiskeywordIn the
mainmethod, create an object ofCircleand 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
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 |
W06 Programming Assignments 2
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 |
W06 Programming Assignments 3
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
ArithmeticExceptionseparately 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
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 |
W06 Programming Assignments 5
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
throwsto inform the caller
Programming Assignment:
Create a method called
calculateSquareRootThe method reads a number and returns its square root
If the number is negative, it throws an
ExceptionIn the
mainmethod, 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
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
MyThreadthat extendsThreadIn its
run()method, print"Thread is running"In the
mainmethod, create an object ofMyThreadand 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
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
MyRunnablethat implementsRunnableIn its
run()method, print"Runnable thread is running"In the
mainmethod, create aThreadobject usingMyRunnableand 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
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
MyThreadthat extendsThreadInside its
run()method, print"Thread is running"In the
mainmethod:Create a
MyThreadobjectPrint
"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
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
MyThreadthat extendsThreadIn the main method:
Create a
MyThreadobjectSet its priority to
8Start 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
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
Counterwith a numbercountstarting from 0Write a method
increment()to increase the number by 1, usingsynchronizedkeywordCreate a thread class called
MyThreadthat 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 |
Week 09 : Programming Assignment 1
Write suitable code to develop a 2D Flip-Flop Array with dimension 5 × 5, which replaces all input elements with values 0 by 1 and 1 by 0. An example is shown below:
INPUT:
00001
00001
00001
00001
00001
OUTPUT:
11110
11110
11110
11110
11110
Note the following points carefully:
1. Here, the input must contain only 0 and 1.
2. The input and output array size must be of dimension 5 × 5.
3. Flip-Flop: If 0 then 1 and vice-versa.
| Public Test Cases | Input | Expected Output | Actual Output | Status |
|---|---|---|---|---|
Test Case 1 | 00001
00001
00001
00001
00001 | 11110\n
11110\n
11110\n
11110\n
11110 | 11110\n
11110\n
11110\n
11110\n
11110\n
| Passed after ignoring Presentation Error |
Week 09 : Programming Assignment 2
Complete the code to develop a BASIC CALCULATOR that can perform operations like Addition, Subtraction, Multiplication and Division.
Note the following points carefully:
1. Use only double datatype to store calculated numeric values.
2. Assume input to be of integer datatype.
3. The output should be rounded using Math.round() method.
4. Take care of the spaces during formatting output (e.g., single space each before and after =).
5. The calculator should be able to perform required operations on a minimum of two operands as shown in the below example:
Input:
5+6
Output:
5+6 = 11
| Public Test Cases | Input | Expected Output | Actual Output | Status |
|---|---|---|---|---|
Test Case 1 | 5+6 | 5+6 = 11 | 5+6 = 11\n
| Passed after ignoring Presentation Error |
Week 09 : Programming Assignment 3
Write a Java program that utilizes multithreading to calculate and print the squares of numbers from a specified begin to a specified end.
The main method is already created.
You need to design a SquareThread class that has two members,
§ int begin;
§ int end;
Each thread should sequentially print the squares of numbers from begin to end (both inclusive).
The same code will be used to create another thread that prints the sqaure of numbers from end to begin in reverse order.
(if begin is greater than end, print the square of each number in reverse order first)
The main method will first call SquareThread with begin and end and then in reverse order.
The class you create should be able to handle such case and print as required in the correct order.
HINT: use the keyword `synchronized` in the run method.
| Public Test Cases | Input | Expected Output | Actual Output | Status |
|---|---|---|---|---|
Test Case 1 | 1
5 | 1\n
4\n
9\n
16\n
25\n
25\n
16\n
9\n
4\n
1 | 1\n
4\n
9\n
16\n
25\n
25\n
16\n
9\n
4\n
1\n
| Passed after ignoring Presentation Error |
Test Case 2 | 9
6 | 81\n
64\n
49\n
36\n
36\n
49\n
64\n
81 | 81\n
64\n
49\n
36\n
36\n
49\n
64\n
81\n
| Passed after ignoring Presentation Error |
Week 09 : Programming Assignment 4
Complete the code segment to catch the exception in the following, if any.
On the occurrence of such an exception, your program should print
“Please enter valid data” .
If there is no such exception, it will print the square of the number entered.
| Public Test Cases | Input | Expected Output | Actual Output | Status |
|---|---|---|---|---|
Test Case 1 | 2 | 4 | 4\n
| Passed after ignoring Presentation Error |
Test Case 2 | p | Please enter valid data | Please enter valid data\n
| Passed after ignoring Presentation Error |
Week 09 : Programming Assignment 5
Define a class Point with members
§ private double x;
§ private double y;
and methods:
§ public Point(double x, double y){} // Constructor to create a new point?
§ public double distance(Point p2){} // Function to return the distance of this Point from another Point
| Public Test Cases | Input | Expected Output | Actual Output | Status |
|---|---|---|---|---|
Test Case 1 | 0 0
1 1 | 1.4142135623730951 | 1.4142135623730951 | Passed |
Test Case 2 | 0 0
0 5 | 5.0 | 5.0 | Passed |
W10 Programming Assignments 1
Introduction to JDBC and Required Imports
Problem Statement
What is JDBC?
JDBC means Java Database Connectivity, which allows Java programs to work with databases.
Before writing database programs, you must import the correct packages. Without proper imports, the code will not compile.
Programming Assignment:
Import the necessary JDBC packages so the program can compile
You only need to complete the import section
The output
"import successful"is printed automatically
This helps you practice the correct way to prepare Java programs for database work.
| Public Test Cases | Input | Expected Output | Actual Output | Status |
|---|---|---|---|---|
Test Case 1 | NA | import successful | import successful\n
| Passed after ignoring Presentation Error |
W10 Programming Assignments 2
Writing a JDBC Connection String
Problem Statement
What is a JDBC Connection String?
To connect a Java program to a database, we use a special sentence called a connection string.
It tells Java:
Which database to use
Where the database is located
In this assignment, you will practice writing the correct JDBC connection string for SQLite database.
Programming Assignment:
Write the correct connection string for an SQLite database called
test.dbThe rest of the program prints
"connection string ready"if your string is correct
This helps beginners practice writing JDBC connection strings safely, without actual database access.
| Public Test Cases | Input | Expected Output | Actual Output | Status |
|---|---|---|---|---|
Test Case 1 | NA | connection string ready | connection string ready\n
| Passed after ignoring Presentation Error |
W10 Programming Assignments 3
Writing a Simple SQL Insert Statement
Problem Statement
What is an SQL Insert Statement?
When working with databases, we use the INSERT command to add new records (data) into a table.
In this assignment:
Imagine there is a table called
studentswith two columns:idandnameYou will practice writing the correct SQL insert statement as a text string
No actual database operation is performed, only the string is checked
Programming Assignment:
Complete the SQL insert statement to add a student with id
1and name'Alice'The rest of the code checks your string and prints
"insert statement ready"if correct
This task helps beginners practice writing SQL commands safely.
| Public Test Cases | Input | Expected Output | Actual Output | Status |
|---|---|---|---|---|
Test Case 1 | NA | insert statement ready | insert statement ready\n
| Passed after ignoring Presentation Error |
W10 Programming Assignments 4
Writing a Simple SQL SELECT Statement
Problem Statement
What is a SQL SELECT Statement?
The SELECT statement is used to get data from a database table.
You can choose to fetch all columns or specific columns.
In this assignment:
Imagine a table called
studentswith two columns:idandnameYou will practice writing a SQL statement to fetch all columns for all students
Programming Assignment:
Write a SQL SELECT statement as a text string to get all data from
studentstableThe rest of the program checks your string and prints
"select statement ready"if correct
This task helps beginners practice safe SQL reading commands.
| Public Test Cases | Input | Expected Output | Actual Output | Status |
|---|---|---|---|---|
Test Case 1 | NA | select statement ready | select statement ready\n
| Passed after ignoring Presentation Error |
W10 Programming Assignments 5
Writing a Simple SQL UPDATE Statement
Problem Statement
What is an SQL UPDATE Statement?
The UPDATE command is used to change existing data in a database table.
In this assignment:
Imagine a table called
studentswith two columns:idandnameYou will write a SQL statement to update the name of the student with id
1to'Bob'
Programming Assignment:
Write the correct SQL UPDATE statement as a text string
The rest of the code checks your string and prints
"update statement ready"if correct
This helps beginners practice safe SQL update syntax.
| Public Test Cases | Input | Expected Output | Actual Output | Status |
|---|---|---|---|---|
Test Case 1 | NA | update statement ready | update statement ready\n
| Passed after ignoring Presentation Error |
Week 11 : Programming Assignment 1
The following code needs some package to work properly.
Write appropriate code to
§ import the required package(s) in order to make the program compile and execute successfully.
(Ignore the hidden code)
| Public Test Cases | Input | Expected Output | Actual Output | Status |
|---|---|---|---|---|
Test Case 1 | 0 | true | true | Passed |
Week 11 : Programming Assignment 2
Write the JDBC codes needed to create a Connection interface using the DriverManager class and the variable DB_URL. Check whether the connection is successful using 'isValid(timeout)' method to generate the output, which is either 'true' or 'false'.
Note the following points carefully:
§ Name the connection object as conn only.
§ Use timeout value as 1.
| Public Test Cases | Input | Expected Output | Actual Output | Status |
|---|---|---|---|---|
Test Case 1 | 0 | true | true | Passed |
Week 11 : Programming Assignment 3
Due to some mistakes in the below code, the code is not compiled/executable.
Modify and debug the JDBC code to make it execute successfully.
| Public Test Cases | Input | Expected Output | Actual Output | Status |
|---|---|---|---|---|
Test Case 1 | 0 | true | true | Passed |
Week 11 : Programming Assignment 4
Complete the code segment to create a new table named ‘STUDENTS’ in SQL database using the following information.
Column | UID | Name | Roll | Age |
Type | Integer | Varchar (45) | Varchar (12) | Integer |
| Public Test Cases | Input | Expected Output | Actual Output | Status |
|---|---|---|---|---|
Test Case 1 | 1 | No. of columns : 4\n
Column 1 Name: UID\n
Column 1 Type : INT\n
Column 2 Name: Name\n
Column 2 Type : VARCHAR\n
Column 3 Name: Roll\n
Column 3 Type : VARCHAR\n
Column 4 Name: Age\n
Column 5 Type : INT | No. of columns : 4\n
Column 1 Name: UID\n
Column 1 Type : INT\n
Column 2 Name: Name\n
Column 2 Type : VARCHAR\n
Column 3 Name: Roll\n
Column 3 Type : VARCHAR\n
Column 4 Name: Age\n
Column 5 Type : INT | Passed |
Week 11 : Programming Assignment 5
Complete the code segment to rename an already created table named ‘STUDENTS’ into ‘GRADUATES’.
| Public Test Cases | Input | Expected Output | Actual Output | Status |
|---|---|---|---|---|
Test Case 1 | 1 | TABLE NAME = GRADUATES | TABLE NAME = GRADUATES | Passed |
W12 Programming Assignments 1
Parameterized Constructors in Java
Problem Statement
What is a Constructor?
A constructor is a special method in Java used to create an object.
It looks like a method, but:
Its name is the same as the class name
It does not have a return type
What is a Parameterized Constructor?
Sometimes, when creating an object, we want to give it some initial values.
We can do this by passing values (parameters) to the constructor.
Example:
If we have a Student class with a name and roll number, we can set these values using a constructor.
Programming Assignment
In this task:
Create a class called
StudentAdd two variables:
name(String) androll(int)Write a parameterized constructor to assign values to these variables
In the
mainmethod, create aStudentobject by passing name and roll numberPrint the details
This helps you understand how to use constructors to create objects with values, a common topic in interviews.
| Public Test Cases | Input | Expected Output | Actual Output | Status |
|---|---|---|---|---|
Test Case 1 | Deepak
101 | Student Name: Deepak\n
Roll Number: 101 | Student Name: Deepak\n
Roll Number: 101\n
| Passed after ignoring Presentation Error |
W12 Programming Assignments 2
Understanding Method Overloading in Java
Problem Statement
What is Method Overloading?
In Java, you can create multiple methods with the same name but different parameters. This is called Method Overloading.
Why is it useful?
Makes code cleaner
Allows methods to perform similar tasks with different types of input
This is a very common Java interview topic to test your understanding of functions and code flexibility.
Programming Assignment
In this task:
Create a class called
CalculatorOverload a method called
addin two ways:A method that adds two integers
A method that adds three integers
In the
mainmethod, call both versions ofaddand print the results
This helps you practice method overloading, which is essential for interviews and real-world coding.
| Public Test Cases | Input | Expected Output | Actual Output | Status |
|---|---|---|---|---|
Test Case 1 | 5
10
2
3
4 | Sum of two numbers: 15\n
Sum of three numbers: 9 | Sum of two numbers: 15\n
Sum of three numbers: 9\n
| Passed after ignoring Presentation Error |
W12 Programming Assignments 3
If-Else with Nested Conditions in Java
Problem Statement
What is If-Else?
In Java, if-else statements let your program make decisions.
ifchecks a conditionIf true, some code runs
If false, another block of code can run
What is a Nested If?
You can place one
ifstatement inside anotherThis allows checking more than one condition
Why is this important?
Decision-making is one of the most common coding tasks
Almost every programming interview includes if-else logic
Programming Assignment
In this task:
Read an integer from the user
If the number is greater than 0: print
"Positive Number"If the number is less than 0: print
"Negative Number"If the number is exactly 0: print
"Zero"
This helps you practice nested if-else, a very important concept
| Public Test Cases | Input | Expected Output | Actual Output | Status |
|---|---|---|---|---|
Test Case 1 | 7 | Positive Number | Positive Number\n
| Passed after ignoring Presentation Error |
Test Case 2 | 0 | Zero | Zero\n
| Passed after ignoring Presentation Error |
W12 Programming Assignments 4
Using a Loop to Calculate Sum of Natural Numbers
Problem Statement
What is a Loop?
In Java, loops allow a block of code to run multiple times automatically.
A for loop runs when you know how many times to repeat the task.
In this assignment:
You will calculate the sum of first
nnatural numbersNatural numbers are: 1, 2, 3, 4, ... up to
n
Programming Assignment:
Read an integer
nfrom the userUse a loop to add numbers from 1 to
nPrint the final sum
This helps practice how loops work and how to perform repeated addition.
| Public Test Cases | Input | Expected Output | Actual Output | Status |
|---|---|---|---|---|
Test Case 1 | 5 | Sum is: 15 | Sum is: 15\n
| Passed after ignoring Presentation Error |
W12 Programming Assignments 5
Array, Loop, and Condition Task
Problem Statement
In this task, you will apply multiple basic programming concepts together:
✅ You will read n numbers and store them in an array
✅ You will calculate the sum of all positive numbers
✅ You will count how many negative numbers are present
✅ Finally, you will print both results
This combines:
Arrays (storing multiple values)
Loops (processing values)
If-else conditions (deciding based on positive or negative)
This type of task helps in applying core concepts together in a structured program.
| Public Test Cases | Input | Expected Output | Actual Output | Status |
|---|---|---|---|---|
Test Case 1 | 5
3 -2 7 -8 10 | Sum of positive numbers: 20\n
Count of negative numbers: 2 | Sum of positive numbers: 20\n
Count of negative numbers: 2\n
| Passed after ignoring Presentation Error |
No comments:
Post a Comment
Keep your comments reader friendly. Be civil and respectful. No self-promotion or spam. Stick to the topic. Questions welcome.