Questions List
Browse all explanatory questions of this chapter.
(x) Give the output of the following program segment and specify how many times the loop is executed.
String s = "JAVA"; for(i=0; i
(ix)
(a) Write the Java statement to initialize the first 6 odd numbers in a 3 × 2 array.
(b) What is the result of x[0][1] + x[2][1] of the above array?
(viii) Consider the following array and answer the questions given below:
int a[ ] = {12,10,8,4,6,2,3,5,7};
(a) What is the output of System.out.print(a[0] + a[5]);?
(b) What is the index (subscript) of the largest element of the array a[ ]?
(vii)
John was asked to write a Java code to calculate the surface area of a cone. The following code was written by him:
Formula:
Surface area of a cone is A = πrℓ, where ℓ = √(r² + h²)
class area { double area(double r, double h) { double l, a; a = 22.0/7 * r * l; l = Math.sqrt(r * r + h * h); return a; } }
Task:
(a) Specify the type of error in the above program.
(b) Correct the program and write the error-free version.
(vi)
(a) Name one String method which results in a positive integer only.
(b) Name one String method which results in a character.
(v) Consider the following Java program and determine its output:
class report
{
int a, b;
report()
{
a = 10;
b = 15;
}
report(int x, int y)
{
a = x;
b = y;
}
void print()
{
System.out.println(a * b);
}
public static void main(String[] args)
{
report r = new report();
r.print();
report p = new report(4, 5);
p.print();
}
}
(iv) Convert the given loop into exit controlled loop.
int a, b;
for ( a=10 , b=1; a>=1 ; a-=2)
{
b+=a;
b++;
}
System.out.print(b);
(iii) Write the Java statement for creating an object named 'sifra' of the class 'Robot', which takes three double parameters.
(ii)
Write the output of the following String method:
String x= "talent"; String y="matrix";
System.out.print(x.substring(3).concat(y.substring(3)));
(i) Write the java expression to find the product of square root of P and the square root of Q using the methods of Math class.
Give the output of the following program segment. How many times is the loop executed?
for(x=10; x>20; x++)
System.out.println(x);
System.out.println(x*2);
Write the value of n after execution:
char ch ='d'; int n = ch + 5;
Name the following:
(a) What is an instance of the class called?
(b) The method which has same name as that of the class name.
Consider the given array and answer the questions given below:
int x[ ] = {4, 7, 9, 66, 72, 0, 16};
(a) What is the length of the array?
(b) What is the value in x[4]?
Give the output of the following String class methods:
(a) "COMMENCEMENT".lastIndexOf('M')
(b) "devote".compareTo("DEVOTE")
Give the output of the following program segment:
int n = 4279; int d;
while(n > 0)
{ d = n % 10;
System.out.println(d);
n = n / 100;
}
Rewrite the following code using the if-else statement:
int m = 400;
double ch = (m>300) ? (m / 10.0) * 2 : (m / 20.0) - 2;
Give the output of the following Character class methods:
(a) Character.toUpperCase ('a')
(b) Character.isLetterOrDigit('#')
Convert the following do…while loop to for loop:
int x = 10;
do
{
x––;
System.out.print(x);
}
Evaluate the expression when the value of x = 4: \[ x *= --x + x++ + x \]
Write the Java expression for \[ (a + b)^x \]
ফটোট্যাকটিক চলন (Phototactic Movement)
ট্যাকটিক চলন কয় প্রকার
আবিষ্ট বা ট্যাকটিক চলন কাকে বলে, ট্যাকটিক চলন কাকে বলে
উদ্ভিদের চলন কত প্রকার ও কি কি
চলন গতি কয় প্রকার
চলন গতি কাকে বলে
বক্র চলন কাকে বলে
প্রকরণ চলন কাকে বলে
উদ্ভিদের চলন এর উদ্দেশ্য
চলন কাকে বলে
i) Ramesh is trying to write a program to check whether a number is palindrome or not. Due to confusion in the syntax of some of the statements. he could not complete the program and has left some places blank marked with ?1?, ?2?, ?3? and ?4? to be filled with expression function. The incomplete program is shown below:
Based on the above discussion. answer the following questions :-
a) What expression will be filled in place of ?1?
b) What expression will be filled in place of ?2?
c) What expression will be filled in place of ?3?
d) What expression will be filled in place of ?4?
import java.util.*; class Palindrome { public static void main(String args[]) { Scanner sc = new Scanner(System.in); int copy, n, rev = 0; System.out.println("Enter the number"); n = sc.nextInt(); copy = n; while (n != 0) { int r = ?1?; // Place 1 rev = ?2?; // Place 2 n = ?3?; // Place 3 } if (?4?) { // Place 4 System.out.println("Palindrome"); } else { System.out.println("Not palindrome"); } } }
What will be the output of the following program segment?
int a[] = {1, 2, 3, 4, 5, 6, 7, 9, 13, 16};
x = Math.pow(a[4], a[2]);
y = Math.sqrt(a[6] + a[7]);
What will be the output of the following program segment?
int ar[] = {1, 2, 3, 4, 5};
int a = 1;
for (int i = 0; i < 7; i++) {
a = a + i * ar[i];
}
System.out.println(a);
Convert the following segment into an equivalent do- while loop.
int a, b;
for (a = 10, b = 20; b >= 10; b = b - 2) {
a++;
}
Differentiate between the following code fragments and also give their output :-
int f = 1, i = 2;
while (++i < 5)
f *= i;
System.out.println(f);
int f = 1, i = 2;
do {
f *= i;
} while (++i < 5);
System.out.println(f);
Write the output of the following code :-
String x;
String str = "INFORMATION";
x = str.concat("PRACTICE");
System.out.println(x.length());
System.out.println(x.toUpperCase());
c) If a=24, b=15. find the value of a+=b++ * 5/a++ +b
Rewrite the following code using switch case statement
if (value == 1) {
System.out.println("1st division");
} else if (value == 2) {
System.out.println("2nd division");
} else if (value == 3) {
System.out.println("3rd division");
} else {
System.out.println("Wrong choice");
}
Write the following lava Expression :- \[ z = x^3 + y^2 - \sqrt{xy} \]
(h) Evaluate the following expression if the value of x=2, y=3 and z=1.
v=x + --z + y++ + y
Question 3
Question 2
Question 1
(a) Write a Java expression for the following:
\[ \lvert x^2 + 2xy \rvert \]
(b) Write the return data type of the following functions:
- startsWith()
- random()
(c) If the value of basic=1500, what will be the value of tax after the following statement is executed?
tax = basic > 1200 ? 200 :100;
(d) Give the output of following code and mention how many times the loop will execute?
int i; for( i=5; i>=1; i--) { if(i%2 == 1) continue; System.out.print(i+" "); }
(e) State a difference between call by value and call by reference.
(f) Give the output of the following:
Math.sqrt(Math.max(9,16))
(g) Write the output for the following:
String s1 = "phoenix"; String s2 ="island"; System.out.println(s1.substring(0).concat(s2.substring(2))); System.out.println(s2.toUpperCase());
(h) Evaluate the following expression if the value of x=2, y=3 and z=1.
v=x + --z + y++ + y
(i) String x[] = {"Artificial intelligence", "IOT", "Machine learning", "Big data"};
Give the output of the following statements:
- System.out.println(x[3]);
- System.out.println(x.length);
(j) What is meant by a package? Give an example.
(a) Differentiate between if else if and switch-case statements
(b) Give the output of the following code:
String P = "20", Q ="19"; int a = Integer.parseInt(P); int b = Integer.valueOf(Q); System.out.println(a+""+b);
(c) What are the various types of errors in Java?
(d) State the data type and value of res after the following is executed:
char ch = '9'; res= Character.isDigit(ch);
(e) What is the difference between the linear search and the binary search technique?
(a) Name any two basic principles of Object-oriented Programming.
Answer
- Encapsulation
- Inheritance
(b) Write a difference between unary and binary operator.
(c) Name the keyword which:
- indicates that a method has no return type.
- makes the variable as a class variable
(d) Write the memory capacity (storage size) of short and float data type in bytes.
(e) Identify and name the following tokens: