Practical Problems for Board Examinations
Problem
Input a paragraph containing ‘n’
number of sentences where (1 = < n < 4). The words are to be separated
with a single blank space and are in UPPERCASE. A sentence may be terminated
either with a full stop ‘.’ Or a question mark ‘?’ only. Any other character
may be ignored. Perform the following operations:
(i) Accept the number of sentences.
If the number of sentences exceeds the limit, an appropriate error message must
be displayed.
(ii) Find the number of words
in the whole paragraph
(iii) Display the words in ascending
order of their frequency. Words with same frequency may appear in any order.
Example 1
INPUT: Enter number of sentences.
1
Enter sentences.
TO BE OR NOT TO BE.
OUTPUT:
Total number of words: 6
WORD
FREQUENCY
OR
1
NOT
1
TO
2
BE
2
Example 2
INPUT: Enter number of sentences
3
Enter sentences.
THIS IS A STRING PROGRAM.IS THIS
EASY?YES,IT IS.
OUTPUT:
Total number of words: 11
WORD
FREQUENCY
A
1
STRING
1
PROGRAM
1
EASY
1
YES
1
IT
1
THIS
2
IS
3
Example 3
INPUT : Enter number of sentences
5
OUTPUT:
INVALID ENTRY
Solution
import java.io.*;
import java.util.*;
class SentencesOrder
{
String
s,str,sarr[],strarr[];
StringTokenizer st;
int
i,j,n,c,index=0,fre[],index1=0;
BufferedReader br=new
BufferedReader(new InputStreamReader(System.in));
public void take()
throws IOException
{
System.out.println(“Enter the Number of sentences:”);
n=Integer.parseInt(br.readLine());
if(n<
1 || n >4)
{
System.out.println(“Wrong Input…”);
return;
}
System.out.println(“Enter the Paragraph:”);
str=br.readLine();
st=new
StringTokenizer(str,”,.? “);
n=st.countTokens();
System.out.println(“Number of Words in the paragraph=”+n);
sarr=new
String[n];
strarr=new String[n];
fre=new
int[n];
while(st.hasMoreTokens())
{
sarr[index++]=st.nextToken();
}
for(i=0;i< index-1;i++)
{
for(j=i+1;j< index;j++)
{
if(sarr[i].compareTo(sarr[j]) > 0)
{
s=sarr[i];
sarr[i]=sarr[j];
sarr[j]=s;
}
}
}
c=1;
s=sarr[0];
for(i=1;i< index;i++)
{
if(!s.equals(sarr[i]))
{
strarr[index1]=s;
fre[index1++]=c;
c=1;
s=sarr[i];
}
else
c++;
}
strarr[index1]=s;
fre[index1++]=c;
for(i=0;i< index1-1;i++)
{
for(j=i+1;j< index1;j++)
{
if(fre[i] > fre[j])
{
n=fre[i];
fre[i]=fre[j];
fre[j]=n;
s= strarr[i];
strarr[i]=strarr[j];
strarr[j]=s;
}
}
}
System.out.println(“WORD FREQUENCY”);
for(i=0;i< index1;i++)
System.out.println(strarr[i]+” ”+fre[i]);
}
}
Problem
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:
Display the input matrix
Find the maximum and minimum value
in the matrix and display them along with their position.
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:
8 7 9 3
-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
3 3 4 5
6 7 8 9
Solution
import java.io.*;
class Matrixmult
{
BufferedReader
br=new BufferedReader(new InputStreamReader(System.in));
int arr[][];
int
r,c,max,min,maxi,maxj,mini,minj,i,j,m,n;
public void
take()throws Exception
{
boolean bool=true;
while(bool)
{
System.out.println("\nEnter the number of rows:");
r=Integer.parseInt(br.readLine());
System.out.println("\nEnter the number of columns:");
c=Integer.parseInt(br.readLine());
if(r < 2 || c < 2 || r > 20 || c > 20)
bool=true;
else
bool=false;
}
arr=new
int[r][c];
for(i=0;i <
r;i++)
{
for(j=0;j < c;j++)
{
System.out.println("\nEnter Value:");
arr[i][j]=Integer.parseInt(br.readLine());
}
}
max=arr[0][0];
min=arr[0][0];
maxi=0;
mini=0;
maxj=0;
minj=0;
for(i=0;i < r;i++)
{
for(j=0;j< c;j++)
{
if(arr[i][j]> max)
{
max=arr[i][j];
maxi=i;
maxj=j;
}
else if(arr[i][j]< min)
{
mini=i;
minj=j;
min=arr[i][j];
}
}
}
System.out.println("\nOriginal Array\n");
for(i=0;i< r;i++)
{
for(j=0;j< c;j++)
{
System.out.print(arr[i][j]+" ");
}
System.out.println();
}
System.out.println("\nMaximum Value="+max);
System.out.println("\nRow="+maxi);
System.out.println("\nColumn="+maxj);
System.out.println("\nMinimum Value="+min);
System.out.println("\nRow="+mini);
System.out.println("\nColumn="+minj);
for(m=0;m< r;m++)
{
for(n=0;n< c;n++)
{
for(i=0;i< r;i++)
{
for(j=0;j< c;j++)
{
if(arr[m][n]< arr[i][j])
{
min=arr[m][n];
arr[m][n]=arr[i][j];
arr[i][j]=min;
}
}
}
}
}
System.out.println("\nSorted Array\n");
for(i=0;i< r;i++)
{
for(j=0;j< c;j++)
{
System.out.print(arr[i][j]+" ");
}
System.out.println();
}
}
public
static void main(String args[]) throws Exception
{
Matrixmult ob=new Matrixmult();
ob.take();
}
}
Free Web Counter
15 comments:
https://bayanlarsitesi.com/
Tokat
Kastamonu
Tekirdağ
Gümüşhane
78E
sakarya
yalova
elazığ
van
kilis
8BUZ
van
düzce
mardin
elazığ
sakarya
SZHRN
görüntülü.show
whatsapp ücretli show
HXCG3
F3D44
Zonguldak Parça Eşya Taşıma
Erzincan Evden Eve Nakliyat
Isparta Parça Eşya Taşıma
Batman Lojistik
Mersin Parça Eşya Taşıma
70200
Ünye Yol Yardım
Amasya Evden Eve Nakliyat
Muğla Şehir İçi Nakliyat
Yalova Parça Eşya Taşıma
Erzurum Evden Eve Nakliyat
Tekirdağ Şehirler Arası Nakliyat
Sincan Boya Ustası
Bayburt Evden Eve Nakliyat
Çanakkale Parça Eşya Taşıma
B3A22
Ankara Parça Eşya Taşıma
Referans Kimliği Nedir
Amasya Şehir İçi Nakliyat
Ardahan Şehir İçi Nakliyat
Çanakkale Evden Eve Nakliyat
Mamak Boya Ustası
Diyarbakır Şehirler Arası Nakliyat
Adıyaman Şehirler Arası Nakliyat
Afyon Parça Eşya Taşıma
67C63
steroid cycles
primobolan
buy anapolon oxymetholone
boldenone for sale
testosterone propionat for sale
deca durabolin
buy fat burner
primobolan for sale
buy testosterone enanthate
7F4BC
buy boldenone
Kripto Para Borsaları
sarms
sustanon for sale
Ankara Asansör Tamiri
Kastamonu Evden Eve Nakliyat
Tokat Evden Eve Nakliyat
buy turinabol
primobolan for sale
شركة تسليك مجاري بالهفوف 22ZsSw9fh0
شركة تنظيف خزانات zx5MRdnjFL
شركة تسليك مجاري بالاحساء JYnT6VH0W9
شركة رش حشرات بالاحساء sZZ5fbL3ku
شركة مكافحة النمل الابيض بالدمام OrttNE5PK2
04ED317069
instagram takipçi satın al
Post a Comment