Home

Learn Programming & Prepare for NPTEL Exams... Swayam Solver is your one-stop destination for NPTEL exam preparation.

NPTEL Programming In Java Programming Assignment Jan-2025 Swayam

 




NPTEL » Programming In Java



  Please scroll down for latest Programs. 👇 


Week 01 : Programming Assignment 1

Due on 2025-02-06, 23:59 IST

Write a Java program to check if a given integer is even or odd.

 

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.

(Ignore presentation errors for this and all future programming assignments)
("passed with presentation error" means you will get full marks)

Your last recorded submission was on 2025-01-15, 16:23 IST
Select the Language for this assignment. 
File name for this program : 
1
import java.util.Scanner;
2
 
3
public class W01_P1 {
4
    public static void main(String[] args) {
5
        Scanner in = new Scanner(System.in);
6
        int number = in.nextInt();
7
// Check if the number is even or odd
8
if (number % 2 == 0) {
9
  System.out.print("Even");
10
} else {
11
  System.out.print("Odd");
12
}
0
in.close();
1
    }
2
}
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
4
Even
Even
Passed



Week 01 : Programming Assignment 2

Due on 2025-02-06, 23:59 IST

Write a Java program to calculate the volume of a cylinder given its radius and height.

Formula:

=π×2×

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)

(Ignore presentation errors for this and all future programming assignments)
("passed with presentation error" means you will get full marks)

Your last recorded submission was on 2025-01-15, 16:25 IST
Select the Language for this assignment. 
File name for this program : 
1
import java.util.Scanner;
2
 
3
public class W01_P2 {
4
    public static void main(String[] args) {
5
        Scanner in = new Scanner(System.in);
6
        double radius = in.nextDouble();
7
        double height = in.nextDouble();
8
// Calculate the volume
9
double volume = Math.PI * radius * radius * height;
0
// Display the result
1
    System.out.printf("Volume is: %.2f", volume);
2
    in.close();
3
  }
4
}
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
3.5
5.0
Volume is: 192.42
Volume is: 192.42
Passed



Week 01 : Programming Assignment 3

Due on 2025-02-06, 23:59 IST

Write a Java program to print the multiplication table of a given number up to 5.

 

NOTE:

Print EXACTLY as shown in the sample output.

DO NOT MISS a single space otherwise you will not be scored.


(Ignore presentation errors for this and all future programming assignments)
("passed with presentation error" means you will get full marks)

Your last recorded submission was on 2025-01-15, 16:28 IST
Select the Language for this assignment. 
File name for this program : 
1
import java.util.Scanner;
2
 
3
public class W01_P3 {
4
    public static void main(String[] args) {
5
        Scanner in = new Scanner(System.in);
6
        int number = in.nextInt();
7
// Print the multiplication table of number up to 5
8
for (int i = 1; i <= 4; i++) {
9
   System.out.println(number + " x " + i + " = " + (number * i));
10
}
11
System.out.print(number + " x " + 5 + " = " + (number * 5));
0
in.close();
1
    }
2
}
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
5
5 x 1 = 5\n
5 x 2 = 10\n
5 x 3 = 15\n
5 x 4 = 20\n
5 x 5 = 25
5 x 1 = 5\n
5 x 2 = 10\n
5 x 3 = 15\n
5 x 4 = 20\n
5 x 5 = 25
Passed



Week 01 : Programming Assignment 4

Due on 2025-02-06, 23:59 IST

Complete the code fragment that reads two integer inputs from keyboard and compute the quotient and remainder.

(Ignore presentation errors for this and all future programming assignments)
("passed with presentation error" means you will get full marks)

Your last recorded submission was on 2025-01-15, 16:36 IST
Select the Language for this assignment. 
File name for this program : 
1
import java.util.Scanner;
2
public class W01_P4{
3
       public static void main(String[] args) {
4
       Scanner sc = new Scanner(System.in);
5
       int x=sc.nextInt();
6
       int y=sc.nextInt();
7
//code for quotient and remainder
8
if (y == 0) {
9
  System.out.println("Error: Division by zero is not allowed.");
10
}
11
else {
12
  int quotient = x / y;
13
  int remainder = x % y;
14
  System.out.println("The Quotient is = " + quotient);
15
  System.out.print("The Remainder is = " + remainder);
16
}
0
sc.close();
1
  }
2
}
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
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-02-06, 23:59 IST

Write a program which will print a pattern of "*" 's of height "n".
For example:
Input:
               n = 3
Output:
               ***
               **
               *
               **
               ***

NOTE:
Print the pattern EXACTLY, without extra spaces.

(Ignore presentation errors for this and all future programming assignments)
("passed with presentation error" means you will get full marks)

Your last recorded submission was on 2025-01-15, 16:53 IST
Select the Language for this assignment. 
File name for this program : 
1
import java.util.*;
2
public class W01_P5{
3
    public static void main(String[] args) {
4
        Scanner inr = new Scanner(System.in);
5
       int n = inr.nextInt();
6
// Add the necessary code in the below space
7
for(int i = n; i >= 1; i--) {
8
  for(int j = 1; j <= i; j++) {
9
    System.out.print("*");
10
  }
11
  System.out.println();
12
}
13
for(int i = n-1; i >= 1; i--) {
14
  for(int j = 1; j <= n-i+1; j++) {
15
    System.out.print("*");
16
  }
17
  if ( i != 1 )
18
    System.out.println();
19
}
0
inr.close();
1
    }
2
}
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
6
******\n
*****\n
****\n
***\n
**\n
*\n
**\n
***\n
****\n
*****\n
******
******\n
*****\n
****\n
***\n
**\n
*\n
**\n
***\n
****\n
*****\n
******
Passed





Week 02 : Programming Assignment 1

Due on 2025-02-06, 23:59 IST

Write a Java program to create a class Student with the following attributes: name, age, and grade. Create a constructor to initialize these attributes. Display the student’s information using a method displayInfo().


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.

(Ignore presentation errors for this and all future programming assignments)
("passed with presentation error" means you will get full marks)

Select the Language for this assignment. 
File name for this program : 
1
import java.util.*;
2
 
3
class Student {
4
    String name;
5
    int age;
6
    String grade;
7
 
8
    // Constructor
9
    public Student(String name, int age, String grade) {
10
        this.name = name;
11
        this.age = age;
12
        this.grade = grade;
13
    }
14
 
15
    public void displayInfo() {
16
        System.out.println("Student Name: " + name);
17
        System.out.println("Age: " + age);
18
        System.out.print("Grade: " + grade);
19
    }
20
}
21
public class W02_P1 {
22
    public static void main(String[] args) {
23
        Scanner sc = new Scanner(System.in);
24
        String name = sc.nextLine();
25
        int age = sc.nextInt();
26
        String grade = sc.next();
27
// Create a Student object and call displayInfo
28
// Add the necessary code in the spaces below 
29
 
30
 
31
//code to create student object 
32
Student student = new Student(name, age, grade);
33
 
34
//code to call displayInfo function
35
student.displayInfo();
0
sc.close();
1
}
2
}
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
Rahul
29
A
Student Name: Rahul\n
Age: 29\n
Grade: A
Student Name: Rahul\n
Age: 29\n
Grade: A
Passed



Week 02 : Programming Assignment 2

Due on 2025-02-06, 23:59 IST

Write a program that demonstrates constructor overloading. Create a class Student with two constructors:

  1. A constructor that accepts name and age 
  2. A constructor that accepts all three attributes: nameage, and grade.

Print the student's information using a method displayInfo().

Input:

  • name (String)
  • age (int)
  • grade (String, optional)

Output:
The program should output:

Name: <name> Age: <age> Grade: <grade>

Select the Language for this assignment. 
File name for this program : 
1
import java.util.*;
2
public class Student {
3
    String name;
4
    int age;
5
    String grade;
6
 
7
    public Student(String name, int age) {
8
        this.name = name;
9
        this.age = age;
10
    }
11
 
12
    public Student(String name, int age, String grade) {
13
        this.name = name;
14
        this.age = age;
15
        this.grade = grade;
16
    }
17
 
18
    public void displayInfo() {
19
        System.out.println("Name: " + name);
20
        System.out.println("Age: " + age);
21
        if(!grade.isEmpty()||grade!=null) System.out.print("Grade: " + grade);
22
    }
23
 
24
    public static void main(String[] args) {
25
        Scanner sc = new Scanner(System.in);
26
        String name = sc.nextLine();
27
        int age = sc.nextInt();
28
        String grade= null;
29
 
30
        // Check if grade is provided or not
31
        if(sc.hasNextLine())
32
        {
33
         sc.nextLine();
34
         grade =  sc.nextLine();
35
         }
36
        
37
        // Create the student object
38
        Student student;
39
// Write the appropriate constructor call code in the given spaces
40
if (grade == null ||grade.isEmpty()) {
41
    student = new Student(name, age);  // Add your code to call the constructor when grade is not given in input
42
} else {
43
    student = new Student(name, age, grade);  // Add your code to call the constructor when grade is given in input
44
}
45
 
46
// code to call displayInfo function to display the information
47
student.displayInfo();  // Call the displayInfo method to display the student's information
0
sc.close();
1
    }
2
}
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
Rahul
30
A
Name: Rahul\n
Age: 30\n
Grade: A
Name: Rahul\n
Age: 30\n
Grade: A
Passed




Week 02 : Programming Assignment 3

Due on 2025-02-06, 23:59 IST

Write a program to demonstrate the use of this keyword. Create a class Rectangle with attributes length and breadth. Write a constructor to initialize these values. Also, define a method area() to return the area of the rectangle.

Input:
Two integers: length and breadth of the rectangle.

Output:
Print the area of the rectangle.

Select the Language for this assignment. 
File name for this program : 
1
import java.util.*;
2
public class W02_P3{
3
    public static void main(String[] args) {
4
        Scanner sc = new Scanner(System.in);
5
        int length = sc.nextInt();
6
        int breadth = sc.nextInt();
7
// Define the class Rectangle here
8
// Use the this keyword in the constructor
9
// Define the area method
10
 
11
class Rectangle {
12
    int length, breadth;
13
 
14
    // Constructor
15
    Rectangle(int length, int breadth) {
16
        this.length = length; 
17
        this.breadth = breadth;
18
    }
19
 
20
    // Method to calculate area
21
     int area() {
22
        return length * breadth; //write the correct formula
23
    }
24
}
0
// Create an object of Rectangle and call the area method
1
        Rectangle r = new Rectangle(length, breadth);
2
        System.out.print(r.area());
3
 
4
        sc.close();
5
    }
6
}
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
5
10
50
50
Passed



