NPTEL - Programming In Java-Week 1: Programming Assignment 1, 2, 3, 4 and 5 Aug-2022




Week 1: Programming Assignment 1


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;
                System.out.println (perimeter);
                //Calculate the area
                area = Math.PI * radius * radius;
                System.out.print(area); 
        }
}

Week 1 : Programming Assignment 2

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;
                if (x > y && x > z)
                {
                          result = x;
                }
                  else if (y > z)
                  {
                           result = y;
                  }
                else
                {
                          result= z;
                }
                System.out.print(result);
    }
}


Week 1 : Programming Assignment 3


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


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;
           for (int i = 0; i < (n*2)-1; i++)
        {
                if (i%2==0)
                  {
                        sum = sum + i;
                }
        }             sum = sum/3;
            System.out.print(sum);
    }
}


Week 1 : Programming Assignment 4


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.


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;

//Use while loop check the number is Armstrong or not.

//store the output(1 or 0) in result variable.

        int temp, digits=0, last=0, sum=0;
        temp=n;
        while(temp>0)
        {
              temp = temp/10;
              digits++;
        }
        temp = n;
        while (temp>0)
        {
              last = temp % 10;
              sum += (Math.pow(last, digits));
              temp = temp/10;
        }
        if(n==sum)
        {
              result = 1;
        }
        else
        {
                  result = 0;
        }
            System.out.print(result);

        }

}


Week 1 : Programming Assignment 5


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

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();
        }

        int sum = arr[0];         result = arr[0];         for (i=1; i<s; i++)         {             if (result < arr[i])             {                 result = arr[i];             }             sum = sum + arr[i];         }             mark_avg = sum / s;             System.out.println(result);         System.out.print(mark_avg);
    }
}


netaji gandi Tuesday, August 9, 2022
NPTEL Problem Solving Through Programming In C Week 2 Quiz Assignment Solution | July 2022

 

Week 2: Assignment 2


A function is
 
 
 
 
1 point
If an integer needs two bytes of storage, then the minimum value of a signed integer in C would be
 
 
 
 
1 point
Which of the following statements is correct?
I.     Keywords are those words whose meaning is already defined by Compiler.
II.    Keywords cannot be used as variable names.
III.   There are 32 keywords in C
IV.   C keywords are also called reserved words.
 
 
 
 
1 point
 
 
 
 
    Ans: 18
1 point
1 point
Which of the following are not standard header files in C?
 
 
 
 
 Ans: 18.50
1 point
1 point
Which of the following is not a C variable?
 
 
 
 
1 point
 
 
 
 
1 point
 
 
 
 
You may submit any number of times before the due date. The final submission will be considered for grading.

netaji gandi Monday, August 8, 2022
NPTEL | Programming In Java| Week 1 : Assignment 1 Answers | July-2022

 


Week 1:Assignment 1

Due date: 2022-08-10, 23:59 IST.
Your last recorded submission was on 2022-07-29, 11:02 IST
1 point
 
 
 
 
1 point
 
 
 
 
1 point
 
 
 
 
1 point
 
 
 
 
1 point
 
 
 
 
1 point
 
 
 
 
1 point
 
 
 
 
1 point
 
 
 
 
1 point
 
 
 
 
1 point
 
 
 
 
You may submit any number of times before the due date. The final submission will be considered for grading.

netaji gandi Thursday, July 28, 2022
NPTEL | Programming, Data Structures And Algorithms Using Python | Week 1 : Assignment 1 Answers | July-2022

 



Week 1 Quiz

Due date: 2022-08-10, 23:59 IST.
Assignment not submitted
All questions carry equal weightage. All Python code is assumed to be executed using Python3. You may submit as many times as you like within the deadline. Your final submission will be graded.

Note:

  • If the question asks about a value of type string, remember to enclose your answer in single or double quotes.
  • If the question asks about a value of type list, remember to enclose your answer in square brackets and use commas to separate list items.

1. What does h(27993) return for the following function definition?

def h(x):
    (d,n) = (1,0)
    while d <= x:
        (d,n) = (d*3,n+1)
    return(n)
   Ans: 10



2.5 points

2. What is g(60) - g(48), given the definition of g below?

def g(n): 
    s=0
    for i in range(2,n):
        if n%i == 0:
           s = s+1
    return(s)
   Ans: 2





2.5 points
2.5 points

3. Consider the following function f.

def f(n): 
    s=0
    for i in range(1,n+1):
        if n//i == i and n%i == 0:
           s = 1
    return(s%2 == 1)

The function f(n) given above returns True for a positive number n if and only if:

 
 
 
 
2.5 points

4. Consider the following function foo.

def foo(m):
    if m == 0:
      return(0)
    else:
      return(m+foo(m-1))

Which of the following is correct?

 
 
 
 
You may submit any number of times before the due date. The final submission will be considered for grading.



netaji gandi

OBJECT ORIENTED PROGRAMMING USING JAVA LAB

Java Programming Lab Experiments VR-23 2025-26 Java Programming Lab Experiments Experiment 1: Fibonacci Sequence The F...