NPTEL 2 min read Updated Jun 2025

NPTEL Programming in Java Week6 Assignment Solution 2024

Faheem Ahmad

85 reads

NPTEL Programming in Java Week6 Assignment Solution

NPTEL Programming in Java Week6 All Programming Assignment Solutions – January 2024 | Swayam. With the growth of Information and Communication Technology, there is a need to develop large and complex software.

Further, those software should be platform independent, Internet enabled, easy to modify, secure, and robust. To meet this requirement object-oriented paradigm has been developed and based on this paradigm the Java programming language emerges as the best programming environment.

Now, Java programming language is being used for mobile programming, Internet programming, and many other applications compatible to distributed systems.

This course aims to cover the essential topics of Java programming so that the participants can improve their skills to cope with the current demand of IT industries and solve many problems in their own filed of studies.

COURSE LAYOUT
    • Week 1 : Overview of Object-Oriented Programming and Java
    • Week 2 : Java Programming Elements
    • Week 3 : Input-Output Handling in Java
    • Week 4 : Encapsulation
    • Week 5 : Inheritance
    • Week 6 : Exception Handling
    • Week 7 : Multithreaded Programming
    • Week 8 : Java Applets and Servlets
    • Week 9 : Java Swing and Abstract Windowing Toolkit (AWT)
    • Week 10 : Networking with Java
    • Week 11: Java Object Database Connectivity (ODBC)
    • Week 12: Interface and Packages for Software Development

Course Name : “Programming in Java 2024”

Question : 1 Complete the code fragment to read two integer inputs from keyboard and find the quotient and remainder.

Java
import java.util.Scanner;
public class Question61{
       public static void main(String[] args) {
	   Scanner sc = new Scanner(System.in);
	   int x=sc.nextInt();
	   int y=sc.nextInt();
	   
	   //code for quotient and remainder

	   int quotient = x / y;
	   int remainder = x % y;
	   
	   System.out.println("The Quotient is = " + quotient);
	   System.out.print("The Remainder is = " + remainder);
	   }
	 }

Course Name : “Programming in Java 2024”

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

Java
import java.util.Scanner;
public class Question62{
    public static void main(String[] args) {
	   Scanner sc = new Scanner(System.in);
	   int num=sc.nextInt();
	   
	   //Use while loop to count number of digits in an integer
       int count = 0;
	   while(num != 0) {
	       num /= 10;
	       ++count;
	   }
	   
	   System.out.print(count);
	  }
	}

Course Name : “Programming in Java 2024”

Question : 3 Complete the code segment to display the factors of a number n.

Java
import java.util.Scanner;
public class Question63{
    public static void main(String[] args) {
	   Scanner sc = new Scanner(System.in);
	   int num =sc.nextInt();
	   
	   //Use while or for loop to find the factors of a number.

	   for(int i = 1; i <= num; ++i) 
       {
	       if(num % i == 0)
           {
	           System.out.print(i + " ");
	       }
	   }
	 }
}

Course Name : “Programming in Java 2024”

Question : 4 Complete the code segment to find the standard deviation of the 1-D array. Here,

σ = Population standard deviation
N = Number of observations in the population
Xi = ith observation in the population
μ = Population mean
Java
import java.util.Scanner;
public class Question64{     
  
    public static void main(String[] args) 
    {
        double sum = 0.0;
        double standardDeviation = 0.0;
        double mean = 0.0;
        double res = 0.0;
        double sq = 0.0;
        Scanner sc = new Scanner(System.in);
        int num = sc.nextInt();
        double arr[] = new double[num];
        for (int i = 0; i < num; i++) {
            arr[i] = sc.nextDouble();
        }
        
        // write code to find standard deviation of input array

		for(int i = 0; i < arr.length; i++) 
        {
            sum += arr[i];
        }
        mean = sum/arr.length;
        
        // Calculate standard deviation
        for(int i = 0; i < arr.length; i++) 
        {
            sq += Math.pow(arr[i] - mean, 2);
        }
        res = Math.sqrt(sq/arr.length);
        
        System.out.print("Standard Deviation: " + res);
  }
}

Course Name : “Programming in Java 2024”

Question : 5 Write a program which will print a pattern of “*” ‘s of height “n”.
For example:
Input: n = 3
Output:
***
**
*
**
***

Java
import java.util.*;
public class Question65{
    public static void main(String[] args) {
        Scanner inr = new Scanner(System.in);
	   int n = inr.nextInt();
	   
	   // Add the necessary code in the below space
		for(int i = n; i >= 1; --i) {
            for(int j = 1; j <= i; ++j) {
                System.out.print("*");
            }
            System.out.println();
        }
        
        // Print the lower half of the pattern
        for(int i = 2; i <= n; ++i) {
            for(int j = 1; j <= i; ++j) {
                System.out.print("*");
            }
            System.out.println();
        }
    }
}

// written by

Faheem Ahmad

Writer at Techies Talk

Faheem writes about NPTEL, Coursera, and How To on Techies Talk, turning tricky topics into guides you can follow step by step.

Writes about #NPTEL117 #Coursera13 #How To5

Articles
145
Reads
631
Writing since
2020
All posts by Faheem