NPTEL
Code compiled and tested successfully!
Due date on 2026-08-14, 23:59 IST
Complete Program
import java.util.Scanner;
class W03_P1 {
// --- START OF SOLUTION CODE ---
public static int factorial(int x) {
if (x == 0 || x == 1) {
return 1;
} else {
return factorial(x - 1) * x;
}
}
// --- END OF SOLUTION CODE ---
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int x;
x = in.nextInt();
System.out.println(factorial(x));
}
}
Code Snippet to Paste in the Editor
// --- START OF SOLUTION CODE ---
public static int factorial(int x) {
if (x == 0 || x == 1) {
return 1;
} else {
return factorial(x - 1) * x;
}
}
// --- END OF SOLUTION CODE ---
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.
Evaluation Results
Note: These tests may not be considered while scoring.
Due date on 2026-08-14, 23:59 IST
Complete Program
import java.util.Scanner;
class cls1
{
void add(int p,int q)
{
System.out.println(p+q);
}
}
// --- START OF SOLUTION CODE ---
class cls2 extends cls1
{
void mul(int p, int q)
{
System.out.println(p * q);
}
void task(int p, int q)
{
System.out.println((p * p) + (q * q));
}
}
// --- END OF SOLUTION CODE ---
public class W03_P2{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
cls2 obj=new cls2();
int a=sc.nextInt();
int b=sc.nextInt();
//String tilde=sc.next();
obj.add(a,b);
obj.mul(a,b);
obj.task(a,b);
}
}
Code Snippet to Paste in the Editor
// --- START OF SOLUTION CODE ---
class cls2 extends cls1
{
void mul(int p, int q)
{
System.out.println(p * q);
}
void task(int p, int q)
{
System.out.println((p * p) + (q * q));
}
}
// --- END OF SOLUTION CODE ---
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.
Evaluation Results
Note: These tests may not be considered while scoring.
Due date on 2026-08-14, 23:59 IST
Complete Program
import java.util.Scanner;
public class W03_P3 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
// --- START OF SOLUTION CODE ---
int count = 0;
while (num != 0) {
num /= 10;
++count;
}
System.out.print(count);
// --- END OF SOLUTION CODE ---
}
}
Code Snippet to Paste in the Editor
// --- START OF SOLUTION CODE ---
int count = 0;
while (num != 0) {
num /= 10;
++count;
}
System.out.print(count);
// --- END OF SOLUTION CODE ---
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.
Evaluation Results
Note: These tests may not be considered while scoring.
Due date on 2026-08-14, 23:59 IST
Complete Program
import java.util.Scanner;
class Student {
private String name;
private int age;
// --- START OF SOLUTION CODE ---
public Student(String name, int age) {
this.name = name;
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
// --- END OF SOLUTION CODE ---
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// System.out.print("Enter student name: ");
String name = scanner.next();
// System.out.print("Enter student age: ");
int age = scanner.nextInt();
Student student = new Student(name, age);
System.out.print("Name: " + student.getName() + ", Age: " + student.getAge());
scanner.close();
}
}
Code Snippet to Paste in the Editor
// --- START OF SOLUTION CODE ---
public Student(String name, int age) {
this.name = name;
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
// --- END OF SOLUTION CODE ---
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.
Evaluation Results
Note: These tests may not be considered while scoring.
Due date on 2026-08-14, 23:59 IST
Complete Program
import java.util.Scanner;
public class W03_P5 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
// --- START OF SOLUTION CODE ---
for (int i = 1; i <= num; i++) {
if (num % i == 0) {
System.out.print(i + " ");
}
}
// --- END OF SOLUTION CODE ---
}
}
Code Snippet to Paste in the Editor
// --- START OF SOLUTION CODE ---
for (int i = 1; i <= num; i++) {
if (num % i == 0) {
System.out.print(i + " ");
}
}
// --- END OF SOLUTION CODE ---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.
Evaluation Results
Note: These tests may not be considered while scoring.