Wednesday, May 24, 2017

Pattern on numbers and space


1
1_2
1_2_3
1_2_3_4
1_2_3_4_5
_ stands for space 


class A
{
 int i,j;
public void show()
{
 for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
 System.out.print(j+" ");
}
System.out.println();
}
}
public static void main(String args[])
{
 A ob=new A();
ob.show();
}
}

Pattern on Numbers



13579
35791
57813
79135
91357 

class A
{
 int i,j,x=1,y;
public void show()
{
 for(i=0;i<=4;i++)
{
 y=x;
for(j=0;j<=4;j++)
{
if(y>9)
y=1;
 System.out.print(y);
y=y+2;
}
System.out.println();
x=x+2;
}
}
public static void main(String args[])
{
 A ob=new A();
ob.show();
}
}

Saturday, April 22, 2017

Pattern on Numbers using nested loop



To print the given below pattern

0
0 1
0 2 4
0 3 6 9
0 4 8 12 16
0 5 10 15 20 25
0 6 12 18 24 30 36
0 7 14 21 28 35 42 49
0 8 16 24 32 40 48 56 64
0 9 18 27 36 45 54 63 72 81

Program is as follows:

class B
{
 int i,j,x;
public void show()
{
 for(i=0;i<=9;i++)
{
 System.out.print("0 ");
x=i;
for(j=0;j<=i-1;j++)
{
 System.out.print(x + " ");
x=x+i;
}
System.out.println();
}
}
public static void main(String args[])
{
 B ob=new B();
ob.show();
}
}

Monday, April 3, 2017

2017 ISC Theoretical Paper on Computer with Solutions











Question 2


(a): What is an interface? How it is different from a class? (2)

An interface is like a class but not a class. In an interface, the data members declared are always static final and methods are declared only. A class can implement an interface but can’t extend an interface.

A class contains data members and method members. Methods are defined in a class. The data members and methods members of a class can have any access specifiers – public, private, default or protected and they may be either instance of static member. We can create objects of a defined class.


An interface contains data members which must be static final and method declaration which should be final only. We can’t create objects of an interface but a class can implements number of interfaces.


(b): Convert the following infix expression to postfix form (2)

P * Q / R + (S+T)


PQ*R/ST++

(c): A matrix P[15][10]is stored with each element requiring 8 bytes of storage. If the base address at P[0][0] is 1400, determine the address at P [10][7] when the matrix is stored in row major wise. (2)

(Row major order) Address(Arr[j,k])=base(Arr)+w[n(j-1)+(k-1)] - 'w' is the bytes required for each location and 'n' is length of 2nd dimension
1400 + 8 * [10*9+6]
1400+8*96

2168

Solutions coming Soon...................

Friday, February 3, 2017

