Home | Contact
aashray | Logout
Home
Resources
Class X
Class XII
Videos
Gallery
Forum
Fun
Friends (0)
Friend Requests
You have no new friend request.
Tutorials
Programming In Java
English
Computer Practical
Viva-Voce
Quick Links
For-loop
While-loop
Do-while loop
Arrays 1D
Arrays 2D
Strings
Functions
Function overloading
Recursive Functions
ISC Computer Practical 2012 Solved
1. A prime palindrome integer is a positive integer (without leading zeros) which is
prime as well as a palindrome. Given two positive integers m and n, where m <
n, write a program to determine how many prime-palindrome integers are there
in the range between m and n (both inclusive) and output them.
The input contains two positive integers m and n where m < 3000 and n <
3000. Display the number of prime palindrome integers in the specified range
along with their values in the format specified below:
Test your program with the sample data and some random data:
Example 1:
INPUT: m=100
N=1000
OUTPUT: The prime palindrome integers are:
101,131,151,181,191,313,351,373,383,727,757,787,797,919,929
Frequency of prime palindrome integers: 15
Example 2:
INPUT:
M=100
N=5000
OUTPUT: Out of range
View/Hide Solution
import java.util.*;
class ISC2012q01
{
public static void main (String args[])
throws InputMismatchException
{
Scanner scan = new Scanner(System.in);
int m,n,i,j,t,c,r,a,freq;
System.out.println("Enter two positive integers m and n,
where m < 3000 and n < 3000: ");
m = scan.nextInt();
n = scan.nextInt();
if(m < 3000 && n < 3000){
// To count the frequency of prime-palindrome numbers
freq = 0;
System.out.println("The prime palindrome integers are:");
for(i=m;i<=n;i++){
t = i;
//Check for prime
c = 0;
for(j =1; j<=t; j++){
if(t%j == 0)
c++;
}
if(c == 2){
//Check for palindrome
r = 0;
while(t>0){
a = t%10;
r = r*10 + a;
t = t/10;
}
if(r == i){
System.out.print(i+" ");
freq++;
}
}
}
System.out.println("\nFrequency of prime palindrome
integers:"+freq);
}else{
System.out.println("OUT OF RANGE");
}
}//end of main
}//end of class
2. Write a program to accept a sentence as input. The words in the string are to be
separated by a blank. Each word must be in upper case. The sentence is
terminated by either '.','!' or '?'. Perform the following tasks:
1. Obtain the length of the sentence (measured in words)
2. Arrange the sentence in alphabetical order of the words.
Test your program with the sample data and some random data:
Example 1:
INPUT: NECESSITY IS THE MOTHER OF INVENTION.
OUTPUT:
Length: 6
Rearranged Sentence:
INVENTION IS MOTHER NECESSITY OF THE
Example 2:
INPUT: BE GOOD TO OTHERS.
OUTPUT:
Length: 4
Rearranged Sentence: BE GOOD OTHERS TO
View/Hide Solution
import java.io.*;
class ISC2012q02
{
public static void main (String args[])throws IOException
{
BufferedReader br=new BufferedReader(
new InputStreamReader (System.in));
int i,j,l,p,x,now;
String str,word,temp;
char ch;
System.out.println("Enter a sentence ");
str = br.readLine();
l = str.length();
now = 0; //To count the
number of words
for(i=0;i< l;i++){
ch = str.charAt(i);
if(ch == ' ' || ch == '?' || ch == '.'
|| ch == '!')
now++;
}
String words[] = new String[now];
x=0; //Used as index pointer for string array
p=0; //To store the index of first letter of each word
for(i=0;i< l;i++){
ch = str.charAt(i);
if(ch == ' ' || ch == '?' || ch == '.'
|| ch == '!'){
word = str.substring(p,i);
words[x++] = word;
p = i+1;
}
}
//Sort the words in string array in alphabetical order
for(i=1; i< x; i++){
for(j=0; j< x-i; j++){
if(words[j].compareTo(words[j+1]) > 0){
temp = words[j];
words[j] = words[j+1];
words[j+1] = temp;
}
}
}
System.out.println("Length: "+now);
System.out.println("Rearranged sentence: ");
for(i=0; i< x; i++){
System.out.print(words[i]+" ");
}
}//end of main
}//end of class
3. Write a program to declare a matrix A [][] of order (MXN) where 'M' is the
number of rows and 'N' is the number of
columns such that both M and N must be greater than 2 and less than 20. Allow
the user to input integers into this matrix.
Perform the following tasks on the matrix:
1. Display the input matrix
2. Find the maximum and minimum value in the matrix and display them along
with their position.
3. Sort the elements of the matrix in ascending order using any standard sorting
technique and rearrange them in the matrix.
Output the rearranged matrix.
Sample input Output
INPUT:
M=3
N=4
Entered values: 8,7,9,3,-2,0,4,5,1,3,6,-4
Original matrix:
8793
-2 0 4 5
1 3 6 -4
Largest Number: 9
Row: 0
Column: 2
Smallest Number: -4
Row=2
Column=3
Rearranged matrix:
-4 -2 0 1
3345
6789
View/Hide Solution
import java.util.*;
class MatrixSort
{
public static void main (String args[])
throws InputMismatchException
{
Scanner scan = new Scanner(System.in);
int m,n,i,j,x,t,smallest,rowS,colS,largest,rowL,colL;
System.out.println("Enter two positive integers m and n,
where 2 < m,n < 20: ");
m = scan.nextInt();
n = scan.nextInt();
if(m > 2 && m < 20 && n > 2 && n < 20){
int a[][] = new int[m][n];
System.out.println("Enter " + (m*n) + " elements: ");
for(i=0;i< m;i++){
for(j=0;j< n;j++){
a[i][j] = scan.nextInt();
}
}
System.out.println("Original Matrix: ");
for(i=0;i< m;i++){
for(j=0;j< n;j++){
System.out.print(a[i][j]+ " ");
}
System.out.println();
}
smallest = largest = a[0][0];
rowS = colS = rowL = colL = 0;
//1-D array to store the elements of the matrix
int b[] = new int[m*n];
x=0;
for(i=0;i< m;i++){
for(j=0;j< n;j++){
//Store elements into a 1-D array
b[x++] = a[i][j];
if(smallest > a[i][j]){
smallest = a[i][j];
rowS = i;
colS = j;
}
if(largest < a[i][j]){
largest = a[i][j];
rowL = i;
colL = j;
}
}
}
//Sort the elements in ascending order using bubble sort
for(i=1;i< x;i++){
for(j=0;j< x-i;j++){
if(b[j] > b[j+1]){
t = b[j];
b[j] = b[j+1];
b[j+1] = t;
}
}
}
//Put the sorted elements back into the matrix
x=0;
for(i=0;i< m;i++){
for(j=0;j< n;j++){
a[i][j] = b[x++];
}
}
System.out.println("\n Largest Number: "+largest);
System.out.println("Row: "+rowL);
System.out.println("Column: "+colL);
System.out.println("Smallest Number: "+smallest);
System.out.println("Row: "+rowS);
System.out.println("Column: "+colS);
System.out.println("Rearranged Matrix: ");
for(i=0;i< m;i++){
for(j=0;j< n;j++){
System.out.print(a[i][j]+ " ");
}
System.out.println();
}
}else{
System.out.println("Invalid value!");
}
}//end of main
}//end of class
Recently Registered
Guess Questions
Ask a Question
View All Questions
Do you know?
The fingerprints of koala bears are virtually indistinguishable from those of humans, so much so that
they could be confused at a crime scene.
Quote Of The Day
The virtue lies in the struggle, not in the prize. - Richard Monckton Milnes
View all quotes
2014 Mentors. All Rights Reserved. Privacy Policy and Terms of Use
Mon Sep 01 2014 18:19:40 GMT+0530 (India Standard Time)