NPTEL » Programming In Java Assignment 2021

nptel programming in java

Programming In Java With the growth of Information and Communication Technology, there is a need to develop large and complex software. 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.

Programming in Java is a MOOC based course which is 12 weeks in duration and can fulfill the criteria of 4 credits in a year. You can visit the NPTEL SWAYAM platform and register yourself for the course. This course is brought to you by Prof. Dr. Debasis Samanta who holds a Ph.D. in Computer Science and Engineering from the Indian Institute of Technology Kharagpur.

Programming In Java 2021 Details:-

  1. Who Can Join: The undergraduate students from the engineering disciplines namely CSE, IT, EE, ECE, etc. might be interested in this course.
  2. Requirements/Prerequisites: The course requires that the students are familiar with a programming language such as C/C++ and data structures, algorithms.
  3. INDUSTRY SUPPORT:   All IT companies.

Nptel Programming In Java Online Programming test Session 2:-

Q1. The following program is intended to calculate the sum of first ‘n’ odd integer numbers. Write the appropriate statement to complete the program given below.

Code:-


For July 2021 session answers click here

Q2. Read the size of an array from keyboard. You have to declare an integer array of the provided size and insert the elements into it by reading from keyboard. You have to find the minimum number in that array and print the same.

Code:-


For July 2021 session answers click here

Q3. An array is defined and initialized in the following program. You have to find the average of all odd numbers present in that array and print the same.

Code:-


For July 2021 session answers click here

Q4. Read a character from keyboard .You have to check whether it is vowel or not. If it is vowel print “vowel” otherwise print “Not_vowel”.

Code:-


For July 2021 session answers click here

Q5. 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 ” findCube(n)” will return the cube of the number n.

Code:-


For July 2021 session answers click here

Nptel Programming In Java Online Programming test:-

Q1. The following program is intended to calculate the sum of first ‘n’ even integer numbers excluding zero. Write the appropriate statement to complete the program given below.

Code:-

For July 2021 session answers click here

Q2. Complete the following program that is intended to find and print the maximum value stored in an array ‘arr[]’.

Code:-

      
QUIZXP TELEGRAM

Q3. In the following program, an array of type integer (arr[]) is declared. The array can store any integer value. The following program is to print the average value of all the even numbers including zero stored in the array (arr[] ).

Code:-


For July 2021 session answers click here

Q4. A user will input any character and a program will print if the input character is a consonant. Write appropriate statements below to complete the following program. Your program should print ‘Consonant’ .

Code:-


For July 2021 session answers click here

Q5. The follwoing program has a number of bugs. It won’t compile successfully. Fix the bug so that the program prints the following output.

Code:


For July 2021 session answers click here

Programming In Java Assignment Week 10 Answers:-

Q1. The following code needs some package to work properly. Write appropriate code toimport the required package(s) in order to make the program compile and execute successfully.

Code:-


For July 2021 session answers click here

Q2. Write the JDBC codes needed to create a Connection interface using the DriverManager class and the variable DB_URL.  Check whether the connection is successful using ‘isAlive(timeout)’ method to generate the output, which is either ‘true’ or ‘false’.

Code:-


For July 2021 session answers click here

Q3. Due to some mistakes in the below code, the code is not compiled/executable. Modify and debug the JDBC code to make it execute successfully.

Code:-


For July 2021 session answers click here
QUIZXP TELEGRAM

Q4. Complete the code segment to create a new table named ‘PLAYERS’ in SQL database using the following information.

Code:-


For July 2021 session answers click here

Q5. Complete the code segment to rename an already created table named ‘PLAYERS’ into ‘SPORTS’.

Code:


For July 2021 session answers click here

Programming In Java Assignment Week 08 Answers:-

Q1. Write a program which will print a pyramid of “*” ‘s of height “n” and print the number of “*” ‘s in the pyramid.

Code:-



QUIZXP TELEGRAM

Q2. Write a program which will print a pascal  pyramid of  “*” ‘s of height “l” .

Code:

  

Q3. Write a program which will print a pyramid of “numbers” ‘s of height “n” and print the sum of all number’s in the pyramid.

Code:-


QUIZXP TELEGRAM

Q4. Write a program to print symmetric Pascal’s triangle of “*” ‘s of  height “l” of odd length . If input “l” is even then your program will print “Invalid line number”.

Code:-

 }
}

Q5. Write a program to display any digit(n) from 0-9 represented as a “7 segment  display”

Code:-


}