Week 02 : Programming Assignment 4

Due on 2025-02-06, 23:59 IST

Create a class Car with attributes brand and price. Add a method display() to show the car details. Write a program to create two objects of this class and display their details.

Input:
Two lines, each containing:

  • Car brand (a single word)
  • Car price (an integer)

Output:
Print the brand and price of both cars.

Select the Language for this assignment. 
File name for this program : 
1
import java.util.*;
2
public class W02_P4{
3
    public static void main(String[] args) {
4
        Scanner sc = new Scanner(System.in);
5
        String brand1 = sc.next();
6
        int price1 = sc.nextInt();
7
        String brand2 = sc.next();
8
        int price2 = sc.nextInt();
9
// Define the class Car here
10
// Write a constructor and a display method
11
 
12
class Car {
13
    //variables 
14
    String brand;
15
    int price;
16
 
17
    // Constructor
18
    Car(String brand, int price) {
19
        this.brand = brand;
20
        this.price = price;
21
    }
22
 
23
    // Display method
24
    void display(int num) {
25
        System.out.println("Car " + num + ": " + brand + ", Price: " + price);
26
    }
27
}
0
// Create two objects of Car and display their details
1
        // Main code
2
       Car car1 = new Car(brand1, price1);
3
       Car car2 = new Car(brand2, price2);
4
       car1.display(1);
5
       car2.display(2);
6
 
7
        sc.close();
8
    }
9
}
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
Maruti  
500000  
Honda  
800000
Car 1: Maruti, Price: 500000\n
Car 2: Honda, Price: 800000
Car 1: Maruti, Price: 500000\n
Car 2: Honda, Price: 800000\n
Passed after ignoring Presentation Error




Week 02 : Programming Assignment 5

Due on 2025-02-06, 23:59 IST

Write a Java program to demonstrate the concept of encapsulation by modeling a Book object. The program should include methods for setting and getting the title and author of the book, and a method to display the details of the book.

Task:

  1. Create a class Book with the following private attributes:

    • title (String)
    • author (String)
  2. Include the following methods in the Book class:

    • setTitle(String title) to set the title of the book.
    • setAuthor(String author) to set the author of the book.
    • getTitle() to return the title of the book.
    • getAuthor() to return the author of the book.
    • displayDetails() to print the details of the book in the format
      Title: <title> Author: <author>
  3. In the main() method, create an object of the Book class, set the title and author, and then call the displayDetails() method to print the book details.

Input:

  • The first line contains the title of the book (a single word).
  • The second line contains the author's name (a single word).

Output:
Print the details of the book in the format:

Title: <title> Author: <author>

Example:

Input:

JavaProgramming JohnDoe

Output:

Title: JavaProgramming Author: JohnDoe
Select the Language for this assignment. 
File name for this program : 
1
import java.util.Scanner;
2
 
3
public class W02_P5{
4
    public static void main(String[] args) {
5
        Scanner sc = new Scanner(System.in);
6
        String title = sc.next();
7
        String author = sc.next();
8
        
9
        // Create a Book object
10
        Book book = new Book();
11
        
12
        // Set title and author
13
        book.setTitle(title);
14
        book.setAuthor(author);
15
        
16
        // Display book details
17
        book.displayDetails();
18
    }
19
}
20
// Define the Book class with private attributes for title and author
21
// Create getter and setter methods for both title and author
22
// Add a displayDetails method to print the title and author
23
 
24
 
25
class Book {
26
    // Private attributes
27
    private String title;
28
    private String author;
29
    
30
    // Setter for title
31
    public void setTitle(String title) {
32
        this.title = title;
33
    }
34
    
35
    // Setter for author
36
    public void setAuthor(String author) {
37
        this.author = author;
38
    }
39
    
40
    // Getter for title
41
    public String getTitle() {
42
        return this.title;
43
    }
44
    
45
    // Getter for author
46
    public String getAuthor() {
47
        return this.author;
48
    }
0
// Method to display details
1
    public void displayDetails() {
2
        System.out.println("Title: " + this.title);
3
        System.out.print("Author: " + this.author);
4
    }
5
}
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
DataStructures
Alice
Title: DataStructures\n
Author: Alice
Title: DataStructures\n
Author: Alice
Passed





Week 03 : Programming Assignment 1

Due on 2025-02-13, 23:59 IST

Write a program to print the factorial of a number by defining a static recursive method named 'Factorial'.

Factorial of any number n is represented by n! and is equal to 1*2*3*....*(n-1)*n. E.g.-

4! = 1*2*3*4 = 24

3! = 3*2*1 = 6

2! = 2*1 = 2

Also,

1! = 1

0! = 1

(Remember to match the output given exactly, including the spaces and new lines)

(passed with presentation error means you will get full marks)


Your last recorded submission was on 2025-02-11, 18:08 IST
Select the Language for this assignment. 
File name for this program : 
1
import java.util.Scanner;
2
class W03_P1{
3
//Create recursive method to find factorial of a number
4
public static int factorial(int n) {
5
        if (n == 0 || n == 1) {
6
            return 1;
7
        } else {
8
            return n * factorial(n - 1);
9
        }
10
    }
0
public static void main(String[] args) {
1
        Scanner in = new Scanner(System.in);
2
        int x;
3
        x = in.nextInt();
4
        System.out.print(factorial(x));   
5
  }
6
}
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
5
120
120
Passed



Week 03 : Programming Assignment 2

Due on 2025-02-13, 23:59 IST

There are two class cls1 and cls2 which is subclass of cls1.  cls1 having a method "add" which add two numbers. Create two method inside cls2 which will take 2 parameters as input i.e. a and b and print the sum , multiplication and sum of their squares i.e (a^2) + (b^2) (name the function task())

(Remember to match the output given exactly, including the spaces and new lines)

(passed with presentation error means you will get full marks)

Your last recorded submission was on 2025-02-11, 18:24 IST
Select the Language for this assignment. 
File name for this program : 
1
import java.util.Scanner;
2
class cls1
3
{
4
    void add(int p,int q)
5
    {
6
        System.out.println(p+q);
7
    }
8
}
9
//Create subclass cls2 of cls1 which perform task of multiplication and sum of squares of passing two parameters.
10
class cls2 extends cls1 {
11
    public void mul(int a, int b) {
12
        System.out.println(a * b);
13
    }
14
  public void task(int a, int b) {
15
        int sumOfSquares = (a * a) + (b * b);
16
        System.out.print(sumOfSquares);
17
    }
18
}
0
public class W03_P2{
1
    public static void main(String args[])
2
    {
3
        Scanner sc=new Scanner(System.in);
4
    
5
        cls2 obj=new cls2();
6
        int a=sc.nextInt();
7
        int b=sc.nextInt();
8
        //String tilde=sc.next();
9
        obj.add(a,b);
10
        obj.mul(a,b);
11
        obj.task(a,b);
12
    
13
    }
14
}
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
2
4
6\n
8\n
20
6\n
8\n
20
Passed



Week 03 : Programming Assignment 3

Due on 2025-02-13, 23:59 IST

Complete the code segment to count number of digits in an integer using while loop.

(Remember to match the output given exactly, including the spaces and new lines)

(passed with presentation error means you will always get full marks)

Your last recorded submission was on 2025-02-11, 18:59 IST
Select the Language for this assignment. 
File name for this program : 
1
import java.util.Scanner;
2
public class W03_P3{
3
    public static void main(String[] args) {
4
       Scanner sc = new Scanner(System.in);
5
       int num=sc.nextInt();
6
//Use while loop to count number of digits in an integer
7
int count = 0;
8
if (num == 0) {
9
            count = 1;  // 0 has one digit
10
        } else {
11
            while (num != 0) {
12
                num = num / 10; // Integer division removes the last digit
13
                count++;
14
            }
15
        }
16
System.out.print(count);
0
}
1
}
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
153
3
3
Passed
Test Case 2
0003452
4
4
Passed



Week 03 : Programming Assignment 4

Due on 2025-02-13, 23:59 IST

A Student class with private fields (name, age) is provided,

Your task is to make the following: 

§ a parameterized constructor to initialize the private fields

§ the getter/setter methods for each field

Follow the naming convention as given in the main method of the suffix code.

Your last recorded submission was on 2025-02-11, 19:02 IST
Select the Language for this assignment. 
File name for this program : 
1
import java.util.Scanner;
2
class Student {
3
    private String name;
4
    private int age;
5
// ================================
6
    // TODO: Implement the Student class with private fields (name, age),
7
    //       a constructor, and getter/setter methods.
8
// Parameterized constructor
9
    public Student(String name, int age) {
10
        this.name = name;
11
        this.age = age;
12
    }
13
    // Getter for name
14
    public String getName() {
15
        return name;
16
    }
17
    // Getter for age
18
    public int getAge() {
19
        return age;
20
    }
0
public static void main(String[] args) {
1
        Scanner scanner = new Scanner(System.in);
2
 
3
        // System.out.print("Enter student name: ");
4
        String name = scanner.next();
5
 
6
        // System.out.print("Enter student age: ");
7
        int age = scanner.nextInt();
8
 
9
        Student student = new Student(name, age);
10
 
11
        System.out.print("Name: " + student.getName() + ", Age: " + student.getAge());
12
 
13
        scanner.close();
14
    }
15
}
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
John
20
Name: John, Age: 20
Name: John, Age: 20
Passed
Test Case 2
Alice
25
Name: Alice, Age: 25
Name: Alice, Age: 25
Passed



Week 03 : Programming Assignment 5

Due on 2025-02-13, 23:59 IST

This program is an exercise to call static and non-static methods.

A partial code is given defining two methods, namely sum( ) and multiply ( ).

You have to call these methods to find the sum and product of two numbers.

