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

Index

Si no topic Page no Teacher signature

1) 1) /**WAP to accept a single


dimensional array and
2)
elements from user..
2)//WAP in java to sort a given
array using bubble sort..

3) The class SaddlePoint


3)
inputs a matrix of n*n size and
finds its
* saddle point if any

WAP to accept an array of n


4)
numbers and accept another
number. Find and count the
CONTINUOUS SUBARRAYS

If in a nxn matrix the four


5) corners are Prime its a
Symmetric matrix else not
Symmetric matrixa

Searching a particular city


from a list using binary search
6)
method

To display Pascal Triangle


7)

8)
Consequtive characters
9)
encode of string
10)
Bubble sort
Java
With
blue-j
environment
1) /**WAP to accept a single dimensional

array and elements from user..


*checking whether the sum of array elements is palindrome or not.
*/
import java.util.*;
public class arraysumpalin
{
public static void main()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the no. of elements of array");
int n=sc.nextInt();int ar[]=new int[n];//creating array..
System.out.println("Enter the elements of array");
for(int i=0;i<n;i++)//loop to accept array elements
ar[i]=sc.nextInt();
int sm=0;
for(int i=0;i<n;i++)
sm=sm+ar[i];
int v=0,d;
int m=sm;
while(m>0)
{
d=m%10;
v=(v*10)+d;
m=m/10;
}
if(v==sm)
System.out.println("Array sum is Palindrome");
else
System.out.println("Array sum is not palindrome");
}
}

2)//WAP in java to sort a given array using


bubble sort..
import java.util.*;
public class BUBBLE
{
public static void main()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the no. of elements of array");
int n=sc.nextInt();int ar[]=new int[n];
System.out.println("Enter elements of array");
for(int i=0;i<n;i++)
ar[i]=sc.nextInt();
int t=0;
for(int i=0;i<n-1;i++)
{
for(int j=0;j<n-i-1;j++)
{
if(ar[j]>ar[j+1])
{
t=ar[j];ar[j]=ar[j+1];ar[j+1]=t;
}
}
}
System.out.println("Sorted array");
for(int i=0;i<n;i++)
System.out.print(ar[i]+" ");
}
}
3)
/**
* The class SaddlePoint inputs a matrix of n*n size and finds its
* saddle point if any
*/

import java.io.*;
class SaddlePoint
{
public static void main(String args[])throws IOException
{
BufferedReader br=new BufferedReader(new
InputStreamReader(System.in));
System.out.print("Enter the order of the matrix : ");
int n=Integer.parseInt(br.readLine());
int

/* Printing the Original Matrix */


System.out.println("The Original Matrix is");
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
System.out.print(A[i][j]+"\t");
}
System.out.println();
}

int max, min, x, f=0;


for(int i=0;i<n;i++)
{
/* Finding the minimum element of a row */
min = A[i][0]; // Initializing min with first element of
every row
x = 0;
for(int j=0;j<n;j++)
{
if(A[i][j]<min)
{
min = A[i][j];
x = j; // Saving the column position of the
minimum element of the row
}
}
/* Finding the maximum element in the column
* corresponding to the minimum element of row */
max = A[0][x]; // Initializing max with first element of
that column
for(int k=0;k<n;k++)
{
if(A[k][x]>max)
{
max = A[k][x];
}
}

/* If the minimum of a row is same as maximum of the


corresponding column,
then, we have that element as the Saddle point */
if(max==min)
{
System.out.println("Saddle point = "+max);
f=1;
}
}

if(f==0)
{
System.out.println("No saddle point");
}
}
}

4) //Q: WAP to accept an array of n numbers and accept another


number. Find and count the CONTINUOUS SUBARRAYS whose sum
of
// elements is equal to the number (the array can have duplicate
elements).
//e.g. : {1,2,3,2,1} and 6
//The subarrays are {1,2,3} and {3,2,1}
//No. of subarrays: 2
//e.g. {3,5,7,9,11,13,12,8} and 20
//The subarrays are {9,11} and {12,8} No. of subsarrays: 2