Programming In Java Assignment Week 07 Answers:-

Q1. Complete the code fragment to read three integer inputs from keyboard and find the sum and store the result in the variable “sum”.

Code:-


Q2. Complete the code segment to catch the exception in the following, if any. On the occurrence of such an exception, your program should print “Please enter valid data” .If there is no such exception, it will print the “square of the number”.

Code:-


	 
 
QUIZXP TELEGRAM

Q3. A byte char array is initialized. You have to enter an index value “n”. According to index your program will print the byte and its corresponding char value.

Complete the code segment to catch the exception in the following, if any. On the occurrence of such an exception, your program should print “exception occur” .If there is no such exception, it will print the required output.

Code:-

Q4. A string is read from the keyboard and is assigned to variable “s1”. Your program should print the “number of vowels in s1”. However, if your input is other than “String” data type it will print “0”.

Code:-

QUIZXP TELEGRAM

Q5. A string “s1” is already initialized. You have to read the index “n” .Complete the code segment to catch the exception in the following, if any. On the occurrence of such an exception, your program should print “exception occur” .If there is no such exception, your program should replace the char ‘a’ at the index value “n” of the “s1” ,then it will print the modified string.

Code:-

Programming In Java Assignment Week 06 Answers:-

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

Code:-


Java Week 06: Q2: 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.

Code:-

quizxp telegram

Java Week 06: Q3: 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.

Code:-

Java Week 06: Q4: Execution of two or more threads occurs in random order. The keyword ‘synchronized’ in Java is used to control the execution of threads in a strict sequence. In the following, the program is expected to print some numbers. Do the necessary use of the ‘synchronized’ keyword, so that, the program prints the output in the following order:  
Code:-

Java Week 06: Q5: Add necessary codes to print the following:

—————–OUTPUT——————-

Name of thread ‘t’:Thread-0

New name of thread ‘t’:NPTEL

Thread is running.

—————————-

Code:-

Programming In Java Assignment Week 05 Answers:-

Java Week 05: Q1: 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.

Code:-

Java Week 05: Q2: This program is to find the GCD (greatest common divisor) of two integers writing a recursive function find GCD(n1,n2). Your function should return -1, if the argument(s) is(are) other than positive number(s).

Code:-

quizxp telegram

Java Week 05: Q3: Complete the code segment to catch the Arithmetic Exception 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.

Code:-

 

Java Week 05: Q4: 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.

Code:-

 

Java Week 05: Q5: 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.

Code:-

Programming In Java Assignment Week 04 Answers:-

Java Week 04: Q1 – Complete the code segment to execute the following program successfully. You should import the correct package(s) and/or class(s) to complete the code.

Code:-

Java Week 04: Q2 – Complete the code segment to print the current year. Your code should compile successfully.

Code:-

Java Week 04: Q3 – The program in this assignment is attempted to print the following output: 

This is large

This is medium

This is small

This is extra-large

Code:-


quizxp telegram

Java Week 04: Q4 – Complete the code segment to call the default method in the interface First and Second.

Code:-

Java Week 04: Q5 – Modify the code segment to print the following output.

Code:-

Programming In Java Assignment Week 03 Answers:-

Java Week 03: Q1 This program is related to the generation of Fibonacci numbers. For example: 0,1, 1,2, 3,5, 8, 13,… is a Fibonacci sequence where 13 is the 8th Fibonacci number. A partial code is given and you have to complete the code as per the instruction given below.

Java Week 03: Q2Define a class Point with two fields x and y each of type double. Also, define a method distance(Point p1, Point p2) to calculate the distance between points p1 and p2 and return the value in double.Complete the code segment given below. Use Math.sqrt( ) to calculate the square root.

Java Week 03: Q3 A class Shape is defined with two overloading constructors in it. Another class Test1 is partially defined which inherits the class Shape. The class Test1 should include two overloading constructors as appropriate for some object instantiation shown in main() method. You should define the constructors using the super class constructors. Also, override the method calculate( ) in Test1 to calculate the volume of a Shape.

Java Week 03: Q4 This program exercise the call of 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. 

Java Week 03: Q5 Complete the code segment to swap two numbers using call by object reference.<

Programming In Java Assignment Week 02 Answers:-

Java Week 02: Q1 Complete the code segment to call the method print() of class Student first and then call print() method of class School.

// Creating object of class Student
		Student student = new Student();
		// Call 'print()' method of class Student 
		student.print();
		// Creating object of class School
		School school = new School();
		// Call 'print()' method of class School
		school.print();

