NPTEL Programming In Java Programming Week 1 : Programming Assignment 1,2,3,4 and 5 August-2023 Swayam

 

Week 1: Programming Assignment 1

Due on 2023-08-10, 23:59 IST

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 radius is zero or less than zero then print " please enter non zero positive number ".

Your last recorded submission was on 2023-07-23, 19:28 IST
Select the Language for this assignment. 
File name for this program : 
import java.util.Scanner;  
public class Exercise1_1 {
       public static void main(String[] args) {
Scanner s = new Scanner(System.in); 
       double radius= s.nextDouble();
       double perimeter;
       double area;
//Calculate the perimeter
perimeter = 2* Math.PI* radius;
  //Calculate the area
area = Math.PI*radius*radius;
 
System.out.println(perimeter);
System.out.print(area);
}
}
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.0
12.566370614359172\n
12.566370614359172
12.566370614359172\n
12.566370614359172
Passed





Private Test cases used for EvaluationStatus
Test Case 1
Passed



Week 1 : Programming Assignment 2

Due on 2023-08-10, 23:59 IST

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

Your last recorded submission was on 2023-07-27, 08:18 IST
Select the Language for this assignment. 
File name for this program : 
import java.util.Scanner;  
public class Exercise1_2 {
       public static void main(String[] args) {
Scanner s = new Scanner(System.in); 
        int x = s.nextInt(); 
        int y = s.nextInt();
int z = s.nextInt();
int result = 0;
//Use if...else ladder to find the largest among 3 numbers and store the largest number in a variable called result.
if(x > y)
  if(x > z)
    result = x;
  else
    result = z;
else if( y > z )
    result = y;
  else 
    result =z;
  
System.out.print(result);
}
}
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
-4 -2 -5
-2
-2
Passed





Private Test cases used for EvaluationStatus
Test Case 1
Passed
Test Case 2
Passed


Week 1 : Programming Assignment 3

Due on 2023-08-10, 23:59 IST

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

Your last recorded submission was on 2023-07-23, 19:29 IST
Select the Language for this assignment. 
File name for this program : 
import java.util.Scanner;
public class Exercise1_3 {
       public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
       int n=sc.nextInt();
      int sum=0;
//Use for or while loop do the operation.
 
for( int i = 0; i<=n*2; i+=2)
  if( i%3 == 0)
    sum+=i;
 
System.out.print(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
0
0
Passed





Private Test cases used for EvaluationStatus
Test Case 1
Passed
Test Case 2
Passed


Week 1 : Programming Assignment 4

Due on 2023-08-10, 23:59 IST

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 = 1
3+53+33, 370, 371, 407, etc.

Your last recorded submission was on 2023-07-23, 19:30 IST
Select the Language for this assignment. 
File name for this program : 
import java.util.Scanner;
public class Exercise1_4 {
    public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
       int n=sc.nextInt();
           int result=0;
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.print(result);
}
}
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
203
0
0
Passed





Private Test cases used for EvaluationStatus
Test Case 1
Passed
Test Case 2
Passed




Week 1 : Programming Assignment 5

Due on 2023-08-10, 23:59 IST

Complete the code segment to help Ragav , find the highest mark and average mark secured by him in "s" number of subjects.

Your last recorded submission was on 2023-07-23, 19:31 IST
Select the Language for this assignment. 
File name for this program : 
import java.util.Scanner;
public class Exercise1_5{
    public static void main(String[] args) {
     Scanner input = new Scanner(System.in);
         double mark_avg;
         int result;
         int i;
         int s;
      //define size of array
       s = input.nextInt();
     //The array is defined "arr" and inserted marks into it.
      int[] arr = new int[s];   
      for(i=0;i<arr.length;i++)
      {
    arr[i]=input.nextInt();
        }
//Initialize maximum element as first element of the array.  
   //Traverse array elements to get the current max.
   //Store the highest mark in the variable result.
   //Store average mark in avgMarks.
result=arr[0];
mark_avg=0;
 
for(i=0;i<arr.length;i++)
      {
  mark_avg+=arr[i];
  if( arr[i]> result)
  result = arr[i];
}
mark_avg/=s;
System.out.println(result);
System.out.print(mark_avg);
}
}
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
5
20 50 60 40 70
70\n
48.0
70\n
48.0
Passed






Private Test cases used for EvaluationStatus
Test Case 1
Passed
Test Case 2
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...