0% found this document useful (0 votes)
10 views

Programs For Practice2

Computer class 12 program

Uploaded by

biswanathk1969
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Programs For Practice2

Computer class 12 program

Uploaded by

biswanathk1969
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

Question 1

import java.util.*;

public class keystroke

public static void main(String[] args)

Scanner sc=new Scanner(System.in);

System.out.println("Enter word:");
String s=sc.next();

int ns=0;

for(int i=0;i<s.length();i++)

char ch=s.charAt(i);

if("adgjmptwADGJMPTW".indexOf(ch)>=0)

ns=ns+1;

else if("behknquxBEHKNQUX".indexOf(ch)>=0)

ns=ns+2;

else if("cfilorvyCFILORVY".indexOf(ch)>=0)

ns=ns+3;

else if("szSZ".indexOf(ch)>=0)

ns=ns+4;

System.out.println("Number of Strokes:"+ns);

}
Question 2
import java.util.Scanner;

public class shift_mat

public static void main(String args[]) {

Scanner in = new Scanner(System.in);

System.out.print("Enter no. of row: ");

int m = in.nextInt();

System.out.print("Enter no. of col: ");

int n = in.nextInt();

int a[][] = new int[m][n];

int b[][] = new int[m][n];

System.out.println("Enter numbers: ");

for (int i = 0; i < m; i++) {

for (int j = 0; j <n; j++) {

a[i][j]= in.nextInt();

System.out.println("Original array: ");

for (int i = 0; i < m; i++) {

for (int j = 0; j <n; j++) {

System.out.print(a[i][j]+ " ");

}
System.out.println();

for (int i = 0; i <n; i++)

b[m-1][i]=a[0][i];

int x=1;

for (int i = 0; i < m-1; i++) {

for (int j = 0; j <n; j++) {

b[i][j]=a[x][j];

x++;

System.out.println("Shifted array: ");

for (int i = 0; i < m; i++) {

for (int j = 0; j <n; j++) {

System.out.print(b[i][j]+ " ");

System.out.println();

int max=b[0][0],r=0,c=0;;

System.out.println("Shifted array: ");

for (int i = 0; i < m; i++) {

for (int j = 0; j <n; j++) {


if(b[i][j]>max)

max=b[i][j];

r=i;

c=j;

System.out.println("Highest element"+ max);

System.out.println("row:"+ r);

System.out.println("col:"+ c);

}
Question 3

import java.util.Scanner;

public class anagram{

public static void main(String args[]) {

int i,j; String s1="",s2="";

Scanner in = new Scanner(System.in);

System.out.print("Enter 1st word: ");

String m = in.next();

System.out.print("Enter 2nd word: ");

String n = in.next();

int l1=m.length();

int l2=n.length();

if(l1!=l2)
System.out.print(" Not Anagram ");

else {

char a[] = new char[l1];

char b[] = new char[l2];

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

a[i]= m.charAt(i);

b[i]= n.charAt(i);

for (i = 0; i < l1-1; i++){

for(j=0;j<(l1-1)-i;j++){

if(a[j]>a[j+1]) {

char x=a[j];

a[j]=a[j+1];

a[j+1]=x;

for (i = 0; i < l1-1; i++) {

for(j=0;j<(l1-1)-i;j++) {

if(b[j]>b[j+1])

char y=b[j];

b[j]=b[j+1];

b[j+1]=y;

}
for (i = 0; i < l1; i++)

s1=s1+a[i];

s2=s2+b[i];

if(s1.equalsIgnoreCase(s2))

System.out.println("Anagram ");

else

System.out.println("Not Anagram ");

}
Question 4

import java.util.*;

public class unique_digit

public static void main(String[] args)

int i,j,k,c,f,fr=0;

Scanner sc=new Scanner(System.in);

System.out.println("Enter starting range:");

int m=sc.nextInt();

System.out.println("Enter ending range:");

int n=sc.nextInt();

if(m>0 && n>0)

{
for(i=m;i<=n;i++)

f=1;

int x=i;

for(j=0;j<=9;j++)

int p=x;

c=0;

while(p!=0)

int r=p%10;

if(r==j)

c++;

p=p/10;

if(c>1)

f=0;

break;

if (f==1)

System.out.println(i);

fr=fr+1;

}
else

System.out.println("Invalid");

System.out.println("FREQUENCY OF UNIQUE-DIGIT INTEGERS IS:"+fr);

}
import java.util.Scanner;

public class symmetric

public static void main(String args[]) {

Scanner in = new Scanner(System.in);

System.out.print("Enter order of matrix: ");

int m = in.nextInt();

int a[][] = new int[m][m];

int f=1;

System.out.println("Enter numbers: ");

for (int i = 0; i < m; i++) {

for (int j = 0; j <m; j++) {

a[i][j]= in.nextInt();

}
}

System.out.println("Original array: ");

for (int i = 0; i < m; i++) {

for (int j = 0; j <m; j++) {

System.out.print(a[i][j]+ " ");

System.out.println();

for (int i = 0; i < m; i++) {

for (int j = 0; j <m; j++) {

if(a[i][j]!=a[j][i])

f=0;

break;

if(f==1)

System.out.println("Symmetric ");

else

System.out.println("Not Symmetric ");

}
}

You might also like