Complete the code segment as instructed.  

Your last recorded submission was on 2025-02-11, 19:07 IST
Select the Language for this assignment. 
File name for this program : 
1
import java.util.Scanner;
2
class QuestionScope {
3
int sum(int a, int b){ //non-static method
4
        return a + b;
5
    }
6
static int multiply(int a, int b){ //static method
7
        return a * b;
8
    }
9
}
10
public class W03_P5{
11
public static void main( String[] args ) {
12
        Scanner sc = new Scanner(System.in);
13
     int n1=sc.nextInt();
14
     int n2=sc.nextInt();
15
     QuestionScope st= new QuestionScope(); // Create an object to call non-static method
16
//Call the method sum() to find the sum of two numbers and store in result1
17
int result1 = st.sum(n1, n2);
18
//Call the method multiply() to find the product of two numbers and store in result2
19
int result2 = QuestionScope.multiply(n1, n2);
0
System.out.println(result1);
1
    System.out.print(result2);  
2
  }
3
}
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
3
5
8\n
15
8\n
15
Passed





Week 04 : Programming Assignment 1

Due on 2025-02-20, 23:59 IST
Complete the code segment to execute the following program successfully. Note: You should import the correct package(s) and/or class(s) to complete the code.
Your last recorded submission was on 2025-02-18, 23:08 IST
Select the Language for this assignment. 
File name for this program : 
1
// Import the required package(s) and/or class(es)
2
//HINT1:  Import of pre-defined package java.util and class Scanner
3
//HINT2:  Import of pre-defined package java.lang and class System and all of its member
4
import java.util.Scanner;
5
import static java.lang.System.*;
0
// main class Question is created
1
public class Main{
2
  public static void main(String[] args) {
3
    // Scanner object is created
4
    Scanner scanner = new Scanner(System.in);
5
     // Read String input using scanner class
6
    String courseName = scanner.nextLine(); 
7
     // Print the scanned String
8
    out.println("Course: " + courseName); 
9
  }
10
}
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
JOY WITH JAVA
Course: JOY WITH JAVA
Course: JOY WITH JAVA\n
Passed after ignoring Presentation Error



Week 04 : Programming Assignment 2

Due on 2025-02-20, 23:59 IST

Complete the code segment to print the current year.
Your code should compile successfully.

Note: In this program, you are not allowed to use any import statement. You should use predefined class Calendar defined in java.util package.

Your last recorded submission was on 2025-02-18, 23:09 IST
Select the Language for this assignment. 
File name for this program : 
1
// The following is the declaration of the main class named Main
2
public class Main{ 
3
    public static void main(String args[]){
4
        int year; // integer type variable to store year    
5
 
6
                 // Create an object of Calendar class. 
7
                 java.util.Calendar current; 
8
 
9
                // Use getInstance() method to initialize the Calendar object.
10
                 current = java.util.Calendar.getInstance();
11
// Initialize the int variable year with the current year
12
year = current.get(current.YEAR);
0
// Print the current Year
1
System.out.println("Current Year: "+year);
2
 
3
}
4
}
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
NA
Current Year: 2025
Current Year: 2025\n
Passed after ignoring Presentation Error



Week 04 : Programming Assignment 3

Due on 2025-02-20, 23:59 IST

The program in this assignment is attempted to print the following output: 

-----------------OUTPUT-------------------

This is large

This is medium

This is small

This is extra-large

-------------------------------------------------

However, the code is intentionally with some bugs in it. Debug the code to execute the program successfully.

Your last recorded submission was on 2025-02-18, 23:12 IST
Select the Language for this assignment. 
File name for this program : 
1
interface ExtraLarge{
2
    static String extra = "This is extra-large";
3
    void display();
4
}
5
 
6
class Large {
7
    public void Print() {
8
        System.out.println("This is large");
9
    }
10
}
11
 
12
class Medium extends Large {
13
    public void Print() {
14
        super.Print();  
15
        System.out.println("This is medium");
16
    }
17
}
18
class Small extends Medium {
19
    public void Print() {
20
        super.Print();  
21
        System.out.println("This is small");
22
    }
23
}
24
 
25
class Main implements ExtraLarge{
26
    public static void main(String[] args) {
27
        Small s = new Small();
28
        s.Print();
29
    Main q = new Main();
30
    q.display();
31
    }
32
    public void display(){
33
        System.out.println(extra);
34
    }
35
}
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
NA
This is large\n
This is medium\n
This is small\n
This is extra-large
This is large\n
This is medium\n
This is small\n
This is extra-large\n
Passed after ignoring Presentation Error



Week 04 : Programming Assignment 4

Due on 2025-02-20, 23:59 IST

Complete the code segment to call the default method in the interface First and Second.

Your last recorded submission was on 2025-02-18, 23:14 IST
Select the Language for this assignment. 
File name for this program : 
1
interface First{ 
2
    // default method 
3
    default void show(){ 
4
        System.out.println("Default method implementation of First interface."); 
5
    } 
6
} 
7
  
8
interface Second{ 
9
    // Default method 
10
    default void show(){ 
11
        System.out.println("Default method implementation of Second interface."); 
12
    } 
13
} 
14
  
15
// Implementation class code 
16
class Main implements First, Second{ 
17
    // Overriding default show method 
18
    public void show(){
19
// Call show() of First interface.
20
First.super.show();
21
// Call show() of Second interface.
22
Second.super.show();
0
} 
1
  
2
    public static void main(String args[]){ 
3
        Main q = new Main(); 
4
        q.show(); 
5
    } 
6
}
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
NA
Default method implementation of First interface.\n
Default method implementation of Second interface.
Default method implementation of First interface.\n
Default method implementation of Second interface.\n
Passed after ignoring Presentation Error



Week 04 : Programming Assignment 5

Due on 2025-02-20, 23:59 IST

Modify the code segment  to print the following output.

-----------------OUTPUT-------------------

Circle: This is Shape1

Circle: This is Shape2

-------------------------------------------------

Your last recorded submission was on 2025-02-18, 23:15 IST
Select the Language for this assignment. 
File name for this program : 
1
// Interface ShapeX is created
2
interface ShapeX {
3
 public String base = "This is Shape1";
4
 public void display1();
5
}
6
 
7
// Interface ShapeY is created which extends ShapeX
8
interface ShapeY extends ShapeX {
9
 public String base = "This is Shape2";
10
 public void display2();
11
}
12
//the code in this cell is sample code --please edit this to perform as asked in the question
13
 
14
 
15
// Class ShapeG is created which implements ShapeY
16
class ShapeG implements ShapeY {
17
 public String base = "This is Shape3";
18
 //Overriding method in ShapeX interface
19
 public void display1() {
20
  System.out.println("Circle: " + ShapeX.base);
21
 }
22
 // Overriding method in ShapeY interface
23
 public void display2() {
24
  System.out.println("Circle: " + ShapeY.base);
25
 }
26
}
0
public class Main{
1
 public static void main(String[] args) {
2
  //Object of class shapeG is created and display methods are called.
3
  ShapeG circle = new ShapeG();
4
  circle.display1();
5
  circle.display2();
6
 }
7
}
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
NA
Circle: This is Shape1\n
Circle: This is Shape2
Circle: This is Shape1\n
Circle: This is Shape2\n
Passed after ignoring Presentation Error





Week 05 : Programming Assignment 1

Due on 2025-02-27, 23:59 IST

An interface Number is defined in the following program.

You have to declare a class A, which will implement the interface Number.

 

Note that the method findSqr(n) will return the square of the number n.

Your last recorded submission was on 2025-02-21, 07:53 IST
Select the Language for this assignment. 
File name for this program : 
1
import java.util.Scanner;
2
 
3
interface Number {
4
    int findSqr(int i);  // Returns the square of n
5
}
6
class A implements Number{
7
  public int findSqr(int i){
8
    return i*i;
9
  }
10
}
0
public class W05_P1{ 
1
        public static void main (String[] args){ 
2
          A a = new A();   //Create an object of class A
3
           // Read a number from the keyboard
4
           Scanner sc = new Scanner(System.in);  
5
           int i = sc.nextInt();
6
           System.out.print(a.findSqr(i)); 
7
    } 
8
}
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
12
144
144
Passed



Week 05 : Programming Assignment 2

Due on 2025-02-27, 23:59 IST

This program is to find the GCD (greatest common divisor) of two integers writing a recursive function findGCD(n1,n2).

Your function should return -1, if the argument(s) is(are) negative (zero is allowed).

Your last recorded submission was on 2025-02-21, 07:54 IST
Select the Language for this assignment. 
File name for this program : 
1
import java.util.Scanner;
2
 
3
interface GCD {
4
    public int findGCD(int n1,int n2);
5
}
6
class B implements GCD{
7
  public int findGCD(int n1,int n2){
8
    if ( n1 < 0 || n2 < 0 )
9
      return(-1);
10
    else if ( n2 == 0 )
11
      return n1;
12
    else if ( n1 > n2 )
13
      return findGCD(n2,n1%n2);
14
    else
15
      return findGCD(n1,n2%n1);
16
      }
17
}
0
public class W05_P2{ 
1
        public static void main (String[] args){ 
2
          B a = new B();   //Create an object of class B
3
            // Read two numbers from the keyboard
4
            Scanner sc = new Scanner(System.in);  
5
            int p1 = sc.nextInt();
6
           int p2 = sc.nextInt();
7
            System.out.print(a.findGCD(p1,p2)); 
8
    } 
9
}
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
20 30
10
10
Passed
Test Case 2
2 -1
-1
-1
Passed



Week 05 : Programming Assignment 3

Due on 2025-02-27, 23:59 IST

Complete the code segment to catch the ArithmeticException in the following, if any.

On the occurrence of such an exception, your program should print “Exception caught: Division by zero.”

If there is no such exception, it will print the result of division operation on two integer values. 

Your last recorded submission was on 2025-02-21, 07:58 IST
Select the Language for this assignment. 
File name for this program : 
1
import java.util.Scanner;
2
  