Java Week 02: Q2– Complete the code segment to call the method  print() of class given class Printer to print the following.

// Create an object of class Printer

Printer p = new Printer();

// Call 'print()' methods for desired output

p.print("Hi! I am class STUDENT");
p.print();

Java Week 02: Q3 Complete the code segment to call print() method of class Question by creating a method named ‘studentMethod()’.

// Define a method named 'studentMethod()' in class Question
void studentMethod(){
// Call the method named 'print()' in class Question
		print(this);
	}
quizxp telegram

Java Week 02: Q4 Complete the code segment to call default constructor first and then any other constructor in the class Answer.

// This is the class Answer
class Answer{
	// This is the default constructor of the class Answer
	Answer(){
		System.out.println("You got nothing.");
	}
	// This is a parameterized constructor of the class Answer
	Answer(int marks, String type){
		//The 'this()' referene variable is able to call the default constructor of the class.
		this();		
		//Print marks and type of the question
		System.out.println("You got "+marks+" for an "+ type);
	}
}

Java Week 02: Q5 Complete the code segment to debug the program which is intended to print ‘NPTEL JAVA’.

//Declare variable with name 'nptel', 'space' and 'java' and proper datatype
String nptel, space, java;

//Initialize the variables with proper input
nptel = "NPTEL";
space = " ";
java = "JAVA";
quizxp telegram

Programming In Java Assignment Week 01 Answers:-

Java Week 01: Q1. -Complete the code segment to find the perimeter and area of a circle given a value of radius. You should use Math.PI constant in your program. If the radius is zero or less than zero then print ” please enter non zero positive number “.

if(radius<=0)
 {
  System.out.println("please enter non zero positive number ");
 }
else
{
 perimeter = 2 * Math.PI * radius;
 area = Math.PI * radius * radius;
 System.out.println(perimeter);
 System.out.println(area);
}

Java Week 01: Q2 – Complete the code segment to find the largest among three numbers x, y, and z. You should use if-then-else construct in Java.

if(x >= y && x >= z)
        {
            result=x;
        }
        else if(y >= z)
        {
            result=y;
        }
        else
        {
            result=z;
        }
System.out.println(result);	 
 

Java Week 01: Q3 – Consider First n even numbers starting from zero(0).Complete the code segment to calculate sum of  all the numbers divisible by 3 from 0 to n.Print the sum.

Example:

Input: n = 5

——-
0 2 4 6 8
Even number divisible by 3:0 6
sum:6

int result=1;
int i=0;
while(result<=n)
	 {
	  if(i%2==0)
	  {
		 if(i%3==0)
		 {
			 sum=sum+i;
			
         }			 
		 result=result+1; 
	  }
	  i=i+1;
	 }
      System.out.println(sum);

Java Week 01: Q4 – Complete the code segment to check whether the number is an Armstrong number or not.

Armstrong Number:

A positive number is called an Armstrong number if it is equal to the sum of cubes of its digits for example 153 = 13+53+33, 370, 371, 407, etc

int temp=n;
int c=0,t; 
//Use while loop to check the number is Armstrong or not.
    while(n>0)
	{
		t=n%10;
		n=n/10;
		c=c+(t*t*t);
	}		
	if(temp==c)
		result=1;
	else
		result=0;
    //Evaluation code 
    System.out.println(result);

Java Week 01: Q5 – Complete the code segment to help Raj , find the highest mark and average mark secured by him in “s” number of subjects.

//initialise maximum element as first element of array.  
	   int max=arr[0];
           double sum=arr[0];  
	  //traverse array elements to get the current max
      for(i=1;i<arr.length;i++)
	  { 
         sum=sum+arr[i]; 
         if(arr[i]>max)
            max =arr[i];
	  }
	 
    //Store the highest mark in the variable max
   //Store average mark in avgMarks
    result=max;	
    mark_avg=sum/(arr.length);    
 //Evaluation code 
    System.out.println(result);
    System.out.println(mark_avg);

Find Other Quiz Here:

Amazon Fashion Quiz Answers & Win ₹1000

Amazon Great Indian Festival Quiz Answers: Win Rs. 50,000

NPTEL » Programming In Java Assignment week 6 Sep-2020

NPTEL » Programming In Java Assignment week 7 Sep-2020

NOTE: These codes are based on our knowledge. Answers might be incorrect, we suggest you to not the copy-paste answers blindly.

[foobar id=”1315″]