Home
/
Questions
/
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");
}
}
}
Explanatory Question
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");
}
}
}
Read the answer carefully and go through the related questions on the right side to improve your understanding of this topic.