import java.util.*;
public class subarray
{
public static void main (String args[])
{
Scanner sc= new Scanner (System.in);
int n, i, j, sm, k, s=0, num;
System.out.println ("Enter size of array:");
n=sc.nextInt ();
int a[]= new int [n];
System.out.println ("Enter "+n+" numbers in array:");
for (i=0; i<n; i++)
a[i]= sc.nextInt ();
System.out.println ("Enter the number for subarrays:");
num=sc.nextInt ();
for (i=0; i<n-1; i++)
{
sm= a[i];
for (j=i+1; j<n; j++)
{
sm+=a[j];
if (sm==num)
{
s++;
System.out.print ("{");
for (k=i; k<=j; k++)
System.out.print (a[k]+" ");
System.out.print ("}");
}//if
} //for loop (inner)
}//for loop (outer)
if (s>0)
{
System.out.println (" are the subarrays");
System.out.println ("No. of subarrays: "+s);
}//if
else
System.out.println ("No subarrays");
}//main
}//class

5)//If in a nxn matrix the four corners are Prime its a Symmetric
matrix else not Symmetric matrixa
import java.util.*;
class corners
{
int prime(int x)
{
int f=0;
for(int i=1;i<=x;i++)
{
if(x%i==0)
f++;
}
return f;
}
public static void main()
{
Scanner sc=new Scanner(System.in);
corners ob=new corners();
System.out.println("Enter size of array");
int n=sc.nextInt();
int ar[][]=new int[n][n];
int i,j;
System.out.println("Enter array values");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
ar[i][j]=sc.nextInt();
}
}
System.out.println("The original array");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
System.out.print(ar[i][j]+"\t");
}
System.out.println();
}
int a=ob.prime(ar[0][0]);
int b=ob.prime(ar[0][n-1]);
int c=ob.prime(ar[n-1][0]);
int d=ob.prime(ar[n-1][n-1]);
if(a==2&&b==2&&c==2&&d==2)
System.out.println("Symmetric matrix");
else
System.out.println("Not a symmetric matrix");
}
}

6)// Searching a particular city from a list using binary search method

import java.util.*;
public class binarystring
{
public static void main(String []args)
{
Scanner sc=new Scanner (System.in);
String
c[]={"AGRA","BHOPAL","DELHI","GANGTOK","JAMMU","KOLKATA","
MYSORE","PATNA","SHIMLA","UDAIPUR"};
int flg=0,fst=0,lst=9,md=0;
System.out.println("The cities from the array are :");
for(int i=0;i<10;i++)
{
System.out.print(c[i]+" ");
}
System.out.println();
System.out.println("Enter city name to Search:");
String str=sc.nextLine().toUpperCase();
while(fst<=lst)
{
md=(fst+lst)/2;
if(c[md].compareTo(str)<0)
fst=md+1;
if(c[md].compareTo(str)> 0)
lst=md-1;
if(c[md].compareTo(str)==0)
{
flg=1;
break;
}//if
}//while
if(flg==1)
System.out.println("City name Present in the Array at position
"+(md+1));
else
System.out.println("City name not Present in the Array ");
}}
7 )To display Pascal Triangle
import java.util.*;
public class Pascal_Triangle
{
public static void main(String args[])
{
Scanner in=new Scanner(System.in);
int i,j,n,k,p=5;
int m[]=new int[20];
System.out.println("Enter number of rows of the pascal
Triangle");
n=in.nextInt();
m[0]=1;
for(i=0;i<n;i++)
{
for(k=p;k>=1;k--)
System.out.print("");
for(j=0;j<=i;j++)
System.out.print(m[j]+"");
System.out.println();
p--;
for(j=i+1;j>0;j--)
m[j]=m[j]+m[j-1];
}
}
}
8//Consequtive characters

import java.util.*;
public class conscecutivestar
{
static void main()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter a word ");
String s=sc.next();
s=s+" ";s=s.toUpperCase();
for(int i=0;i<s.length()-1;i++)
{
int c=(int)s.charAt(i);
int c1=(int)s.charAt(i+1);
if(c1==(c+1))
System.out.print("*");
else
System.out.print(s.charAt(i));
}
}
}
9)//encode of string
public class encode
{
public static void main(String str)
{
str=str.toUpperCase();
String s="";
for(int i=0;i<str.length();i++)
{
char ch=str.charAt(i);
if(ch=='A'||ch=='E'||ch=='I'||ch=='O'||ch=='U')
s=s+ch;
else
{
if (ch=='Y')
ch='A';
else
if(ch=='Z')
ch='B';
else
ch+=2;
s=s+ch;
}
}
System.out.println("The new String :"+s);}}
10//Bubble sort
import java.io.*;
public class sort
{
public static void main (String args[]) throws IOException
{
InputStreamReader read=new InputStreamReader(System.in);
BufferedReader in=new BufferedReader(read);
int i,t,k;
int ar[]=new int[5];
System.out.println("Enter 5 no. in the array one by one ");
for(i=0;i<5;i++)
ar[i]=Integer.parseInt(in.readLine());
for(i=0;i<5-1;i++)
{
for(k=0;k<5-i-1;k++)
{
if(ar[k]< ar[k+1])
{
t=ar[k];ar[k]=ar[k+1];ar[k+1]=t; }// if
}//k
}//i
System.out.println(" Array in descending order ");
for(i=0;i<5;i++)
System.out.print(ar[i]+" ");
}
}
ACKNOWLEDGEMENT