2017 ISC Computer Practical Paper Programs with Solutions

  • A Company manufacturing packaging cartoons in four sizes, i,e cartoons to accommodate 6 boxes, 12 boxes, 24 boxes and 48 boxes.Design a program to accept the number of boxes to be packed (N) by the user (maximum upto 1000 boxes) and display the break up of the cartoons used in descending order of capacity. (ie preference should be given to the highest capacity available and if boxes left are less than 6. an extra cartoon of capacity 6 should be used.


Test your program with the following data and some random data:

Example 1: 
INPUT= N=726
OUTPUT= 48 X 15=720
6 X 1=6
Remaining boxes= 0
Total number of boxes= 726
Total Number of cartoons= 16


Example 2: 
INPUT= N=140
OUTPUT= 48 X 2=96
24 x 1= 24
12 x 1= 12
6 x 1= 6
Remaining boxes= 2 x 1= 2

Total number of boxes= 140
Total Number of cartoons= 6


Example 2: 
INPUT= N= 4296
OUTPUT= INVALID INPUT



import java.io.*;
class Pat
{
 BufferedReader br=new BufferedReader (new InputStreamReader(System.in));
int n,no,x,cartoons=0, size=48;
public void takeBoxes() throws Exception
{
 System.out.print("\nEnter the number of boxes:");
 n=Integer.parseInt(br.readLine());
no=n;
if(n >=1001)
{
 System.out.println("INVALID INPUT.");
return;
}
System.out.print("\nOUTPUT:");
while(true)
{
if(n/size!=0)
{
x=n/size;
 System.out.print("\n"+size + "x"+ x + "=" + (size * x));
 cartoons+=n/size;
n=n%size;
}
size=size/2;
if(size==0)
break;
if(n<6 amp="" font="" n="">
{
 cartoons++;
System.out.print("\nRemaining Boxes:" + n + "x 1 ");
break;
}
else if(n==0)
{
 System.out.print("\nRemaining Boxes: 0");
break;
}
}
System.out.print("\nTotal No of Boxes:" + no);
System.out.print("\nTotal No of Cartoons:" + cartoons);
}
public static void main(String args[]) throws Exception
{
 Pat ob=new Pat();
ob.takeBoxes();
}
}



  • The result of a quiz competition is to be prepared as follows:


The quiz has five questions with four multiple choices (A, B, C, D), with each question carrying 1 mark for the correct answer. Design a program to accept the number of participants N such that N must be greater than 3 and less than 11. Create a double dimensional array of size (Nx5) to store the answers of each participant row-wise.
Calculate the marks for each participant by matching the correct answer stored in a single dimensional array of size 5. Display the scores for each participant and also the participant(s) having the highest score.
Example: If the value of N = 4, then the array would be:
Note: Array entries are line fed (i.e. one entry per line)
Test your program with the sample data and some random data:
Example 1
INPUT : N = 5
Participant 1 D A B C C
Participant 2 A A D C B
Participant 3 B A C D B
Participant 4 D A D C B
Participant 5 B C A D D
Key: B C D A A
OUTPUT : Scores :
Participant 1 D A B C C
Participant 1 = 0
Participant 2 = 1
Participant 3 = 1
Participant 4 = 1
Participant 5 = 2
Highest score: Participant 5
Example 2
INPUT : N = 4
Participant 1 A C C B D
Participant 2 B C A A C
Participant 3 B C B A A
Participant 4 C C D D B
Key: A C D B B
OUTPUT : Scores :
Participant 1 = 3
Participant 2 = 1
Participant 3 = 1
Participant 4 = 3
Highest score:
Participant 1
Participant 4
Example 3
INPUT : N = 12
OUTPUT : INPUT SIZE OUT OF RANGE.

import java.io.*; class Quiz { char allans[][],correct[]; int result[],n; BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); public void takeAns() throws Exception { System.out.print("Enter number of participants : "); n = Integer.parseInt(br.readLine()); if(n < 4 || n > 10) { System.out.println("INPUT SIZE OUT OF RANGE"); return; } allans = new char[n][5]; // Array to hold answers of every participants correct = new char[5]; // Array to store answer key result = new int[n]; // Array to store score of individual participant System.out.print("\nSet the Answer Key : "); for(int i = 0; i<=4; i++) { br=new BufferedReader(new InputStreamReader(System.in)); System.out.print("\nAnswer of Quiz No "+ (i+1) + ": "); correct[i] = (char)br.read(); } System.out.println("\n Enter answer of each participant\n"); for(int i = 0; i<=n-1;i++) { System.out.print("Taking answers from participant no "+(i+1)); for(int j=0; j<=4; j++) { br =new BufferedReader(new InputStreamReader(System.in)); System.out.print("\nAnswer of Quiz No " + (j+1) + " : "); allans[i][j] = (char)br.read(); } } getMarks(); } private void getMarks() // Function to calculate score { for(int i = 0; i<=n-1;i++) { result[i] = 0; for(int j=0; j<=4; j++) { if(allans[i][j] == correct[j]) { result[i]=result[i]+1; } } } printResult(); } private void printResult() { int max = 0; System.out.println("\nSCORES : "); for(int i = 0; i<=n-1;i++) { System.out.println("\tParticipant No:"+(i+1)+" = "+result[i]); if(result[i] > max) { max = result[i]; // Storing the Highest Score } } System.out.println("\nHighest Score : "+max); System.out.println("\tHighest Scorers : "); for(int i = 0; i<=n-1;i++) { if(result[i] == max) { System.out.println("***Participant No "+(i+1)); } } } public static void main(String args[])throws Exception { Quiz ob = new Quiz(); ob.takeAns(); } }



  • Caesar Cipher is an encryption technique which is implemented as ROT13 (‘rotate by 13 places’). It is a simple letter substitution cipher that replaces a letter with the letter 13 places after it in the alphabets, with the other characters remaining unchanged.


Write a program to accept a plain text of length L, where L must be greater than 3 and less than 100.
Encrypt the text if valid as per the Caesar Cipher.
Test your program with the sample data and some random data:
Example 1
INPUT : Hello! How are you?
OUTPUT : The cipher text is:
Uryyb? Ubj ner lbh?
Example 2
INPUT : Encryption helps to secure data.
OUTPUT : The cipher text is:
Rapelcgvba urycf gb frpher qngn.
Example 3
INPUT : You
OUTPUT : INVALID LENGTH

import java.io.*; class Pat { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String s,str=""; int a; char ch; void takeString() throws Exception { System.out.print("\nEnter the sentence:"); s=br.readLine().trim(); if(s.length()<3 s.length="">100) { System.out.print("\nInvalid Length of String:"); return; } for(int i = 0; i<=s.length()-1;i++) { ch = s.charAt(i); if(Character.isLetter(ch)) { a = ch + 13; if((Character.toUpperCase(ch) > 90) ||(Character.toLowerCase(ch) > 122)) { a = a - 26; } ch = (char)a; } str = str + ch; } System.out.println("The cipher text is :"+str); } public static void main(String args[]) throws Exception { Pat ob = new Pat(); ob.takeString(); } }

Saturday, December 10, 2016

Twist Number Program using BlueJ



In this BlueJ program, the consecutive digits in a number will exchange their positions. If the number has odd number of digits then the number would remain the same

Example: Enter the Number: 123456
Original Sentence: 123456
Modified Sentence: 214365
(The above sentence has 06 Digits)


Enter the Number: 123
Original Sentence: 123
Modified Sentence: 213
(The above sentence has 03 Digits)


 import java.io.*;
class Twist
{
int n,n1;
int i,len;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
public void take() throws Exception
{
System.out.print("\nEnter the Number:");
n=Integer.parseInt(br.readLine());
}
int countDigits(int m)
{
 int c=0;
for(int i=m;i>=1;i=i/10)
c++;
return c;
}
public void show()
{
 System.out.println("Original Number:"+n);
 System.out.println("Modified Number:"+n1);
}
public void exchange()
{
 len=countDigits(n);
System.out.println("Length="+len);
if(len%2!=0)
 n1=n;
else
{
for(int i=n;i>=1;i=i/100)
 n1=n1*100+i%100;
n1=rev(n1);
}
}
private int rev(int x)
{
 int r=0;
for(int i=x;i>=1;i=i/10)
r=r*10+i%10;
return r;
}
 public static void main(String args[]) throws Exception
{
Twist ob=new Twist();
ob.take();
ob.exchange();
ob.show();
 }
}

Exchange of position between consecutive letters in a sentence



In this BlueJ program, the consecutive letters in a sentence will exchange their positions. If the sentence has odd number of characters then the last character will remain in it's positin

Example: Enter the Sentence: This is a test of twist
Original Sentence: This is a test of twist
Modified Sentence: hTsii  s aettso  fwtsit
(The above sentence has 23 characters)


Example: Enter the Sentence:Oh Mahua
Original Sentence: Oh Mahua
Modified Sentence: hOM haau
(The above sentence has 08 characters)




 import java.io.*;
class TwistWord
{
String s,s1="";
int i,len;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
public void take() throws Exception
{
System.out.print("\nEnter the Sentence:");
s=br.readLine();
}
public void show()
{
 System.out.println("Original Sentence:"+s);
 System.out.println("Modified Sentence:"+s1);
}
public void exchange()
{
 int flag=0;
len=s.length();
if(len%2!=0)
{
 len=len-1;
flag=1;
}

for(int i=0;i<=len-1;i=i+2)
{
 s1=s1+s.charAt(i+1)+s.charAt(i);
}
if(flag==1)
s1=s1+s.charAt(len);
}
 public static void main(String args[]) throws Exception
{
 TwistWord ob=new TwistWord();
ob.take();
ob.exchange();
ob.show();
 }
}

Sunday, November 20, 2016

BlueJ Program to check whether the values in a list are in order


In this program, user will enter number of values in an array and the program will check whether the values are in order
(ascending).

For example if the values in the array are 3 5 23 32 34 90, the the output will be " The values are in order." and if the numbers are 3 5 23 32 34 90 21, the output would be "The values are not in order.".


import java.io.*;

class Order
{
 BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int arr[];
int i;

Order()
{
 arr=new int[10];
}

public void takeValues() throws Exception
{
for(i=0;i<=9;i++)
{
System.out.print("\nEnter Value :");
arr[i]=Integer.parseInt(br.readLine());
}
}

public void show()
{
System.out.println("\nValues are :");
for(i=0;i<=9;i++)
{
System.out.print(" "+arr[i]);
}
}

boolean isOrder()
{
for(i=0;i<=8;i++)
{
 if(arr[i]>arr[i+1])
break;
}
if (i>8)
return true;
else
return false;
}

public static void main(String args[])throws Exception
{
 Order ob=new Order();
ob.takeValues();
ob.show();
if(ob.isOrder())
System.out.print("\nValues are in order.");
else
System.out.print("\nValues are not in order.");
}
}

CHECK HERE FOR PREVIOUS POSTS

Google+ Followers

Subscribe via email

Enter your email address:

Delivered by FeedBurner