3
  public class W05_P3 {
4
  public static void main(String[] args) { 
5
      int a, b;
6
      Scanner input = new Scanner(System.in);
7
       // Read any two values for a and b
8
       int result;  
9
 
10
       a = input.nextInt();
11
       b = input.nextInt();
12
// try block to divide two numbers and display the result
13
         try {
14
              result = a/b;
15
              System.out.print(result);
16
             }
17
          // catch block to catch the ArithmeticException
18
          catch (ArithmeticException e) {
19
             System.out.print("Exception caught: Division by zero.");
20
          }
0
}
1
}
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
4 5
0
0
Passed
Test Case 2
20 0
Exception caught: Division by zero.
Exception caught: Division by zero.
Passed



Week 05 : Programming Assignment 4

Due on 2025-02-27, 23:59 IST

In the following program, an array of integer data to be initialized.

During the initialization, if a user enters a value other than integer value, then it will throw InputMismatchException exception.

On the occurrence of such an exception, your program should print “You entered bad data.”

If there is no such exception it will print the total sum of the array.

Your last recorded submission was on 2025-02-21, 07:59 IST
Select the Language for this assignment. 
File name for this program : 
1
//Prefixed Fixed Code:
2
import java.util.Scanner;
3
import java.util.InputMismatchException;
4
 
5
public class W05_P4 {
6
  public static void main(String[] args) {
7
      Scanner sc = new Scanner(System.in); 
8
    int length = sc.nextInt(); 
9
    // create an array to save user input 
10
    int[] name = new int[length];
11
     int sum=0;//save the total sum of the array.
12
try{
13
       for(int i=0;i<length;i++){  
14
          int userInput=sc.nextInt();
15
          name[i] = userInput;
16
          sum=sum+name[i]; 
17
          } 
18
        System.out.print(sum);
19
        }
20
       catch(InputMismatchException e) {
21
        System.out.print("You entered bad data.");
22
        }
0
}
1
}
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
3
5 2 1
8
8
Passed
Test Case 2
2
1 h
You entered bad data.
You entered bad data.
Passed



Week 05 : Programming Assignment 5

Due on 2025-02-27, 23:59 IST

In the following program, there may be multiple exceptions.

You have to complete the code using only one try-catch block to handle all the possible exceptions.

For example, if user’s input is 1, then it will throw and catch “java.lang.NullPointerException“.

Your last recorded submission was on 2025-02-21, 08:00 IST
Select the Language for this assignment. 
File name for this program : 
1
import java.util.Scanner;
2
public class W05_P5{
3
      public static void main (String   args[ ] ) {
4
        Scanner scan = new Scanner(System.in);
5
          int i=scan.nextInt();
6
          int j;
7
try {
8
             switch (i) {
9
            case 0 : 
10
            int zero = 0; 
11
            j = 92/ zero;       
12
            break;
13
            case 1 : 
14
            int b[ ] = null; 
15
            j = b[0] ;  
16
            break;
17
               default:
18
               System.out.print("No exception");
19
            }       
20
          }
21
            // catch block          
22
        catch (Exception e) {       
23
           System.out.print(e) ;
24
        }
0
}
1
}
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
5
No exception
No exception
Passed
Test Case 2
1
java.lang.NullPointerException
java.lang.NullPointerException
Passed
Test Case 3
0
java.lang.ArithmeticException: / by zero
java.lang.ArithmeticException: / by zero
Passed




Week 06 : Programming Assignment 1

Due on 2025-03-06, 23:59 IST

Complete the code segment to print the following using the concept of extending the Thread class in Java:

-----------------OUTPUT-------------------

Thread is Running.

-------------------------------------------------

Your last recorded submission was on 2025-02-21, 08:01 IST
Select the Language for this assignment. 
File name for this program : 
1
// Modify the code to extend the Thread class to complete the class Question61.
2
public class W06_P1 extends Thread{
3
    public void run(){
4
        System.out.print("Thread is Running.");
5
    }
0
public static void main(String args[]){  
1
 
2
        // Creating object of thread class
3
        W06_P1 thread=new W06_P1();  
4
 
5
                // Start the thread
6
        thread.start();
7
    }  
8
}
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
NA
Thread is Running.
Thread is Running.
Passed



Week 06 : Programming Assignment 2

Due on 2025-03-06, 23:59 IST

In the following program, a thread class ThreadRun is created using the Runnable interface which prints "Thread using Runnable interface". Complete the main class to create a thread object of the class ThreadRun and run the thread.

Your last recorded submission was on 2025-02-21, 08:19 IST
Select the Language for this assignment. 
File name for this program : 
1
class ThreadRun implements Runnable {
2
        public void run(){ 
3
            System.out.print("Thread using Runnable interface."); 
4
        } 
5
   }
6
// Create main class W06_P2 with main() method and appropriate statements in it
7
public class W06_P2{  
8
    public static void main(String[] args) {  
9
        ThreadRun ex = new ThreadRun();  
10
        Thread t1= new Thread(ex);
11
        t1.start();
12
    }
13
}
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
NA
Thread using Runnable interface.
Thread using Runnable interface.
Passed



Week 06 : Programming Assignment 3

Due on 2025-03-06, 23:59 IST

A part of the Java program is given, which can be completed in many ways, for example using the concept of thread, etc.  Follow the given code and complete the program so that your program prints the message "NPTEL Java". Your program should utilize the given interface/ class.

 

Your last recorded submission was on 2025-02-21, 08:05 IST
Select the Language for this assignment. 
File name for this program : 
1
// Interface A is defined with an abstract method run()
2
interface A {
3
    public abstract void run();
4
}
5
 
6
// Class B is defined which implements A and an empty implementation of run()
7
class B implements A {
8
    public void run() {}
9
}
10
class MyThread extends B {
11
    // run() is overriden and 'NPTEL Java' is printed.
12
    public void run() {
13
        System.out.print("NPTEL Java");
14
    }
15
}
0
// Main class Question is defined
1
public class W06_P3{
2
     public static void main(String[] args) {
3
         // An object of MyThread class is created
4
         MyThread t = new MyThread();
5
         // run() of class MyThread is called
6
         t.run();
7
     }
8
}
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
NA
NPTEL Java
NPTEL Java
Passed



Week 06 : Programming Assignment 4

Due on 2025-03-06, 23:59 IST

Execution of two or more threads occurs in a random order. The keyword synchronized in Java is used to control the execution of threads in a specific sequence. In the following program, some numbers are expected to be printed. Use the synchronized keyword appropriately to ensure that the program prints the output in the following order:

-----------------OUTPUT-------------------

5

10

15

20

25

100

200

300

400

500

-------------------------------------------------

 

Your last recorded submission was on 2025-02-21, 08:08 IST
Select the Language for this assignment. 
File name for this program : 
1
class Execute{
2
// Just add 'synchronized' in the method
3
synchronized void print(int n){
4
   for(int i=1;i<=5;i++){  
5
     System.out.println(n*i);  
6
     try{  
7
      Thread.sleep(400);  
8
     }catch(Exception e){
9
        System.out.println(e);
10
     }  
11
   }
12
 }
0
} // Ending Execute class
1
 
2
class Thread1 extends Thread{  
3
    Execute t;  
4
    Thread1(Execute t){  
5
        this.t=t;  
6
    }  
7
    public void run(){  
8
        t.print(5);  
9
    } 
10
}  
11
 
12
class Thread2 extends Thread{  
13
    Execute t;  
14
    Thread2(Execute t){  
15
        this.t=t;  
16
    }  
17
    public void run(){  
18
        t.print(100);  
19
    }  
20
}  
21
  
22
public class W06_P4{  
23
    public static void main(String args[]){  
24
        Execute obj = new Execute();//only one object  
25
        Thread1 t1=new Thread1(obj);  
26
        Thread2 t2=new Thread2(obj);  
27
        t1.start();  
28
        t2.start();  
29
    }  
30
}
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
NA
5\n
10\n
15\n
20\n
25\n
100\n
200\n
300\n
400\n
500
5\n
10\n
15\n
20\n
25\n
100\n
200\n
300\n
400\n
500\n
Passed after ignoring Presentation Error



Week 06 : Programming Assignment 5

Due on 2025-03-06, 23:59 IST

Add necessary codes to print the following:

-----------------OUTPUT-------------------

Name of thread 't':Thread-0

New name of thread 't':NPTEL

Thread is running.

-------------------------------------------------

Your last recorded submission was on 2025-02-21, 08:09 IST
Select the Language for this assignment. 
File name for this program : 
1
class W06_P5 extends Thread{  
2
  public void run(){  
3
    System.out.println("Thread is running.");  
4
  }  
5
 public static void main(String args[]){  
6
    W06_P5 t=new W06_P5();  
7
    System.out.println("Name of thread 't':"+ t.getName());
8
// start the thread  
9
  t.start();  
10
// set the name
11
  t.setName("NPTEL");
0
System.out.println("New name of thread 't':"+ t.getName());  
1
 }  
2
}
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
NA
Name of thread 't':Thread-0\n
New name of thread 't':NPTEL\n
Thread is running.
Name of thread 't':Thread-0\n
New name of thread 't':NPTEL\n
Thread is running.\n
Passed after ignoring Presentation Error




Week 07 : Programming Assignment 1

Due on 2025-03-13, 23:59 IST

Implement a Simple Calculator

Calculator class is provided. Your task is to implement the following:

  • A parameterized constructor to initialize two numbers.

  • Methods for addition, subtraction, multiplication, and division.

  • The division method should handle division by zero and print "Cannot divide by zero!" if attempted.

Follow the naming conventions in the given template code.

Your last recorded submission was on 2025-03-12, 07:12 IST
Select the Language for this assignment. 
File name for this program : 
1
import java.util.Scanner;
2
 
