Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 12

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 2013 Solved


1. An ISBN ( International Stanadar Book Number) is a ten digit code which
uniquely identifies a book. The first nine digits represent the Group, Publisher
and Title of the book and the last digit is used to check whehter ISBN is correct

or not. Each of the first nine digits of the code can take a value between 0 and
9. Sometimes it is necessary to make the last digit equal to ten; this is done by
writing the last digit of the code as X. To verify an ISBN, calculate 10 times the
first digit, plus 9 times the second digit, plus 8 times the third and so on until we
add 1 time the last digit. If the final number leaves no remainder when divided
by 11, the code is a valid ISBN.
For example:
1. 02011003311 = 10*0 + 9*2 + 8*0 + 7*1 + 6*1 + 5*0 + 4*3 + 3*3 + 2*1
+ 1*1 = 55
Since 55 leaves no remainder when divisible by 11, hence it is a valid ISBN.
Design a program to accept a ten digit code from the user. For an invalid inout,
display an
appropriate message. Verify the code for its validity in the format specified
below:
Test your program with sample data and some random data.
Example 1
INPUT CODE : 0201530821
OUTPUT : SUM = 99
LEAVES NO REMAINDER - VALID ISBN CODE
Example 2
INPUT CODE : 035680324
OUTPUT : INVALID INPUT
Example 1
INPUT CODE : 0231428031
OUTPUT : SUM = 122
LEAVES REMAINDER - INVALID ISBN CODE

View/Hide Solution

import java.io.*;

class ISCPrac2013Q1{

public static void main(String args[])throws IOException{

BufferedReader br = new BufferedReader(


new InputStreamReader(System.in));

System.out.println("INPUT CODE: ");


String isbn = br.readLine();

int l = isbn.length();
int i, t, ctr, s;
char ch;

if(l!= 10){

System.out.println("INVALID INPUT");

}else{
//PROCEED WITH COMPUTATION ONLY IF ISBN CODE CONTAINS 10 DIGITS
ctr = 10;
s = 0;

for(i=0;i < l;i++){

ch = isbn.charAt(i);

if(ch == 'X') //X REPRESENTS 10 IN ISBN CODE

t = 10;
else
t = ch - 48; //NUMERIC VALUE OF THE ASCII CODE OF DIGIT

s= s + ctr*t; //PERFORM COMPUTATION

ctr--;
}//END OF FOR LOOP

//IF SUM IS DIVISIBLE BY 11, IT IS A VALID ISBN CODE


if(s%11 == 0){
System.out.println("SUM = "+s);
System.out.println("LEAVES NO REMAINDER - VALID ISBN CODE");
}else{
System.out.println("SUM = "+s);
System.out.println("LEAVES REMAINDER - INVALID ISBN CODE");
}
}//END OF OUTERMOST ELSE

}//END OF MAIN
}//END OF CLASS

// EXAMPLE 1
// INPUT CODE:
// 0201103311
// SUM = 55
// LEAVES NO REMAINDER - VALID ISBN CODE

//EXAMPLE 2

// INPUT CODE:
// 0231428031
// SUM = 122
// LEAVES REMAINDER - INVALID ISBN CODE
//

2. Write a program to declare a square matrix A[][] of order (M X M) where 'M' is


the number of rows and the number of columns such that M must be greater
than 2 and less than 20. Allow the user to input integers into this matrix. Display
appropriate error message for an invalid input. Perform the following tasks:
(a) Display the input matrix.
(b) Create a mirror image of the inputted matrix.
(c) Display the mirror image matrix.
Test your program for the following data and some random data:
Example 1
3.

INPUT

M = 3

4.
5.

16

12

6.

14

7.

8.

OUTPUT

9.
10.

ORIGINAL MATRIX

11.
12.

16

12

13.

14

14.

15.
16.

MIRROR IMAGE MATRIX

17.
18.

12

16

19.

14

20.

Example 2
INPUT

M = 22

OUTPUT

SIZE OUT OF RANGE

View/Hide Solution

import java.util.*;

