Programming In Java Week 7: Programming Assignments Jan-Jun 2022

 NPTEL PROGRAMMING ASSIGNMENTS

Week 7 : Programming Assignment 1

Due Date of Submission 2022-03-17, 23:59 IST

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.


import java.util.Scanner;
public class Question1{ 
        public static void main (String[] args){


 

 


System.out.println(sum);
  }
}




Week 7 : Programming Assignment 2

Due Date of Submission 2022-03-17, 23:59 IST
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[]){ 



 

 



Week 7 : Programming Assignment 3

Due Date of Submission 2022-03-17, 23:59 IST
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();


 

 

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



Week 7 : Programming Assignment 4

Due Date of Submission 2022-03-17, 23:59 IST
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();

 

 


   System.out.println(c); 
   }
       catch (Exception e){
System.out.println(e);
    }    
    }  



Week 7 : Programming Assignment 5

Due Date of Submission 2022-03-17, 23:59 IST
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';


 

 

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

Post a Comment (0)
Previous Post Next Post