3
class W07_1 {
4
    private int num1;
5
    private int num2;
6
// Constructor to initialize the numbers
7
    public W07_1(int num1, int num2) {
8
        this.num1 = num1;
9
        this.num2 = num2;
10
    }
11
// Method for addition
12
    public int add() {
13
        return num1 + num2;
14
    }
15
    // Method for subtraction
16
    public int subtract() {
17
        return num1 - num2;
18
    }
19
    // Method for multiplication
20
    public int multiply() {
21
        return num1 * num2;
22
    }
23
    // Method for division, handles division by zero
24
    public int divide() {
25
        if (num2 == 0) {
26
            System.out.println("Cannot divide by zero!");
27
            return 0; // You might want to return a different value or throw an exception
28
        }
29
        return num1 / num2;
30
    }
0
public static void main(String[] args) {
1
        Scanner scanner = new Scanner(System.in);
2
        int a = scanner.nextInt();
3
        int b = scanner.nextInt();
4
 
5
        W07_1 calc = new W07_1(a, b);
6
        System.out.println("Sum: " + calc.add());
7
        System.out.println("Difference: " + calc.subtract());
8
        System.out.println("Product: " + calc.multiply());
9
        System.out.println("Quotient: " + calc.divide());
10
 
11
        scanner.close();
12
    }
13
}
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
10 5
Sum: 15\n
Difference: 5\n
Product: 50\n
Quotient: 2
Sum: 15\n
Difference: 5\n
Product: 50\n
Quotient: 2\n
Passed after ignoring Presentation Error



Week 07 : Programming Assignment 2

Due on 2025-03-13, 23:59 IST

 Implement a Simple Counter

Counter class is provided. Implement:

  • A constructor initializing the counter to zero.

  • Methods to increment()decrement(), and getValue().

  • Ensure the counter does not go below zero.

Your last recorded submission was on 2025-03-12, 07:18 IST
Select the Language for this assignment. 
File name for this program : 
1
import java.util.Scanner;
2
 
3
class Counter {
4
    private int count;
5
// Constructor to initialize the counter to zero
6
    public Counter() {
7
        count = 0;
8
    }
9
    // Method to increment the counter by 1
10
    public void increment() {
11
        count++;
12
    }
13
    // Method to decrement the counter by 1, ensuring it does not go below zero
14
    public void decrement() {
15
        if (count > 0) {
16
            count--;
17
        }
18
    }
19
    // Method to return the current value of the counter
20
    public int getValue() {
21
        return count;
22
    }
0
}
1
public class W07_2 {
2
    public static void main(String[] args) {
3
        Counter counter = new Counter();
4
        counter.increment();
5
        counter.increment();
6
        counter.decrement();
7
        System.out.println(counter.getValue()); // Output: 1
8
    }
9
}
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
NA
1
1\n
Passed after ignoring Presentation Error



Week 07 : Programming Assignment 3

Due on 2025-03-13, 23:59 IST

 Implement a Basic Employee Class

An Employee class is provided. Implement:

  • A constructor to initialize name and salary.

  • A method getDetails() to return "Employee: Name, Salary: X" format.

Example Input:
Alice 50000

Example Output:
Employee: Alice, Salary: 50000

Your last recorded submission was on 2025-03-12, 07:20 IST
Select the Language for this assignment. 
File name for this program : 
1
import java.util.Scanner;
2
 
3
class Employee {
4
    private String name;
5
    private double salary;
6
// Constructor to initialize name and salary
7
    public Employee(String name, double salary) {
8
        this.name = name;
9
        this.salary = salary;
10
    }
11
    // Method to return employee details in the required format
12
    public String getDetails() {
13
        return "Employee: " + name + ", Salary: " + salary;
14
    }
15
}
0
public class W07_3 {
1
    public static void main(String[] args) {
2
        Scanner scanner = new Scanner(System.in);
3
        String empName = scanner.next();
4
        double empSalary = scanner.nextDouble();
5
 
6
        Employee emp = new Employee(empName, empSalary);
7
        System.out.print(emp.getDetails());
8
 
9
        scanner.close();
10
    }
11
}
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
Deepak 50000
Employee: Deepak, Salary: 50000.0
Employee: Deepak, Salary: 50000.0
Passed



Week 07 : Programming Assignment 4

Due on 2025-03-13, 23:59 IST

Implement a Simple Array Processor

You need to complete the implementation of the getMax() method inside the NumberArray class. This method should return the largest number from the array.

Tasks:

  1. Complete the getMax() method in the template section.
  2. The method should iterate through the array and find the largest value.

Example Input:

3 8 1 5 7

Example Output:
Max: 8, Min: 1

Your last recorded submission was on 2025-03-12, 07:24 IST
Select the Language for this assignment. 
File name for this program : 
1
import java.util.Scanner;
2
 
3
 
4
 
5
// Class to store and process an array of numbers
6
class NumberArray {
7
    private int[] numbers; // This array will store the numbers given by the user
8
 
9
    // Constructor to initialize the array
10
    public NumberArray(int[] numbers) {
11
        this.numbers = numbers;
12
    }
13
// Method to find and return the largest number in the array
14
    public int getMax() {
15
        int max = numbers[0]; // Initialize max with the first element
16
        for (int num : numbers) {
17
            if (num > max) {
18
                max = num; // Update max if a larger number is found
19
            }
20
        }
21
        return max; // Return the largest number found
22
    }
23
    // Method to find and return the smallest number in the array
24
    public int getMin() {
25
        int min = numbers[0]; // Assume the first element is the smallest
26
        for (int num : numbers) {
27
            if (num < min) {
28
                min = num;
29
            }
30
        }
31
        return min; // Return the smallest number found
32
    }
33
}
0
// ==========================================================
1
// Main class to test the NumberArray class
2
public class W07_4 {
3
    public static void main(String[] args) {
4
        Scanner scanner = new Scanner(System.in);
5
 
6
        // Read 5 integers from the user and store them in an array
7
        int[] arr = new int[5]; // Create an array of size 5
8
        for (int i = 0; i < arr.length; i++) {
9
            arr[i] = scanner.nextInt(); // Read numbers from user
10
        }
11
 
12
        // Create an instance of NumberArray and print max & min values
13
        NumberArray numArray = new NumberArray(arr);
14
        System.out.println("Max: " + numArray.getMax() + ", Min: " + numArray.getMin());
15
 
16
        scanner.close(); // Close scanner to free resources
17
    }
18
}
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
3 8 1 5 7
Max: 8, Min: 1
Max: 8, Min: 1\n
Passed after ignoring Presentation Error



Week 07 : Programming Assignment 5

Due on 2025-03-13, 23:59 IST

 Implement a Simple Password Validator

In this task, you need to implement a password validation system using Java. The goal is to check if a given password meets the following conditions:

  1. Minimum Length Requirement: The password must be at least 8 characters long.
  2. Uppercase Letter Requirement: The password must contain at least one uppercase letter (A-Z).
  3. Number Requirement: The password must contain at least one numeric digit (0-9).

If the password meets all three conditions, print "Valid Password". Otherwise, print "Invalid Password".

Input Format:

  • single string representing the password (can contain alphabets, numbers, and special characters).

Output Format:

  • Print "Valid Password" if the password satisfies all the conditions.
  • Otherwise, print "Invalid Password".

Example Input:
Password123


Example Output:
Valid Password

Your last recorded submission was on 2025-03-12, 07:27 IST
Select the Language for this assignment. 
File name for this program : 
1
import java.util.Scanner;
2
 
3
public class W07_5 {
4
    private String password;
5
 
6
    // Step 1: Constructor to initialize the password variable
7
    public W07_5(String password) { 
8
        this.password = password; // Assign the passed password to the instance variable
9
    }
10
    // ================================
11
    // Note: Try solving it without hints first-only check if you're truly stuck.
12
    // Avoid AI or internet searches; quick answers won't build real skills.
13
    // Struggle a bit, learn for life! Be honest with yourself!
14
    //
15
    public boolean isValidPassword(String p) {
16
        // Step 1: Check if the password length is at least 8 characters
17
        if (password.length() < 8) {
18
            return false;
19
        }
20
        // Flag to track if there is an uppercase letter
21
        boolean hasUpperCase = false;
22
        // Flag to track if there is a number
23
        boolean hasDigit = false;
24
        // Step 2: Loop through each character in the password
25
        for (char ch : password.toCharArray()) {
26
            if (Character.isUpperCase(ch)) {
27
                hasUpperCase = true; // Found an uppercase letter
28
            }
29
            if (Character.isDigit(ch)) {
30
                hasDigit = true; // Found a number
31
            }
32
            // If both conditions are met, no need to check further
33
            if (hasUpperCase && hasDigit) {
34
                return true;
35
            }
36
        }
37
        // Step 3: If either condition is not met, return false
38
        return false;
39
    }
0
public static void main(String[] args) {
1
        Scanner scanner = new Scanner(System.in);
2
        // Read password input from user
3
        String inputPassword = scanner.nextLine();
4
        scanner.close();
5
        W07_5 validator = new W07_5(inputPassword);
6
        
7
        // Check password validity and print result
8
        if (validator.isValidPassword(inputPassword)) {
9
            System.out.print("Valid Password");
10
        } else {
11
            System.out.print("Invalid Password");
12
        }
13
  
14
        scanner.close();
15
    }
16
  }
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
Password123
Valid Password
Valid Password
Passed



Week 08 : Programming Assignment 1

Due on 2025-03-20, 23:59 IST
 Write a Java program that reads a positive integer from the user and computes the sum of its digits.
 
  Expected Input/Output:
 Input: 123
 Output: 6
Your last recorded submission was on 2025-03-15, 15:52 IST
Select the Language for this assignment. 
File name for this program : 
1
import java.util.Scanner;
2
 
3
public class W08_P1 {
4
    public static void main(String[] args) {
5
        Scanner scanner = new Scanner(System.in);
6
        
7
        
8
        int number = scanner.nextInt();
9
        int sum = 0;
10
        while (number > 0) {
11
            int digit = number % 10; // Extract the last digit
12
            sum += digit; // Add the digit to the sum
13
            number /= 10; // Remove the last digit
14
        }
15
        System.out.print(sum);
0
scanner.close();
1
    }
2
}
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
640
10
10
Passed



Week 08 : Programming Assignment 2

Due on 2025-03-20, 23:59 IST
Write a Java program that reads an integer from the user and computes its factorial.
 Factorial of a number n is calculated as: n! = n * (n-1) * (n-2) * ... * 1
 Assume the input is a non-negative integer.
Select the Language for this assignment. 
File name for this program : 
1
import java.util.Scanner;
2
 