class ISCPrac2013Q2{
public static void main(String[]args)throws InputMismatchException
{

int M, i, j, k, t;

Scanner scan = new Scanner(System.in);


System.out.println("Enter no of rows for a square matrix: ");
M= scan.nextInt();

if(M<=2 || M>=20){
System.out.println("\nSIZE OUT OF RANGE");
}else{

int A[][] = new int [M][M];

System.out.println("Enter "+(M*M) + " elements: ");


for(i=0;i < M;i++){
for(j=0;j < M;j++){
A[i][j] = scan.nextInt();
}
}

//DISPLAY THE ORIGINAL MATRIX


System.out.println("ORIGINAL MATRIX");
for(i=0;i < M;i++){
for(j=0;j < M;j++){
System.out.print(A[i][j]+" ");
}
System.out.println();
}

//USE TWO COUNTERS FOR ACCESSING COLUMNS // ONE INCREMENTAL, ONE DECREMENTAL

for(j=0, k = M-1; j < M/2; j++, k--){

for(i=0;i < M; i++){


//SWAP THE ELEMENTS OF THE FIRST COLUMN WITH THE LAST,
//SECOND COLUMN WITH SECOND LAST AND SO ON

t = A[i][j];
A[i][j] = A[i][k];
A[i][k] = t;

}
}

//DISPLAY THE MIRROR IMAGE MATRIX


System.out.println("ORIGINAL MATRIX");
for(i=0;i < M;i++){
for(j=0;j < M;j++){
System.out.print(A[i][j]+" ");
}
System.out.println();
}

}//END OF ELSE

}//END OF MAIN
}//END OF CLASS

//EXAMPLE
// Enter no of rows for a square matrix:
// 3
// Enter 9 elements:
// 4
// 16
// 12
// 8
// 2
// 14
// 6

// 1
// 3
// ORIGINAL MATRIX
// 4 16 12
// 8 2 14
// 6 1 3
// ORIGINAL MATRIX
// 12 16 4
// 14 2 8
// 3 1 6

21. A palindrome is a word that may be read the same way in either direction.
Accept a sentence in UPPER CASE which is terminated by either ".", "?", or "!".
Each word of the sentence is separated by a single blank space.
Perform the following taks:
(a) display the count of palindromic words in the sentence.
(b) Display the palindromic words in the sentence.
Example of palindromic words:
MADAM, ARORA, NOON
Test your program with the sample data and some random data:
Example 1
22.

INPUT

MOM AND DAD ARE COMING AT NOON

23.

OUTPUT

MOM DAD NOON

24.

NUMBER OF PALINDROMIC WORDS : 3

Example 2
INPUT

OUTPUT

HOW ARE YOU?


NO PALINDROMIC WORDS

View/Hide Solution

import java.io.*;

class ISCPrac2013Q3{

public static void main(String args[])throws IOException{

BufferedReader br = new BufferedReader(


new InputStreamReader(System.in));
String str, t, r;
int l, i, c;
char ch;

System.out.println("Enter a sentence (terminated by '.',


'?', '!') : ");
str = br.readLine();
l = str.length();

c = 0; // TO COUNT PALINDROMIC WORDS


t = ""; // TO STORE A WORD
r = ""; // TO STORE THE REVERSED WORD

for(i=0; i < l; i++){


ch = str.charAt(i);
//CHECK FOR BLANK OR SENTENCE TERMINATOR
if(ch == ' ' || ch == '.' || ch == '?' || ch == '!'){
//IF BOTH THE WORD AND REVERSED WORD MATCH, IT IS A PALINDROME
if(t.equals(r)){
System.out.print(t+" ");
c++;
}
//RESET THE VARIABLES TO STORE THE NEXT WORD
t = "";
r = "";
}// IF
else{
//STORING CHARACTERS TO FORM A WORD
t = t + ch;
//STORING CHARACTERS IN REVERSE ORDER TO GET REVERSED WORD
r = ch + r;
}//ELSE
}//END OF FOR LOOP

System.out.println("\nNO OF PALINDROMIC WORDS: "+c);


}//END OF MAIN
}//END OF CLASS

//EXAMPLE 1

// Enter a sentence (terminated by '.', '?', '!') :


// MOM AND DAD ARE COMING AT NOON.

// MOM DAD NOON


// NO OF PALINDROMIC WORDS: 3

Recently Registered

Guess Questions
Ask a Question
View All Questions
Do you know?
A duck's quack doesn't echo, and no one knows why.
Quote Of The Day
Age is a recommendation in four things- old wood to burn, old wine to drink, old friends to trust, and
old books to read. - Alonzo of Aragon
View all quotes
2014 Mentors. All Rights Reserved. Privacy Policy and Terms of Use
Mon Sep 01 2014 18:13:35 GMT+0530 (India Standard Time)

You might also like