Programming In Java | Week 1
Session: JAN-APR 2024
Course name: Programming In Java
Course Link: Click Here
For answers or latest updates join our telegram channel: Click here to join
These are NPTEL Programming In Java Week 1 Assignment 1 Answers
Q1. What is the primary focus of Java programming?
a. Low-level optimizations
b. Hardware-specific operations
c. Platform independence
d. Assembly language programming
Answer: c. Platform independence
Q2. Which of the following programming principles is a key aspect of Java?
a. Code obfuscation
b. Platform dependence
c. Object-oriented programming
d. Global variables
Answer: c. Object-oriented programming
Q3. What is the last step in the Java programming process?
a. Java Program Execution
b. Java Program Editing
c. Java Program Compilation
d. C/C++ versus Java
Answer: a. Java Program Execution
For answers or latest updates join our telegram channel: Click here to join
These are NPTEL Programming In Java Week 1 Assignment 1 Answers
Q4. Which of the following is NOT a Java programming tool?
a. Eclipse
b. NetBeans
c. IntelliJ IDEA
d. GCC
Answer: d. GCC
Q5. What does the term “Write Once, Run Anywhere” (WORA) imply in Java?
a. Code reusability
b. Platform independence
c. Cross-compilation
d. Dynamic typing
Answer: b. Platform independence
Q6. In Java, what is used to store multiple values of the same type?
a. Structures
b. Pointers
c. Arrays
d. Lists
Answer: c. Arrays
For answers or latest updates join our telegram channel: Click here to join
These are NPTEL Programming In Java Week 1 Assignment 1 Answers
Q7. Which of the following is a valid identifier in Java?
a. 123identifier
b. _identifier
c. #identifier
d. identifier-123
Answer: b. _identifier
Q8. What is the purpose of Java Language Subset?
a. To limit the capabilities of Java
b. To make Java code compatible with other languages
c. To define a smaller set of Java features for specific purposes
d. To enhance the performance of Java programs
Answer: c. To define a smaller set of Java features for specific purposes
Q9. What is the primary purpose of the Java Virtual Machine (JVM) in the Java programming language?
a. Code optimization
b. Platform independence
c. Memory management
d. Hardware-specific operations
Answer: b. Platform independence
Q10. What is emphasized during the Java Program Editing phase?
a. Writing platform-specific code
b. Debugging the program
c. Compiling the program
d. Writing and modifying the source code
Answer: d. Writing and modifying the source code
For answers or latest updates join our telegram channel: Click here to join
These are NPTEL Programming In Java Week 1 Assignment 1 Answers
More Weeks of Programming In Java: Click here
More Nptel Courses: https://progiez.com/nptel-assignment-answers
Session: JULY-DEC 2023
Course Name: Programming In Java
Course Link: Click Here
These are NPTEL Programming In Java Week 1 Assignment 1 Answers
Programming Assignment
Question 1
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:
if(radius<=0)
{
System.out.println("please enter non zero positive number ");
}
else
{
perimeter = 2 * Math.PI * radius;
area = Math.PI * radius * radius;
System.out.println(perimeter);
System.out.println(area);
}
Question 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.
Solution:
if(x >= y && x >= z)
{
result=x;
}
else if(y >= z)
{
result=y;
}
else
{
result=z;
}
System.out.print(result);
These are NPTEL Programming In Java Week 1 Assignment 1 Answers
Question 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
Solution:
int result=1;
int i=0;
while(result<=n)
{
if(i%2==0)
{
if(i%3==0)
{
sum=sum+i;
}
result=result+1;
}
i=i+1;
}
System.out.println(sum);
Question 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.
Solution:
int temp=n;
int c=0,t;
while(n>0)
{
t=n%10;
n=n/10;
c=c+(t*t*t);
}
if(temp==c)
result=1;
else
result=0;
System.out.println(result);
These are NPTEL Programming In Java Week 1 Assignment 1 Answers
Question 5
Complete the code segment to help Ragav , find the highest mark and average mark secured by him in “s” number of subjects.
Solution:
int max=arr[0];
double sum=arr[0];
for(i=1;i<arr.length;i++)
{
sum=sum+arr[i];
if(arr[i]>max)
max =arr[i];
}
result=max;
mark_avg=sum/(arr.length);
System.out.println(result);
System.out.println(mark_avg);
These are NPTEL Programming In Java Week 1 Assignment 1 Answers
More Weeks of Programming In Java: Click here
More Nptel Courses: Click here
Session: JAN-APR 2023
Course Name: NPTEL Programming In Java Assignment
These are NPTEL Programming In Java Week 1 Assignment 1 Answers
Week 2: Click Here
Quiz
Q1) What is the incorrect statement about bytecode?
a. Java when compiles the source code, it converts it to bytecode.
b. JVM (Java Virtual Machine) is an interpreter of bytecode.
c. Bytecode is not portable and it needs to be compiled separately for each platform.
d. JVM offers a protected environment which helps in enhanced safety for the system.
Answer: c. Bytecode is not portable and it needs to be compiled separately for each platform.
Q2) Consider the following program
What is the output of the above code?
a. a
b. Compiler error due to line n1
c. Compiler error due to line n2
d. Print nothing
Answer: d. Print nothing
Q3) Which one of the following is not a primitive datatype?
a. byte
b. short
c. class
d. long
Answer: c. class
These are NPTEL Programming In Java Week 1 Assignment 1 Answers
Q4) Which of the following is not a keyword in java?
a. final
b. super
c. integer
d. extend
Answer: c, d
Q5) Consider the following program
What will be the output of the program if it is executed?
a. 15-even-1
b. 15-odd-1
c. 15-even-
d. 15-odd-
Answer: b. 15-odd-1
Q6) Why does the error “javac is not recognized as an internal or external command” occur?
a. Path is not set for java
b. JDK is not correctly installed
c. .class file is not found
d. javac jar is missing from java library
Answer: a. Path is not set for java
These are NPTEL Programming In Java Week 1 Assignment 1 Answers
Q7) Following is a piece of code where some parts of a statement is missing:
In the following, some options are given. You have to choose the correct option(s) for the argument in System.out.print() function to print the value 102.
a. nptel[nptel.length-2] + nptel[0]
b. nptel[0] + nptel[nptel.length-2]
c. “” + nptel[nptel.length-2] + nptel[0]
d. “” + nptel[0] + nptel[nptel.length-2]
Answer: a, b
Q8) Which of the following concept that Java doesn’t support?
a. inheritance
b. serialization
c. goto
d. array
Answer: c. goto
Q9) The subsystem of JVM that is used to load class files is known as ______.
a. Classloader
b. JRE
c. JDK
d. Compiler
Answer: a. Classloader
These are NPTEL Programming In Java Week 1 Assignment 1 Answers
Q10) What is the value of total after executing the following code snippet?
int mark = 5;
int grace = 2;
int total = mark + (mark > 6 ? ++grace : –grace);
a. 6
b. 5
c. 4
d. 3
Answer: a. 6
Assignment Solution
Question 1
Complete the code segment to help Ragav , find the highest mark and average mark secured by him in “s” number of subjects.
Solution:
//Code
These are NPTEL Programming In Java Week 1 Assignment 1 Answers
Question 2
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
Solution:
//Code
These are NPTEL Programming In Java Week 1 Assignment 1 Answers
Question 3
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:
//Code
These are NPTEL Programming In Java Week 1 Assignment 1 Answers
Question 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.
Solution:
//Code
These are NPTEL Programming In Java Week 1 Assignment 1 Answers
Question 5
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:
//Code
Session: JULY-DEC 2022
These are NPTEL Programming In Java Week 1 Assignment 1 Answers
1. What of the following can be used for a variable name in java?
a. Byte
b. Throw
c. This
d. Extend
Answer: Please login to see answer.
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: Please login to see answer.
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
These are NPTEL Programming In Java Week 1 Assignment 1 Answers
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: Please login to see answer.
5. Which of the following is used to find and fix bus in the Java programs?
- JVM
- JRE
- JDK
- JDB
Answer: Please login to see answer.
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
These are NPTEL Programming In Java Week 1 Assignment 1 Answers
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: Please login to see answer.
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
These are NPTEL Programming In Java Week 1 Assignment 1 Answers
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:-
//Code
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:-
//Code
These are NPTEL Programming In Java Week 1 Assignment 1 Answers
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:-
//Code
4. Complete the code segment to check whether the number is an Armstrong number or not.
SOLUTION:-
//Code
These are NPTEL Programming In Java Week 1 Assignment 1 Answers
Q5. Complete the code segment to help Ragav , find the highest mark and average mark secured by him in “s” number of subjects.
SOLUTION:-
//Code
* The material and content uploaded on this website are for general information and reference purposes only. Please do it by your own first. COPYING MATERIALS IS STRICTLY PROHIBITED.
These are NPTEL Programming In Java Week 1 Assignment 1 Answers
MORE NPTEL ANSWERS: CLICK HERE