I would like to express my special thanks of


gratitude to my teacher (ANURADHA MISS)
as well as our principal (-----------------
)who gave me the golden opportunity to do
this wonderful project on the topic (--------
----------------------), which also helped
me in doing a lot of Research and i came to
know about so many new things I am
really thankful to them.
Secondly i would also like to thank my
parents and friends who helped me a lot in
finalizing this project within the limited
time frame.
 BIBLIOGRAPHY
I HAVE TAKEN HELP OF THE FOLLOWING
WEBSIDE
1

Free Java Projects - javatpoint


https://www.javatpoint.com/free-java-projects

https://www.GOOGLE.com

https://YAHOO.com/free-java-projects
BOSE NAGAR
MADHYAMGRAM

NAME = Shushanto debnath


CLASS = XI
SUBJECT = COMPUTER SCIENCE
ROLL NO. = 24
SEC. = SCIENCE
Question:1 (ISE 2017)

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
{
public static void main(String args[])throws IOException
{
InputStreamReader in = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(in);
System.out.print("Number of participants: ");
int n = Integer.parseInt(br.readLine());
int highest = 0;
if(n < 4 || n > 10){
System.out.println("INPUT SIZE OUT OF RANGE.");
return;
}
char q[][] = new char[n][5];
char a[] = new char[5];
int score[] = new int[n];
System.out.println("Key to the questions:");
for(int i = 0; i < a.length; i++)
a[i] = br.readLine().charAt(0);
System.out.println("Answers by participants:");
for(int i = 0; i < n; i++){
System.out.println("Participant " + (i + 1));
for(int j = 0; j < 5; j++){
q[i][j] = br.readLine().charAt(0);
if(q[i][j] == a[j])
score[i]++;
}
if(highest < score[i])
highest = score[i];
}
for(int i = 0; i < n; i++)
System.out.println("Participant " + (i + 1) + " = " + score[i]);
System.out.println("Highest score(s):");
for(int i = 0; i < n; i++)
if(score[i] == highest)
System.out.println("Participant " + (i + 1));
}
}

Question:2 (ISE 2017)


A company manufactures packing cartons in four
sizes, i.e. cartons 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 up to 1000 boxes) and display the break-
up of the cartons used in descending order of capacity
(i.e. preference should be given to the highest capacity
available, and if boxes left are less than 6, an extra
carton of capacity 6 should be used.)

Test your program with the sample 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 cartons = 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 cartons = 6

Example 3

INPUT : N = 4296

OUTPUT : INVALID LENGTH

