### Programming In Java NPTEL Week 1 Assignment

**Course Name: **NPTEL Programming In Java Assignment

Link: https://onlinecourses.nptel.ac.in/noc22_cs47/preview

1. What of the following can be used for a variable name in java?

a. Byte

b. Throw

c. This

d. Extend

ANSWER:-a

2. A platform is the hardware or software environment in which a program runs. Which of the following is/are java platform component?

a. HTML

b. Java Virtual Machine

c. Java application programming interface(API)

d. HotJava

ANSWER:-b,c

3. What is the value returned by the method f() define below? Public static int f(int x, int y) {return (x>y) ? y: x; }

- The sum of x and y that is, x + y.
- Thee difference of x and y that is, x-y.
- The maximum of x and y that is,the large r value of x and y
- The minimum of x and y that is, the smaller r value of x and y

ANSWER:-d

4. A java file with extension ‘.class’ contains

- Java source code
- HTML tags
- Java byte code
- A program file written in java programming language

ANSWER:-a

5. Which of the following is used to find and fix bus in the Java programs?

- JVM
- JRE
- JDK
- JDB

ANSWER:-d

6. What will be the output of the program if it is executed?

```
For (int b=7;b<3;b+=5){
System.out.print(b+++b);
}
}
}
```

What will be the output of the program if it is executed?

- 15
- 12
- 14
- 10

ANSWER:-a

7. Following is a piece of code where some part of the statement is missing :

In the following , some option are given. You have to choose the correct option for the argument in system.out.print() function to print the first and the last but one characters in the array nptel.

- nptel[nptel.length-2] + nptel[0]
- nptel[0] + nptel[nptel.length-2]
- “” + nptel[nptel.length-2] + nptel[0]
- “” + nptel[0] + nptel[nptel.length-2]

ANSWER:-d

8. Consider the following program .

What will be the output of the program if it is executed?

- Print first six even numbers.
- Print first six odd numbers.
- Print first five even number.
- Print first six Fibonacci numbers.

**ANSWER:- a**

9. Int N = Integer.parseInt (args[])

- 5
- 20
- 8
- 10

**ANSWER:- c**

10. Consider the following program.

- Print the value of N!
- Print the value of N(N+1)/2
- Print the value of 1*3*3*…………..* N
- Print the value of 1!*2!*3!*……………*N!

**ANSWER:- a**

## Programming Assignment Answers

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

**SOLUTION:-**

```
//Calculate the perimeter
perimeter = 2 * Math.PI * radius;
System.out.println (perimeter);
//Calculate the area
area = Math.PI * radius * radius;
System.out.print(area);
```

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

**SOLUTION:-**

```
//Use if...else ladder to find the largest among 3 numbers and store the largest number in a variable called result.
if (x > y && x > z)
{
result = x;
}
else if (y > z)
{
result = y;
}
else{
result= z;
}
System.out.print(result);
```

Q3. 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.

SOLUTION:-

```
for (int i = 0; i < (n*2)-1; i++)
{
if (i%2==0){
sum = sum + i;
}
}
sum = sum/3;
System.out.print(sum);
```

4. Complete the code segment to check whether the number is an Armstrong number or not.

**SOLUTION:-**

```
//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);
```

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

**SOLUTION:-**

```
//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.
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);
```

* The material and content uploaded on this website are for general information and reference purposes only. Please do it by your own first.

These are answers for NPTEL Programming In Java Assignment

MORE NPTEL ANSWERS: CLICK HERE

More Related links:

- Time Management Tips
- NPTEL Introduction To Machine Learning IITKGP ASSIGNMENT 9
- NPTEL INTRODUCTION TO MACHINE LEARNING ASSIGNMENT 9
- NPTEL Introduction To Internet Of Things Assignment 9
- Introduction to industry 4.0 and Industrial Internet of Things NPTEL Week 9
- Cloud Computing NPTEL Week 9 Assignment
- Problem Solving Through Programming In C NPTEL Assignment 9
- Programming in Java NPTEL Week 9 Assignment
- Soft Skills NPTEL Week 9 Assignment Solutions
- Software Testing NPTEL Week 9 Assignment