3
public class W08_P2 {
4
    public static void main(String[] args) {
5
        Scanner scanner = new Scanner(System.in);
6
        
7
       
8
        int n = scanner.nextInt();
9
        long factorial = 1;
10
        if (n == 0) {
11
            factorial = 1;
12
        } else {
13
            for (int i = 1; i <= n; i++) {
14
                factorial *= i;
15
            }
16
        }
17
        System.out.print(factorial);
0
scanner.close();
1
    }
2
}
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
5
120
120
Passed



Week 08 : Programming Assignment 3

Due on 2025-03-20, 23:59 IST
Write a Java program that reads a positive integer from the user and prints its reverse.

Expected Input/Output:
 Input: 1234
 Output: 4321

Your last recorded submission was on 2025-03-15, 16:15 IST
Select the Language for this assignment. 
File name for this program : 
1
import java.util.Scanner;
2
 
3
public class W08_P3 {
4
    public static void main(String[] args) {
5
        Scanner scanner = new Scanner(System.in);
6
        
7
        
8
        int number = scanner.nextInt();
9
        int reversedNumber = 0;
10
        while (number != 0) {
11
            int digit = number % 10;
12
            reversedNumber = reversedNumber * 10 + digit;
13
            number /= 10;
14
        }
15
        System.out.print(reversedNumber);
0
scanner.close();
1
    }
2
}
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
1005
5001
5001
Passed



Week 08 : Programming Assignment 4

Due on 2025-03-20, 23:59 IST
 Write a Java program that reads an integer and determines if it is a prime number.
 A prime number is only divisible by 1 and itself.

Expected Input/Output:
Input: 7
Output: Prime
Select the Language for this assignment. 
File name for this program : 
1
import java.util.Scanner;
2
 
3
public class W08_P4 {
4
    public static void main(String[] args) {
5
        Scanner scanner = new Scanner(System.in);
6
        
7
        
8
        int number = scanner.nextInt();
9
        if (number < 2) {
10
            System.out.print("Not Prime");
11
        } else {
12
            boolean isPrime = true;
13
            for (int i = 2; i <= Math.sqrt(number); i++) {
14
                if (number % i == 0) {
15
                    isPrime = false;
16
                    break;
17
                }
18
            }
19
            if (isPrime) {
20
                System.out.print("Prime");
21
            } else {
22
                System.out.print("Not Prime");
23
            }
24
        }
0
scanner.close();
1
    }
2
}
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
10
Not Prime
Not Prime
Passed



Week 08 : Programming Assignment 5

Due on 2025-03-20, 23:59 IST
Write a Java program to perform matrix multiplication.
The program should:
  •  - Read two matrices from user input.
  •  - Validate that matrix multiplication is possible (columns of first == rows of second).
  •  - Compute the product of the matrices.
  •  - Display the resulting matrix.
 
  Expected Input/Output:

  Input:
  2 3  \ (Rows and Columns of first matrix)
  1 2 3
  4 5 6
  3 2  \ (Rows and Columns of second matrix)
  7 8
  9 10
  11 12

  Output:
  58 64
  139 154
 ----------------------
 Input:
 2 2
 1 2
  3 4
  2 2
  2 0
  1 3

  Output:
  4 6
  10 12
 
Select the Language for this assignment. 
File name for this program : 
1
import java.util.Scanner;
2
 
3
public class W08_P5 {
4
    public static void main(String[] args) {
5
        Scanner scanner = new Scanner(System.in);
6
        
7
        
8
        int rows1 = scanner.nextInt();
9
        int cols1 = scanner.nextInt();
10
        int[][] matrix1 = new int[rows1][cols1];
11
        for (int i = 0; i < rows1; i++) {
12
            for (int j = 0; j < cols1; j++) {
13
                matrix1[i][j] = scanner.nextInt();
14
            }
15
        }
16
        
17
        int rows2 = scanner.nextInt();
18
        int cols2 = scanner.nextInt();
19
        int[][] matrix2 = new int[rows2][cols2];
20
        for (int i = 0; i < rows2; i++) {
21
            for (int j = 0; j < cols2; j++) {
22
                matrix2[i][j] = scanner.nextInt();
23
            }
24
        }
25
        if (cols1 != rows2) {
26
            System.out.println("Multiplication Not Possible");
27
            return;
28
        }
29
        int[][] result = new int[rows1][cols2];
30
        for (int i = 0; i <  rows1 ; i++) {
31
            for (int j = 0; j <  cols2 ; j++) {
32
                for (int k = 0; k <  cols1 ; k++) {
33
                    result[i][j] +=  matrix1[i][k] * matrix2[k][j] ;
34
                }
35
            }
36
        }
37
        for (int i = 0; i < rows1; i++) {
38
            for (int j = 0; j <  cols2 ; j++) {
39
                System.out.print( result[i][j] );
40
                if (j < cols2 - 1) {
41
                    System.out.print(" "); // Ensure no trailing space at end of row
42
                }
43
            }
44
            System.out.println(); // Move to next row
45
        }
0
scanner.close();
1
    }
2
}
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
2 3
  1 2 3
  4 5 6
  3 2
  7 8
  9 10
  11 12
58 64\n
139 154
58 64\n
139 154\n
Passed after ignoring Presentation Error




Week 09 : Programming Assignment 1

Due on 2025-03-27, 23:59 IST

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.

Select the Language for this assignment. 
File name for this program : 
1
import java.util.Scanner;
2
public class Question91{
3
    public static void main(String args[]){
4
        Scanner sc = new Scanner(System.in);
5
// Declare the 5X5 2D array to store the input
6
        char original[][]= new char[5][5];
7
        // Input 2D Array using Scanner Class and check data validity
8
        for(int line=0;line<5; line++){
9
            String input = sc.nextLine();
10
            char seq[] = input.toCharArray();
11
            if(seq.length==5){
12
                for(int i=0;i<5;i++){
13
                    if(seq[i]=='0' || seq[i]=='1'){
14
                        original[line][i]=seq[i];
15
                        if(line==4 && i==4)
16
                            flipflop(original);
17
                    }
18
                    else{
19
                        System.out.print("Only 0 and 1 supported.");
20
                        break;
21
                    }
22
                }
23
            }else{
24
                System.out.print("Invalid length");
25
                break;
26
            }
27
        }
28
    }
29
    static void flipflop(char[][] flip){
30
        // Flip-Flop Operation
31
        for(int i=0; i<5;i++){
32
            for(int j=0; j<5;j++){      
33
                if(flip[i][j]=='1')
34
                    flip[i][j]='0';
35
                else
36
                    flip[i][j]='1';
37
            }
38
        }
39
        // Output the 2D FlipFlopped Array
40
        for(int i=0; i<5;i++){
41
            for(int j=0; j<5;j++){      
42
                System.out.print(flip[i][j]);
43
            }
44
            System.out.println();
45
        }
0
} // The main() ends here
1
} // The main class ends here
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
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

Due on 2025-03-27, 23:59 IST

A program needs to be developed which can mirror reflect any 5 × 5 2D character array into its side-by-side reflection. Write suitable code to achieve this transformation as shown below:

 INPUT:                                       OUTPUT:
               OOXOO                                        OOXOO
               OOXOO                                        OOXOO
               XXXOO                                        OOXXX
               OOOOO                                        OOOOO
               XOABC                                        CBAOX

Note the following points carefully
:
1. Here, instead of X and O any character may be present.

2. The input and output array size must be of dimension 5 × 5 and nothing else.
3. Only side-by-side reflection should be performed i.e. ABC || CBA.

 

Select the Language for this assignment. 
File name for this program : 
1
import java.util.Scanner;
2
public class Question92{
3
    public static void main(String args[]){
4
        Scanner sc = new Scanner(System.in);
5
// Declaring 5x5 2D char array to store input
6
        char original[][]= new char[5][5];
7
        // Declaring 5x5 2D char array to store reflection
8
        char reflection[][]= new char[5][5];
9
        // Input 2D Array using Scanner Class
10
        for(int line=0;line<5; line++){
11
            String input = sc.nextLine();
12
            char seq[] = input.toCharArray();
13
            if(seq.length==5){
14
                for(int i=0;i<5;i++){
15
                    original[line][i]=seq[i];
16
                }
17
            }
18
        }
19
        // Performing the reflection operation
20
        for(int i=0; i<5;i++){
21
            for(int j=0; j<5;j++){      
22
                reflection[i][j]=original[i][4-j];
23
            }
24
        }
25
        // Output the 2D Reflection Array
26
        for(int i=0; i<5;i++){
27
            for(int j=0; j<5;j++){      
28
                System.out.print(reflection[i][j]);
29
            }
30
            System.out.println();
31
        }
0
} // The main() method ends here
1
} // The main class end
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
OOXOO
OOXOO
XXXOO
OOOOO
XOABC
OOXOO\n
OOXOO\n
OOXXX\n
OOOOO\n
CBAOX
OOXOO\n
OOXOO\n
OOXXX\n
OOOOO\n
CBAOX\n
Passed after ignoring Presentation Error



Week 09 : Programming Assignment 3

Due on 2025-03-27, 23:59 IST

Complete the code to perform a 45 degree anti clock wise rotation with respect to the center of a 5 × 5 2D Array as shown below:

INPUT:

              00100

              00100

              11111

              00100

              00100


OUTPUT:


              10001

              01010

              00100

              01010

              10001


Note the following points carefully
:
1. Here, instead of 0 and 1 any character may be given.

2. The input and output array size must be of dimension 5 × 5 and nothing else.