import java.util.*;
class BoxPacking_ISC2017
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);

System.out.print("Enter number of boxes to be packed : ");


int N = sc.nextInt();
if(N<1 || N > 1000)
{
System.out.println("INVALID INPUT");
}
else
{
int cart[] = {48, 24, 12, 6};
int copy = N;
int totalCart = 0,count = 0;
System.out.println("OUTPUT :");
for(int i=0; i<4; i++)
{
count = N / cart[i];
if(count!=0)
{
System.out.println("\t"+cart[i]+"\tx\t"+count+"\t=
"+cart[i]*count);
}
totalCart = totalCart + count;
N = N % cart[i];
}
if(N>0)
{
System.out.println("\tRemaining Boxes "+N+" x 1 = "+N);
totalCart = totalCart + 1;
}
else
{
System.out.println("\tRemaining Boxes\t\t= 0");
}
System.out.println("\tTotal number of boxes = "+copy);
System.out.println("\tTotal number of cartons = "+totalCart);
}
}
}

Output:
Enter number of boxes to be packed : 815

OUTPUT :

48 x 16 = 768
24 x 1 = 24

12 x 1 = 12

6 x 1 = 6

Remaining Boxes 5 x 1 = 5

Total number of boxes = 815

Total number of cartons = 20

Question:3(ISE 2015)
Write a program to accept a sentence which may be terminated by
either ‘.’ or ‘?’ only. The words are to be separated by a single blank
space. Print an error message if the input does not terminate with ‘.’
or ‘?’. You can assume that no word in the sentence exceeds 15
characters, so that you get a proper formatted output.

Perform the following tasks:


(i) Convert the first letter of each word to uppercase.
(ii) Find the number of vowels and consonants in each word and
display them with proper headings along with the words.

Test your program with the following inputs.


Example 1

INPUT: Intelligence plus character is education.

OUTPUT:
Intelligence Plus Character Is Education

Word Vowels Consonants

Intelligence 5 7

Plus 1 3
Character 3 6

Is 1 1

Education 5 4

Example 2

INPUT: God is great.

OUTPUT:
God is Great

Word Vowels Consonants

God 1 2

Is 1 1

Great 2 3

Example 3

INPUT: All the best!

OUTPUT:
Invalid Input.

Programming Code:
/**
* The class Q3_ISC2015 inputs a
sentence, converts the first letter of each
word to
* uppercase and find the number of vowels
and consonants
* @author : www.guideforschool.com
* @Program Type : BlueJ Program – Java
* @Question Year : ISC Practical 2015
Question 3
*/
import java.util.*;
class Q3{
public static boolean isVowel( char ch
){
String vowel="aeiouAEIOU";
return vowel.indexOf(ch)>=0;
}
public static boolean isConsonant(
char ch ){
return Character.isLetter(ch) &&
!isVowel(ch);
}
public static void main( String args[] ){
Scanner sc = new Scanner(
System.in );
System.out.print( "INPUT: ");
String input = sc.nextLine();
char ch=input.charAt(input.length()-
1);
if( ch!='.' && ch!='?'){
System.out.println("OUTPUT:Inva
lid Input");
}else{
input=input+" ";
String word="";
int vowels=0, consonants=0;
String
ans="",out=String.format("%-
16s\t%s\t%s\n","Word","Vowels","Conson
ants");
for( int i=0; i<input.length()-1;i++
){
ch=input.charAt(i);
if(ch==' ' || ch==',' || ch=='?' ||
ch=='.' || ch==';' ){
out+=String.format("%-
16s\t%2d\t%2d\n",word,vowels,consonan
ts);
ans=ans+word+ " ";
word="";
vowels=consonants=0;
}else{
if(isVowel(ch)) vowels++;
if(isConsonant(ch))
consonants++;
if(word.equals(""))
ch=Character.toUpperCase(ch);
word = word+ch;
}
}
ans=ans.trim();
System.out.println("OUTPUT:\n"+
ans+"\n"+out);
}
}
}

You might also like