NPTEL Programming In Java Programming Assignment 7 September-2023

 

Week 7 : Programming Assignment 1

Due on 2023-09-14, 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.
Select the Language for this assignment. 
File name for this program : 
// Write the appropriate statement(s) to import the package(s) you need in your program
import java.util.*;
public class Question1{ 
        public static void main (String[] args){
 
//Write the appropriate code to read the 3 integer values and find their sum.
          int i,n=0,sum=0;
             Scanner inr = new Scanner(System.in);
        for (i=0;i<3;i++)
        {
            n = inr.nextInt();
            
        sum =sum+n;
            }
System.out.println(sum);
  }
}
You may submit any number of times before the due date. The final submission will be considered for grading.
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.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
1
1
1
3
3\n
Passed after ignoring Presentation Error


Week 7 : Programming Assignment 2

Due on 2023-09-14, 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".
Select the Language for this assignment. 
File name for this program : 
import java.io.*;  
public class Question2{  
public static void main(String args[]){
try {  
   InputStreamReader r=new InputStreamReader(System.in);  
   BufferedReader br=new BufferedReader(r);  
   String number=br.readLine();  
   int x = Integer.parseInt(number);
   System.out.print(x*x);
    }
   catch (Exception e){
       System.out.print("Please enter valid data");
    }
}  
}
You may submit any number of times before the due date. The final submission will be considered for grading.
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.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
2
4
4
Passed
Test Case 2
p
Please enter valid data
Please enter valid data
Passed




Week 7 : Programming Assignment 3

Due on 2023-09-14, 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.
Your last recorded submission was on 2023-09-04, 15:31 IST
Select the Language for this assignment. 
File name for this program : 
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.
String s2 = new String(barr,n,1);  
        System.out.println(barr[n]);
    System.out.println(s2); 
    }
catch (Exception e){
        System.out.println("exception occur");
        }      
    }  
}
You may submit any number of times before the due date. The final submission will be considered for grading.
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.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
1
80\n
P
80\n
P
Passed
Test Case 2
24
exception occur
exception occur\n
Passed after ignoring Presentation Error
Test Case 3
4
76\n
L
76\n
L
Passed


Week 7 : Programming Assignment 4

Due on 2023-09-14, 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".
Select the Language for this assignment. 
File name for this program : 
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 s2=s1.charAt(i);
          if(s2=='e' || s2=='E'|| s2=='a' || s2=='A' || s2=='i' || s2=='I' || s2=='o' || s2=='O' || s2=='u' || s2=='U') 
         {
           c=c+1;
             }    
         }
System.out.println(c); 
       }
       catch (Exception e){
         System.out.println(e);
        }      
    }  
}
You may submit any number of times before the due date. The final submission will be considered for grading.
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.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
sam
1
1\n
Passed after ignoring Presentation Error
Test Case 2
eeE
3
3\n
Passed after ignoring Presentation Error
Test Case 3
10
0
0\n
Passed after ignoring Presentation Error


Week 7 : Programming Assignment 5

Due on 2023-09-14, 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.
Select the Language for this assignment. 
File name for this program : 
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
byte[] barr=s1.getBytes();   
          
                byte b1 = (byte) c;
                barr[n]=b1;
        System.out.print(new String(barr)); 
       }
catch (Exception e){
          System.out.println("exception occur");
        }      
    }  
}
You may submit any number of times before the due date. The final submission will be considered for grading.
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.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
-1
exception occur
exception occur\n
Passed after ignoring Presentation Error
Test Case 2
e
exception occur
exception occur\n
Passed after ignoring Presentation Error
Test Case 3
4
NPTEaJAVA
NPTEaJAVA
Passed



No comments

JavaFX Scene Builder

  This is an article about the JavaFX Scene Builder. You will get a short introduction about the installation and usage of the software. The...