Beruflich Dokumente
Kultur Dokumente
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
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;
t = i;
}
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:
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;
number of words
for(i=0;i< l;i++){
ch = str.charAt(i);
if(ch == ' ' || ch == '?' || ch == '.'
|| ch == '!')
now++;
}
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;
}
}
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;
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();
}
for(i=0;i< m;i++){
for(j=0;j< n;j++){
colS = j;
}
if(largest < a[i][j]){
largest = a[i][j];
rowL = i;
colL = j;
}
}
}
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