nptel java week 7 assignment answers 2023 {last date 15-feb}

NPTEL Programming in Java Week 7 Assignment Solution– Hello everyone, in this blog, we will provide you the solution for assignment 7 of Programming in Java. We will try our best to provide you all the correct answers, but you confirm this answer according to your own and submit the assignment.

Disclaimer – We recommend you to complete your NPTEL Programming in Java Assignment independently because we do not guarantee the accuracy of our solutions. Instead, these answers are based only on our area of expertise, and we are only presenting them to serve as a resource for students.

NPTEL Programming in Java Week 7 : Assignment 7 Answers

Q1) Which of these is a type of IO stream in Java?

  • a. Integer stream
  • b. Short stream
  • c. Byte stream
  • d. Character stream

Q2) Which of the following is a class in java. io package?

  • a. FileReader
  • b. ObjectInput
  • c. ObjectOutput
  • d. Datalnput

Q3) Consider the following program, What will be the output if the above program is executed?

import java.io.*;
public class Question {
public static void main(String[] args)

try {
PrintWriter writer = new PrintWriter(System.out);
writer.write (64+'2");
writer.close():

atch (Exception e) {
System.out.println(e);
  • a. It will give compile-time error.
  • b. B
  • c. 66
  • d. r

Q4) Consider the following program, What is the output of the above code?


import java.io
public cla:

{

files

public static void main(String args[])
{

File obj = new File("java/programm/2023");
System.out.print (obj.getName());

}
  • a. java/programm/2023
  • b. java/programm
  • c. java
  • d. 2023

Q5) Which method is used to read b length bytes from the input stream into an array?

  • public void read(int b)throws IOException { {
  • public int read(byte[ ] b)throws IOException {}
  • public void read(byte[ ] b)throws IOException {}
  • public int read(int b)throws IOException { }

CRITERIA TO GET A CERTIFICATE in NPTEL Course Programming in Java

Average assignment score = 25% of average of best 8 assignments out of the total 12 assignments given in the course.
Exam score = 75% of the proctored certification exam score out of 100

Final score = Average assignment score + Exam score

YOU WILL BE ELIGIBLE FOR A CERTIFICATE ONLY IF AVERAGE ASSIGNMENT SCORE >=10/25 AND EXAM SCORE >= 30/75. If one of the 2 criteria is not met, you will not get the certificate even if the Final score >= 40/100.

NOTE: Please note that there will not be an unproctored programming exam for this course this term

Q6) How many standard streams Java can support?

  • a. 2
  • b. 3
  • c. 4
  • d. 1

Q7) Which of the following stream is different from others?

  • a. System.in
  • b. System.out
  • c. PrintStream
  • d. FileOutputStream

Q8) Which of the following is used to read a string from the input stream?

  • a. cget()
  • b. readLine( )
  • c. getLine( )
  • d. read()

Join Now

Q9) Which of the following class(es) can be used for handling files in Java?

  • a. java.files
  • b. java.io.File
  • c. java.io
  • d. java.Filehandling

Q10) Which of the following statement(s) is/are true?

  • a. The default delimiters for a Scanner object are the white space characters.
  • b. The Scanner class has instance methods for reading each of the Java primitive types except char.
  • c. The Scanner methods do not throw any checked exceptions.
  • d. The Scanner class can be found in the java.util package.

NPTEL Programming in Java Assignment 7 Answers Join Group

NPTEL Programming in Java Week 7 Programming Assignment 7 Solution

Q1) 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.

import java.util.*;
public class Question3 {  
    public static void main(String[] args) { 
       try{	
	  byte barr[]={'N','P','T','E','L','-','J','A','V','A','J','A','N','-','N','O','C','C','S','E'};
          Scanner inr = new Scanner(System.in);
	  int n = inr.nextInt();
	  
// Complete the code to get specific indexed byte value and its corresponding char value.

if(n>=0 && n<barr.length){
System.out.println(""+barr[n]);
System.out.print(""+(char)barr[n]);
}
else{
throw new ArrayIndexOutOfBoundsException();
}
}

catch (Exception e){
	    System.out.println("exception occur");
	    }	   
    }  
}

Q2) The following program reads a string from the keyboard and is stored in the String variable “s1”. You have to complete the program so that it should should print the number of vowels in s1 . If your input data doesn’t have any vowel it will print “0”.

import java.io.*;
import java.util.*;

public class Question4{  
    public static void main(String[] args) { 
	  int c=0;
         try{
            InputStreamReader r=new InputStreamReader(System.in);  
            BufferedReader br=new BufferedReader(r);  
            String s1 = br.readLine();
          
  //Write your code here to count the number of vowels in the string "s1"
  
   for(int i=0; i<s1.length(); i++){
            char ch = s1.charAt(i);
            if(ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u'||ch=='A'||ch=='E'||ch=='I'||ch=='O'||ch=='U')
                c++;
        }
        
        System.out.println(c); 
	   }
       catch (Exception e){
		 System.out.println(e);
	    }	   
    }  
} 

Q3) A string “s1” is already initialized. You have to read the index “n”  from the keyboard. 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.

import java.util.*;
public class Question5 {  
    public static void main(String[] args) { 
       try{	
	    String s1="NPTELJAVA"; 
            Scanner inr = new Scanner(System.in);
	    int n = inr.nextInt();
            char c='a';
            
        //Replace the char in string "s1" with the char 'a' at index "n"  and print the modified string 
        char[] charArray = s1.toCharArray();
        if(n >= s1.length()) {
            throw new IndexOutOfBoundsException();
        }
        charArray[n] = c;
        s1 = new String(charArray);
        System.out.print(s1);

   }
   
catch (Exception e){
          System.out.println("exception occur");
	    }	   
    }  
} 

Q4) Complete the following code fragment to read three integer values from the keyboard and find the sum of the values. Declare a variable “sum” of type int and store the result in it.

// Write the appropriate statement(s) to import the package(s) you need in your program
import java.util.Scanner;

public class Question1{ 
        public static void main (String[] args){

//Write the appropriate code to read the 3 integer values and find their sum.
     //create an object of the Scanner class
    Scanner scanner = new Scanner(System.in);
    
    //read the first integer value
    System.out.print("");
    int num1 = scanner.nextInt();
    
    //read the second integer value
    System.out.print("");
    int num2 = scanner.nextInt();
    
    //read the third integer value
    System.out.print("");
    int num3 = scanner.nextInt();
    
    //find the sum of the three values
    int sum = num1 + num2 + num3;
    
 
System.out.println(sum);
  }
}

Q5) 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”.

import java.io.*;  
public class Question2{  
public static void main(String args[]){ 
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
try {
System.out.print("");
int num = Integer.parseInt(br.readLine());
int square = num * num;
System.out.print("" + square);
} catch (Exception e) {
System.out.print("Please enter valid data");
}

}
}

These are NPTEL Programming in Java Assignment 7 Answers

More Weeks of Programming in Java : Click Here

More nptel course: https://prabhakarguru.com/category/nptel-assignment/

Prabhakar Guru Insta ID

Disclaimer – We recommend you to complete your NPTEL Programming in Java  independently because we do not guarantee the accuracy of our solutions. Instead, these answers are based only on our area of expertise, and we are only presenting them to serve as a resource for students.

Leave a Comment

PHP Code Snippets Powered By : XYZScripts.com