
☞ Programming in Java
NPTEL Week 02 : Programming Assignments Answers- 2025
import java.util.Scanner;
public class W02_P1 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// Read length and width of the rectangle
int length = sc.nextInt();
int width = sc.nextInt();
// Calculate area of the rectangle
int area = length * width;
// Output the area
System.out.println("Area of the rectangle: " + area);
}
}
import java.util.Scanner;
public class W02_P2 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// Read length and width of the rectangle
int length = sc.nextInt();
int width = sc.nextInt();
// Calculate the perimeter using the correct formula
int perimeter = 2 * (length + width);
// Output the perimeter
System.out.println("Perimeter is: " + perimeter);
sc.close();
}
}
import java.util.Scanner;
public class W02_P3 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] arr = new int[n];
// Read n numbers into array
for (int i = 0; i < n; i++) {
arr[i] = sc.nextInt();
}
int max = arr[0]; // Assume first element is maximum
// Use a loop to find maximum element
for (int i = 1; i < n; i++) {
if (arr[i] > max) {
max = arr[i];
}
}
System.out.println("Maximum is: " + max);
sc.close();
}
}
import java.util.Scanner;
public class W02_P4 {
// Declare a class named Rectangle
static class Rectangle {
int length;
int width;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// Read length and width
int l = sc.nextInt();
int w = sc.nextInt();
// Create an object of the Rectangle class
Rectangle rect = new Rectangle();
// Assign values to the object's member variables
rect.length = l;
rect.width = w;
// Print the sum using rect.length and rect.width
System.out.println("Sum of length and width is: " + (rect.length + rect.width));
sc.close();
}
}
import java.util.Scanner;
public class W02_P5 {
// Declare a separate class named Circle
static class Circle {
int radius;
// Constructor that takes radius as parameter
Circle(int radius) {
this.radius = radius;
}
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// Read radius value from user
int r = sc.nextInt();
// Create an object of Circle class using constructor
Circle c = new Circle(r);
// Print the radius using object member
System.out.println("Radius of the circle is: " + c.radius);
sc.close();
}
}
☞ NPTEL - Programming in Java - QUIZ : Week 12:Assignment 12 Answers- 2025
☞ NPTEL - Programming in Java - Week 12 : Programming Assignments Answers- 2025
☞ NPTEL - Programming in Java - QUIZ : Week 11:Assignment 11 Answers- 2025
☞ NPTEL - Programming in Java - Week 11 : Programming Assignments Answers- 2025
☞ NPTEL - Programming in Java - QUIZ : Week 10:Assignment 10 Answers- 2025
☞ NPTEL - Programming in Java - Week 10 : Programming Assignments Answers- 2025
☞ NPTEL - Programming in Java - QUIZ : Week 9:Assignment 9 Answers- 2025
☞ NPTEL - Programming in Java - Week 09 : Programming Assignments Answers- 2025
☞ NPTEL - Programming in Java - QUIZ : Week 8:Assignment 8 Answers- 2025
☞ NPTEL - Programming in Java - Week 08 : Programming Assignments Answers- 2025
☞ NPTEL - Programming in Java - QUIZ : Week 7:Assignment 7 Answers- 2025
☞ NPTEL - Programming in Java - Week 07 : Programming Assignments Answers- 2025
☞ NPTEL - Programming in Java - QUIZ : Week 6:Assignment 6 Answers- 2025
☞ NPTEL - Programming in Java - Week 06 : Programming Assignments Answers- 2025
☞ NPTEL - Programming in Java - QUIZ : Week 5:Assignment 5 Answers- 2025
☞ NPTEL - Programming in Java - Week 05 : Programming Assignments Answers- 2025
☞ NPTEL - Programming in Java - QUIZ : Week 4:Assignment 4 Answers- 2025
☞ NPTEL - Programming in Java - Week 04 : Programming Assignments Answers- 2025
☞ NPTEL - Programming in Java - QUIZ : Week 3:Assignment 3 Answers- 2025
☞ NPTEL - Programming in Java - Week 03 : Programming Assignments Answers- 2025
☞ NPTEL - Programming in Java - QUIZ : Week 2:Assignment 2 Answers- 2025
☞ NPTEL - Programming in Java - Week 02 : Programming Assignments Answers- 2025
☞ NPTEL - Programming in Java - QUIZ : Week 1:Assignment 1 Answers- 2025
☞ NPTEL - Programming in Java - Week 01 : Programming Assignments Answers- 2025
☞ NPTEL - Introduction to Programming in C - Week 7:Assignment 7 Answers- 2025
☞ NPTEL - Introduction to Programming in C - Week 6:Assignment 6 Answers- 2025
☞ NPTEL - Introduction to Programming in C - Week 5:Assignment 5 Answers- 2025
☞ NPTEL - Introduction to Programming in C - Week 4:Assignment 4 Answers- 2025
☞ NPTEL - Introduction to Programming in C - Week 3:Assignment 3 Answers- 2025
☞ NPTEL - Introduction to Programming in C - Week 2:Assignment 2 Answers- 2025
☞ NPTEL - Introduction to Programming in C - Week 1:Assignment 1 Answers- 2025