Select the Language for this assignment. 
File name for this program : 
1
import java.util.Scanner;
2
public class Question93{
3
    public static void main(String args[]){
4
        Scanner sc = new Scanner(System.in);
5
char arr[][]= new char[5][5];
6
            // Input 2D Array using Scanner Class
7
            for(int line=0;line<5; line++){
8
                String input = sc.nextLine();
9
                char seq[] = input.toCharArray();
10
                if(seq.length==5){
11
                    for(int i=0;i<5;i++){
12
                        arr[line][i]=seq[i];
13
                    }
14
                }else{
15
                    System.out.print("Wrong Input!");
16
                    System.exit(0);
17
                }
18
            }
19
            // Declaring the array to store Transition
20
            char tra[][] = new char[5][5];
21
            String outer[]={"00","10","20","30",
22
                            "40","41","42","43",
23
                            "44","34","24","14",
24
                            "04","03","02","01"};           
25
            String inner[]={"11","21","31","32",
26
                            "33","23","13","12"};
27
            // 45-Degree rotation
28
            for(int i=0;i<5;i++){
29
                for(int j=0;j<5;j++){
30
                    // Transform outer portion
31
                    for(int k=0; k<outer.length; k++){
32
                        char indices[]=outer[k].toCharArray();
33
                        int a = Integer.parseInt(String.valueOf(indices[0]));
34
                        int b = Integer.parseInt(String.valueOf(indices[1]));
35
                        if(a==i && b==j){
36
                            if(k==15){k=1;}
37
                            else if(k==14){k=0;}
38
                            else {k+=2;}
39
                            indices=outer[k].toCharArray();
40
                            a = Integer.parseInt(String.valueOf(indices[0]));
41
                            b = Integer.parseInt(String.valueOf(indices[1]));
42
                            tra[a][b] = arr[i][j];
43
                            break;
44
                        }
45
                    }
46
                    // Transform inner portion
47
                    for(int k=0; k<inner.length; k++){
48
                        char indices[]=inner[k].toCharArray();
49
                        int a = Integer.parseInt(String.valueOf(indices[0]));
50
                        int b = Integer.parseInt(String.valueOf(indices[1]));
51
                        if(a==i && b==j){
52
                            if(k==7){k=0;}
53
                            else {k+=1;}
54
                            indices=inner[k].toCharArray();
55
                            a = Integer.parseInt(String.valueOf(indices[0]));
56
                            b = Integer.parseInt(String.valueOf(indices[1]));
57
                            tra[a][b] = arr[i][j];
58
                            break;
59
                        }
60
                    }
61
                    // Keeping center same
62
                    tra[2][2] = arr[2][2];
63
                }
64
            }
65
            // Print the transformed output 
66
            for(int i=0;i<5;i++){
67
                for(int j=0;j<5;j++){
68
                    System.out.print(tra[i][j]);
69
                }
70
                System.out.println();
71
            }
0
} // The main() method ends here
1
} // The main class ends here
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
00100
00100
11111
00100
00100
10001\n
01010\n
00100\n
01010\n
10001
10001\n
01010\n
00100\n
01010\n
10001\n
Passed after ignoring Presentation Error



Week 09 : Programming Assignment 4

Due on 2025-03-27, 23:59 IST

Complete the code to develop an ADVANCED CALCULATOR that emulates all the functions of the GUI Calculator as shown in the image.

Note the following points carefully:
1. Use only double datatype to store all numeric values.
2. Each button on the calculator should be operated by typing the characters from 'a' to 'p'.
3. To calculate 25-6, User should input fjhkc (where, f for 2, j for 5, h for '-', k for 6 and c for '=' ).
3. You may use the already defined function 
gui_map(char).
4. Without '=', operations won't give output as shown in Input_2 and Output_2 example below.
5. The calculator should be able to perform required operations on two operands as shown in the below example:


Input_1:
                   klgc

Output_1:
                        
18.0

Select the Language for this assignment. 
File name for this program : 
1
import java.util.Scanner;
2
public class Question94{
3
    public static void main(String args[]){
4
        Scanner sc = new Scanner(System.in);
5
        String input = sc.nextLine();
6
        char seq[] = input.toCharArray();
7
        int outflag=0;
8
        // Start the mapping process for each input character
9
        for(int i=0; i<seq.length; i++){
10
            seq[i]=gui_map(seq[i]);
11
        }
12
        //Print Mapped GUI (remove comment to see the mapped sequence input)
13
        /*
14
        for(int i=0; i<seq.length; i++){
15
            System.out.print(seq[i]);
16
        }
17
        */
18
        // Use double type of values for entire calculation
19
        double operand1=0.0;
20
        String o1="";
21
        double operand2=0.0;
22
        String o2="";
23
        double output=0.0;
24
        // Perform calculaton operations
25
        outerloop:
26
        for(int i=0; i<seq.length; i++){
27
            int r=0;
28
            if(seq[i]=='+'||seq[i]=='-'||seq[i]=='/'||seq[i]=='X'||seq[i]=='='){
29
                for(int j=0; j<i; j++){
30
                    o1+=Character.toString(seq[j]);
31
                }
32
                operand1=Double.parseDouble(o1);
33
                for(int k=i+1; k<seq.length; k++){
34
                    if(seq[k]=='='){
35
                        outflag=1;
36
                        operand2=Double.parseDouble(o2);
37
                        if(seq[i]=='+'){
38
                            output=operand1+operand2;
39
                        }else if(seq[i]=='-'){
40
                            output=operand1-operand2;
41
                        }else if(seq[i]=='/'){
42
                            output=operand1/operand2;
43
                        }else if(seq[i]=='X'){
44
                            output=operand1*operand2;
45
                        }
46
                        break outerloop;
47
                    }else{
48
                        o2+=Character.toString(seq[k]);
49
                    }
50
                }
51
            }
52
        }
53
        // Check if output is available and print the output
54
        if(outflag==1)
55
            System.out.print(output);
0
}// The main() method ends here.
1
    
2
// A method that takes a character as input and returns the corresponding GUI character 
3
    static char gui_map(char in){
4
        char out = 'N';// N = Null/Empty
5
        char gm[][]={{'a','.'}
6
                    ,{'b','0'}
7
                    ,{'c','='}
8
                    ,{'d','+'}
9
                    ,{'e','1'}
10
                    ,{'f','2'}
11
                    ,{'g','3'}
12
                    ,{'h','-'}
13
                    ,{'i','4'}
14
                    ,{'j','5'}
15
                    ,{'k','6'}
16
                    ,{'l','X'}
17
                    ,{'m','7'}
18
                    ,{'n','8'}
19
                    ,{'o','9'}
20
                    ,{'p','/'}};
21
                    
22
        // Checking for maps
23
        for(int i=0; i<gm.length; i++){
24
            if(gm[i][0]==in){
25
                out=gm[i][1];
26
                break;
27
            }
28
        }
29
        return out;
30
    }
31
}
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
klgc
18.0
18.0
Passed



Week 09 : Programming Assignment 5

Due on 2025-03-27, 23:59 IST

Complete the code to develop a BASIC CALCULATOR that can perform operations like AdditionSubtractionMultiplication 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

 

Select the Language for this assignment. 
File name for this program : 
1
import java.util.Scanner;
2
public class Question95{
3
    public static void main(String args[]){
4
        Scanner sc = new Scanner(System.in);
5
        String input = sc.nextLine(); // Read as string, e.g., 5+6
6
        // Declare and initialize the required variable(s)
7
        int i=0;
8
        int j=0;
9
        double output=0;
10
        // Split the input string into character array
11
        char seq[] = input.toCharArray();
12
        /*
13
        Use some method to separate the two operands
14
        and then perform the required operation.
15
        */
16
        for(int a=0; a<seq.length; a++){
17
            if(seq[a]=='+'){
18
                i= Integer.parseInt(input.substring(0,a));
19
                j= Integer.parseInt(input.substring(a+1,seq.length));
20
                output = (double)i+j;
21
            }else if(seq[a]=='-'){
22
                i= Integer.parseInt(input.substring(0,a));
23
                j= Integer.parseInt(input.substring(a+1,seq.length));
24
                output = (double)i-j;
25
            }else if(seq[a]=='/'){
26
                i= Integer.parseInt(input.substring(0,a));
27
                j= Integer.parseInt(input.substring(a+1,seq.length));
28
                output = (double)i/j;
29
            }else if(seq[a]=='*'){
30
                i= Integer.parseInt(input.substring(0,a));
31
                j= Integer.parseInt(input.substring(a+1,seq.length));
32
                output = (double)i*j;
33
            }
34
        }
35
        // Print the output as stated in the question
36
        System.out.print(input+" = " + Math.round(output));
0
}
1
}
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
5+6
5+6 = 11
5+6 = 11
Passed




Week 10 : Programming Assignment 1

Due on 2025-04-03, 23:59 IST
Import the Right Packages 

Write a Java program that connects to a database using JDBC (Java Database Connectivity).
However, the code will not compile unless you import the correct packages.
Your task is to add the correct import statements so that the program compiles and runs properly.

Even if you have never worked with JDBC, this is a basic puzzle-style task.
Simply use your understanding of Java import statements and hints in the code to figure out what to include at the top.

📌 Hint: JDBC is part of java.sql, and you might need java.lang too (which is imported automatically, but keep it for good practice).

Your last recorded submission was on 2025-03-29, 16:09 IST
Select the Language for this assignment. 
File name for this program : 
1
// ================================================
2
// NOTE TO STUDENTS:
3
// Try to solve the task on your own before referring to external help.
4
// Avoid using online answers or tools unless absolutely necessary.
5
// Struggling with the problem is a part of the learning process and will help you build long-term understanding.
6
// ================================================
7
 
8
// TODO: Add the necessary import statements below so that the program can compile and connect to a database using JDBC.
9
 
10
/*
11
 What is this program about?
12
 - The goal is to write a Java program that establishes a database connection using JDBC (Java Database Connectivity).
13
 
14
 Why are import statements important?
15
 - In Java, import statements allow you to use classes and interfaces that are part of external packages.
16
 - If required classes are not imported, the program will not compile.
17
 
18
 How should you approach this?
19
 - Read through the code and identify which classes are being used.
20
 - Determine which packages these classes belong to.
21
 
22
 Helpful guidelines:
23
 - All JDBC-related classes such as Connection and DriverManager are found in the java.sql package.
24
 - The java.lang package is automatically imported, but can be explicitly mentioned for clarity.
25
 
26
 Example:
27
 - If you see a class like Connection being used, import it using:
28
   import java.sql.Connection;
29
 
30
 Your task:
31
 - Identify the required classes.
32
 - Import them from the correct packages using proper syntax.
33
 - Do not include unnecessary imports.
34
*/
35
import java.sql.Connection;
36
import java.sql.DriverManager;
0
public class W10_P1 {
1
    public static void main(String args[]) {
2
        try {
3
            Connection conn = null;
4
            String DB_URL = "jdbc:sqlite:/tempfs/db";
5
            System.setProperty("org.sqlite.tmpdir", "/tempfs");
6
 
7
            // Try to connect to the database
8
            conn = DriverManager.getConnection(DB_URL);
9
            System.out.print(conn.isValid(1));
10
 
11
            conn.close();
12
        } catch (Exception e) {
13
            System.out.println(e);
14
        }
15
    }
16
}
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
NA
true
true
Passed



