In this post, We have provided answers of NPTEL Programming in Java Assignment 1. We provided answers here only for reference. Plz, do your assignment at your own knowledge.
ALSO READ :-
NPTEL Registration Steps [July – Dec 2022]
NPTEL Exam Pattern Tips & Top Tricks [2022]
NPTEL Exam Result 2022 | NPTEL Swayam Result Download
NPTEL Programming In Java Week 1 Assignment Answers 2023
1. Which of the following is NOT a primitive data type in Java??
a. int
b. boolean
c. String
d. char
Answer :- c
2. Consider the following program.
What is the output of the above code?
a. 127
b. -127
c. 129
d. 2
Answer :- b
3.Which of the following concept that Java doesn’t support?
a. inheritance
b. encapsulation
c. pointer
d. arrey
Answer :- c
4. Which of the following is not a keyword in java?
a. import
b. super
c. method
d. class
Answer :- c
5. Consider the following program.
What will be the output of the program if it is executed?
a. 12 20 13
b. 12 20 15
c. 12 20 015
d. 12 20 F
Answer :- a
6. Match the following java terms with their descriptions?
a. A-1. B-2, C-3
b. A-2, B-3. C-1
c. A-3, B-2,C-1
d. A-3, B-1.C-2
Answer :- a
7. Consider the following program.
What will be the output of the program if it is executed ?
a. 20
b. 2
C. Compiler error
d. 40
Answer :- c
8. What is the output of the following code?
a. null
b. true
c. false
d. 1
Answer :- c
9. Which program is used to compile Java source code into bytecode?
a. javap
b. javac
C. java
d. javad
Answer :- b
10. Consider the following program.
What will be the output of the program if it is executed?
a. 50
b. 10
c. Compiler error
d. 5
Answer :- a
NPTEL Programming In Java Week 1 Programming Assignment Answers
Complete the code segment to find the perimeter and area of a circle given a value of radius.
1.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 “.
if (radius <= 0) { System.out.println("Please enter a non-zero positive number."); } else { perimeter = 2 * Math.PI * radius; area = Math.PI * radius * radius; System.out.println(perimeter); System.out.println(area); }
2. Complete the code segment to find the largest among three numbers x,y, and z. You should use if-then-else construct in Java.
if (x >= y && x >= z) { result = x; } else if (y >= z) { result = y; } else { result = z; } System.out.println(result);
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
int result = 0; int i = 0; while (result < n) { if (i % 2 == 0) { if (i % 3 == 0) { sum = sum + i; } result = result + 1; } i = i + 2; } System.out.print(sum);
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 = 13+53+33, 370, 371, 407, etc.
int originalNumber = n; int sum = 0; // Rename 'result' to 'sum' // Calculate the sum of cubes of digits while (n > 0) { int digit = n % 10; sum += digit * digit * digit; n /= 10; } // Check if the sum is equal to the original number if (sum == originalNumber) { System.out.println("1"); // Armstrong number } else { System.out.println("0"); // Not an Armstrong number }
5. Complete the code segment to help Ragav , find the highest mark and average mark secured by him in “s” number of subjects.
int highestMark = arr[0]; for (i = 1; i < arr.length; i++) { if (arr[i] > highestMark) { highestMark = arr[i]; } } // Calculate the average mark int sum = 0; for (i = 0; i < arr.length; i++) { sum += arr[i]; } mark_avg = (double) sum / arr.length; System.out.println(highestMark); System.out.println(mark_avg);
NPTEL Programming In Java Assignment 1 Answers 2022 [July-Dec]
1. Consider the following program.
What will be the output of the program if it is executed?
a. 15
b. 12
C. 14
d. 10
ANSWER:- a
2. Following is a piece of code where some parts of a statement is missing:
a. nptel[nptel.length-2] + nptel[0]
b. nptel[O] + nptel[nptel.length-2]
c. +nptel[nptel.length-2] + nptel[0]
d. +nptel[0] + nptel[nptel.length-2]
ANSWER:- d
3. Consider the following program.
What will be the output of the progran if it is executed?
a. Print the value of N!
b. Print the value of NN+1)/2
c. Print the value of 1x3x5x.. xN
d. Print the value of 1!x2!x3!x…xN!
ANSWER:- a
4. Which of the following can be used for a variable name in Java?
a. byte
b. throw
c. this
d. extend
ANSWER:- d
5. Consider the following program.
What will be the output of the program if it is executed? Let N=10
a. 5
b. 20
C. 8
d. 10
ANSWER:- c
6. A platform is the hardware or software environment in which a program runs. Which of the following is/are Java platform component(s)?
a. HTML
b. Java Virtual Machine
c. Java Application Programming Interface (API)
d. HotJava
ANSWER:- b, c
7. What is the value returned by the method f() defined below ? public static int f (int x, int y) {return (x>y) ? y: x;}
a. The sum of x and y that is, x + y.
b. The difference of x and y that is, x – y.
c. a. The maxinmum ofx and y that is, the larger value of x and y.
d. The minimum ofx and y that is, the smaller value of x and y.
ANSWER:- For Answer Click Here
8. A Java file with extension ‘.class’ contains
a. Java source code
b. HTML tags
c. Java Byte code
d. A program file written in Java programming language
ANSWER:- c
9. Which of the following is used to find and fix bugs in the Java programs?
a. VM
b. JRE
C. JDK
d. JDB
ANSWER:- d
10. Consider the following program.
What will be the output of the program if it is executed?
a. Print first six even numbers.
b. Print first six odd numbers.
C. Print first five even numbers.
d. Print first six Fibonacci numbers
ANSWER:- d
Programming In Java Week 1 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 “
Code:-
//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.
Code:-
//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.
Code:-
for (int i = 0; i < (n*2)-1; i++)
{
if (i%2==0){
sum = sum + i;
}
}
sum = sum/3;
System.out.print(sum);
Q4. Complete the code segment to check whether the number is an Armstrong number or not.
Code:-
//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.
Code:-
//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);
For More NPTEL Answers:- CLICK HERE
Join Our Telegram:- CLICK HERE
About Programming In Java
With the growth of Information and Communication Technology, there is a need to develop large and complex software. Further, those software should be platform independent, Internet enabled, easy to modify, secure, and robust. To meet this requirement object-oriented paradigm has been developed and based on this paradigm the Java programming language emerges as the best programming environment. Now, Java programming language is being used for mobile programming, Internet programming, and many other applications compatible to distributed systems. This course aims to cover the essential topics of Java programming so that the participants can improve their skills to cope with the current demand of IT industries and solve many problems in their own filed of studies.
COURSE LAYOUT
- Week 1 : Overview of Object-Oriented Programming and Java
- Week 2 : Java Programming Elements
- Week 3 : Input-Output Handling in Java
- Week 4 : Encapsulation
- Week 5 : Inheritance
- Week 6 : Exception Handling
- Week 7 : Multithreaded Programming
- Week 8 : Java Applets and Servlets
- Week 9 : Java Swing and Abstract Windowing Toolkit (AWT)
- Week 10 : Networking with Java
- Week 11: Java Object Database Connectivity (ODBC)
- Week 12: Interface and Packages for Software Development
CRITERIA TO GET A CERTIFICATE
Average assignment score = 25% of average of best 8 assignments out of the total 12 assignments given in the course.
Exam score = 75% of the proctored certification exam score out of 100
Final score = Average assignment score + Exam score
YOU WILL BE ELIGIBLE FOR A CERTIFICATE ONLY IF AVERAGE ASSIGNMENT SCORE >=10/25 AND EXAM SCORE >= 30/75. If one of the 2 criteria is not met, you will not get the certificate even if the Final score >= 40/100.
Please post the answer of week 2
ok Sure it will be added soon
Also thank you for Posting answers 🌝❤️
Most Welcome
can u please post the ans of statistical learning and eleability analysis