0% found this document useful (0 votes)
7 views15 pages

Java Programming: Key Concepts Explained

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)
7 views15 pages

Java Programming: Key Concepts Explained

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

Question 1

import [Link].*;

public class keystroke

public static void main(String[] args)

Scanner sc=new Scanner([Link]);

[Link]("Enter word:");
String s=[Link]();

int ns=0;

for(int i=0;i<[Link]();i++)

char ch=[Link](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;

[Link]("Number of Strokes:"+ns);

}
Question 2
import [Link];

public class shift_mat

public static void main(String args[]) {

Scanner in = new Scanner([Link]);

[Link]("Enter no. of row: ");

int m = [Link]();

[Link]("Enter no. of col: ");

int n = [Link]();

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

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

[Link]("Enter numbers: ");

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

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

a[i][j]= [Link]();

[Link]("Original array: ");

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

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

[Link](a[i][j]+ " ");

}
[Link]();

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++;

[Link]("Shifted array: ");

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

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

[Link](b[i][j]+ " ");

[Link]();

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

[Link]("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;

[Link]("Highest element"+ max);

[Link]("row:"+ r);

[Link]("col:"+ c);

}
Question 3

import [Link];

public class anagram{

public static void main(String args[]) {

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

Scanner in = new Scanner([Link]);

[Link]("Enter 1st word: ");

String m = [Link]();

[Link]("Enter 2nd word: ");

String n = [Link]();

int l1=[Link]();

int l2=[Link]();

if(l1!=l2)
[Link](" Not Anagram ");

else {

char a[] = new char[l1];

char b[] = new char[l2];

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

a[i]= [Link](i);

b[i]= [Link](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([Link](s2))

[Link]("Anagram ");

else

[Link]("Not Anagram ");

}
Question 4

import [Link].*;

public class unique_digit

public static void main(String[] args)

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

Scanner sc=new Scanner([Link]);

[Link]("Enter starting range:");

int m=[Link]();

[Link]("Enter ending range:");

int n=[Link]();

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)

[Link](i);

fr=fr+1;

}
else

[Link]("Invalid");

[Link]("FREQUENCY OF UNIQUE-DIGIT INTEGERS IS:"+fr);

}
import [Link];

public class symmetric

public static void main(String args[]) {

Scanner in = new Scanner([Link]);

[Link]("Enter order of matrix: ");

int m = [Link]();

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

int f=1;

[Link]("Enter numbers: ");

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

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

a[i][j]= [Link]();

}
}

[Link]("Original array: ");

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

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

[Link](a[i][j]+ " ");

[Link]();

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)

[Link]("Symmetric ");

else

[Link]("Not Symmetric ");

}
}

Common questions

Powered by AI

The 'anagram' program uses a sorting-based algorithm to check if two words are anagrams. The critical steps involve comparing the lengths of the words, sorting their characters using a bubble sort, and then comparing the sorted forms of the words. If the sorted forms match, the words are anagrams; otherwise, they are not .

In the 'shift_mat' program, elements of the matrix are shifted downwards by copying elements from the first row to the last row of a new matrix 'b', and shifting all other rows up by one position. The maximum element is identified by iterating through the shifted matrix and comparing each element to track the highest value and its position .

The 'symmetric' program determines if a matrix is symmetric by checking if it is equal to its transpose. It iterates over the matrix and compares each element at position (i, j) with the element at (j, i). For the matrix to be symmetric, all these comparisons must hold true; otherwise, it is not symmetric .

The 'keystroke' program calculates the number of strokes needed by iterating through each character of the input word. It increases a counter based on predefined character groups: characters 'adgjmptwADGJMPTW' contribute 1 stroke each, 'behknquxBEHKNQUX' contribute 2 strokes, 'cfilorvyCFILORVY' contribute 3 strokes, and 'szSZ' contribute 4 strokes. The program sums these values to determine the total number of strokes needed .

The 'unique_digit' program identifies numbers with unique digits by iterating over each number in the given range. For each number, it counts the occurrence of each digit. If any digit appears more than once, the program marks the number as non-unique. It maintains a frequency count of numbers that have unique digits and displays the result .

You might also like