Week 10 : Programming Assignment 2

Due on 2025-04-03, 23:59 IST
Check if a JDBC Driver is Available

Java uses JDBC drivers to connect to different databases.
Each database (like SQLite, MySQL, PostgreSQL, etc.) has its own JDBC driver.

This program checks whether the SQLite JDBC driver is available in the classpath.
To do that, Java uses Class.forName(...) to try to load the driver class by its name.

Your task is to complete one line of code to load the SQLite driver and print true if the driver is successfully loaded.

This is a common step when using JDBC in real-world applications, and this exercise helps you get comfortable with how drivers are managed.

Your last recorded submission was on 2025-03-29, 11:45 IST
Select the Language for this assignment. 
File name for this program : 
1
import java.sql.*;  // Import required for JDBC classes
2
 
3
public class W10_P2 {
4
    public static void main(String[] args) {
5
        try {
6
            // We will attempt to load the SQLite JDBC driver class.
7
            // If successful, we'll print true.
8
            // If the driver class isn't available, we'll catch the error and print false.
9
// ================================================
10
            // NOTE TO STUDENTS:
11
            // Try to solve the task on your own before referring to external help.
12
            // Avoid using online sources or tools unless absolutely necessary.
13
            // Engaging with the problem independently will improve your understanding and confidence.
14
            // ================================================
15
 
16
            // TODO: Load the JDBC driver class for SQLite using Class.forName
17
 
18
            /*
19
             Hint (read only if necessary):
20
             - The Class.forName() method is used to load a class at runtime by its fully qualified name.
21
             - For the SQLite JDBC driver, the class name to load is: "org.sqlite.JDBC"
22
             
23
             Pseudocode:
24
             Class.forName("org.sqlite......");
25
            */
26
Class.forName("org.sqlite.JDBC");
0
// If the driver loads successfully, this line will execute.
1
            System.out.println(true);
2
        } catch (Exception e) {
3
            // If there is any error in loading the driver, this line will execute.
4
            System.out.println(false);
5
        }
6
    }
7
}
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
NA
true
true\n
Passed after ignoring Presentation Error



Week 10 : Programming Assignment 3

Due on 2025-04-03, 23:59 IST
Connect to a SQLite Database Using JDBC

Once a JDBC driver is available, the next step is to establish a connection to a database.
In this task, your job is to connect to a SQLite database using the correct JDBC method.

Java provides the class DriverManager with a method getConnection(String url) to establish the connection.

Your task is to complete the program by writing one line that uses DriverManager.getConnection(...) to connect to the database.

You are not required to write any SQL queries or manage database content.
The focus is on learning how to establish a basic JDBC connection.


Your last recorded submission was on 2025-03-29, 16:13 IST
Select the Language for this assignment. 
File name for this program : 
1
import java.sql.*; // Required for JDBC classes like Connection and DriverManager
2
 
3
public class W10_P3 {
4
    public static void main(String[] args) {
5
        try {
6
            // Set up a Connection reference to hold the database connection
7
            Connection conn = null;
8
 
9
            // JDBC URL string pointing to the SQLite database path
10
            String DB_URL = "jdbc:sqlite:/tempfs/studentdb";
11
 
12
            // This line sets a temporary directory for SQLite to avoid permission issues
13
            System.setProperty("org.sqlite.tmpdir", "/tempfs");
14
// ================================================
15
            // NOTE TO STUDENTS:
16
            // Try to solve the task on your own before referring to external help.
17
            // Avoid using online sources or tools unless absolutely necessary.
18
            // Engaging with the problem independently will improve your understanding and confidence.
19
            // ================================================
20
 
21
            // TODO: Establish a connection to the database using DriverManager.getConnection
22
 
23
            /*
24
             Hint (only if needed):
25
             - Use DriverManager.getConnection(...) method and pass DB_URL as the argument
26
             - Assign the returned Connection object to the variable 'conn'
27
 
28
             Pseudocode:
29
             conn = DriverManager.getConnection(......_URL);
30
            */
31
conn = DriverManager.getConnection(DB_URL);
0
// If the connection is successful, conn.isValid(1) will return true
1
            System.out.println(conn.isValid(1));
2
 
3
            // Always close the connection after use
4
            conn.close();
5
        } catch (Exception e) {
6
            System.out.println(e);
7
        }
8
    }
9
}
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
NA
true
true\n
Passed after ignoring Presentation Error



Week 10 : Programming Assignment 4

Due on 2025-04-03, 23:59 IST

Create a Table in a SQLite Database Using JDBC

Once a connection to a database is established, SQL commands can be executed using JDBC.
In this task, your job is to create a table named students with the following columns:

  • roll – an integer that represents the student’s roll number
  • name – a string (up to 30 characters) representing the student’s name

You will complete one line of code that executes a SQL CREATE TABLE statement using a Statement object.

You are not required to insert or retrieve any data — only to create the table using proper JDBC methods.

Your last recorded submission was on 2025-03-29, 16:14 IST
Select the Language for this assignment. 
File name for this program : 
1
import java.sql.*; // Required for JDBC classes
2
 
3
public class W10_P4 {
4
    public static void main(String[] args) {
5
        try {
6
            // Set SQLite temp directory to avoid native driver errors in restricted environments
7
            System.setProperty("org.sqlite.tmpdir", "/tempfs");
8
 
9
            // Create a connection to the SQLite database
10
            Connection conn = DriverManager.getConnection("jdbc:sqlite:/tempfs/studentdb");
11
 
12
            // Create a Statement object to send SQL statements to the database
13
            Statement stmt = conn.createStatement();
14
 
15
            // SQL query string to create the 'students' table
16
            String sql = "CREATE TABLE students(roll INTEGER, name VARCHAR(30))";
17
// ================================================
18
            // NOTE TO STUDENTS:
19
            // Try to solve the task on your own before referring to external help.
20
            // Avoid using online sources or tools unless absolutely necessary.
21
            // Engaging with the problem independently will improve your understanding and confidence.
22
            // ================================================
23
 
24
            // TODO: Execute the SQL command to create the table using the Statement object
25
 
26
            /*
27
             Hint (if needed):
28
             - Use the executeUpdate(...) method of the Statement object
29
             - Pass the SQL string variable 'sql' as the argument
30
 
31
             Pseudocode:
32
             stmt.executeUpdate(...Todo....);
33
            */
34
stmt.executeUpdate(sql);
0
// If the table is created without exceptions, print success
1
            System.out.println("success");
2
 
3
            // Close statement and connection to release resources
4
            stmt.close();
5
            conn.close();
6
        } catch (Exception e) {
7
            System.out.println(e);
8
        }
9
    }
10
}
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
NA
success
success\n
Passed after ignoring Presentation Error



Week 10 : Programming Assignment 5

Due on 2025-04-03, 23:59 IST

Insert a Record into a Table Using JDBC

Once a table is created in a database, we can insert records into it using SQL INSERT statements.
In this task, your goal is to insert a single student record into the existing students table.

You are provided with the following variables:

  • roll – an integer roll number
  • name – a string representing the student’s name

Your task is to write one line of code that inserts this data into the table using a PreparedStatement.

This is a common and safe way to insert data, as it avoids issues like SQL injection and improper formatting.

Your last recorded submission was on 2025-03-29, 16:15 IST
Select the Language for this assignment. 
File name for this program : 
1
import java.sql.*; // Required for JDBC classes
2
import java.util.*; // Required for Scanner input
3
 
4
public class W10_P5 {
5
    public static void main(String[] args) {
6
        try {
7
            Scanner sc = new Scanner(System.in);
8
 
9
            // Read input values
10
            int roll = sc.nextInt();
11
            sc.nextLine(); // consume newline
12
            String name = sc.nextLine();
13
 
14
            // Set SQLite temp directory to avoid native driver errors in restricted environments
15
            System.setProperty("org.sqlite.tmpdir", "/tempfs");
16
 
17
            // Connect to SQLite database
18
            Connection conn = DriverManager.getConnection("jdbc:sqlite:/tempfs/db");
19
 
20
            // Ensure the 'students' table exists (create it if it doesn't)
21
            Statement stmt = conn.createStatement();
22
            String createTableQuery = "CREATE TABLE IF NOT EXISTS students (roll INTEGER, name VARCHAR(30))";
23
            stmt.executeUpdate(createTableQuery);
24
 
25
            // SQL insert statement with placeholders
26
            String sql = "INSERT INTO students VALUES(?, ?)";
27
 
28
            // Prepare the SQL statement
29
            PreparedStatement pstmt = conn.prepareStatement(sql);
30
 
31
            // Set values to the placeholders
32
            pstmt.setInt(1, roll);     // First '?' is replaced with roll number
33
            pstmt.setString(2, name);  // Second '?' is replaced with name
34
// ================================================
35
            // NOTE TO STUDENTS:
36
            // Try to solve the task on your own before referring to external help.
37
            // Avoid using online sources or tools unless absolutely necessary.
38
            // Engaging with the problem independently will improve your understanding and confidence.
39
            // ================================================
40
 
41
            // TODO: Execute the insert operation using the PreparedStatement
42
 
43
            /*
44
             Hint (only if required):
45
             - To insert the data into the database, use the executeUpdate() method on the PreparedStatement object.
46
             - This method executes the SQL command and modifies the database.
47
 
48
             Pseudocode:
49
             pstmt.executeUpdate();
50
            */
51
pstmt.executeUpdate();
0
// If insert is successful, print a confirmation message
1
            System.out.println("inserted");
2
 
3
            // Close resources after use
4
            pstmt.close();
5
            conn.close();
6
            sc.close();
7
        } catch (Exception e) {
8
            System.out.println(e);
9
        }
10
    }
11
}
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
1
Alice
inserted
inserted\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.