Home

Swayam Solver

Learn Programming & Prepare for NPTEL Exams...

Find your course

Explore Courses

Latest Blog Posts

NPTEL Programming In Java Programming Assignment Jan-2025 Swayam

 




NPTEL » Programming In Java





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