
A union B, transpose of matric, denomination of a given number i need java programs for this category?

Hi Friend,
Transpose of matrix:
import java.util.*;
public class Transpose {
public static void main(String[] args) throws Exception {
int rows, cols;
int[][] matrix, tmatrix;
Scanner input = new Scanner(System.in);
System.out.print("Enter number of rows: ");
rows = input.nextInt();
System.out.print("Enter number of columns: ");
cols = input.nextInt();
matrix = new int[rows][cols];
tmatrix = new int[cols][rows];
System.out.println("Enter elements for Matrix");
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
matrix[i][j] = input.nextInt();
}
}
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
tmatrix[i][j] = matrix[j][i];
}
}
System.out.println("Matrix is:");
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
System.out.print(matrix[i][j] + " ");
}
System.out.println();
}
System.out.println("Its transpose is: ");
for (int i = 0; i < cols; i++) {
for (int j = 0; j < rows; j++) {
System.out.print(tmatrix[i][j] + " ");
}
System.out.println();
}
}
}
Thanks

Hi Friend,
Denominations of Number:
import java.util.*;
class FindDenomination{
public static void main(String arg[]) throws Exception {
Scanner input=new Scanner(System.in);
String get_value;
int five=0,ten=0,twenty=0,fifty=0,hundred=0, fivehundred=0,thousand=0;
System.out.print("Enter a number: ");
int number=input.nextInt();
thousand = number / 1000;
number = number % 1000;
fivehundred = number / 500;
number = number % 500;
hundred = number / 100;
number = number % 100;
fifty = number / 50;
number = number % 50;
twenty = number / 20;
number = number % 20;
ten = number / 10;
number = number % 10;
five = number / 5;
number = number % 5;
System.out.println(" Number of 1000 denomination = " + thousand);
System.out.println(" Number of 500 denomination = " + fivehundred);
System.out.println(" Number of 100 denomination = " + hundred);
System.out.println(" Number of 50 denomination = " + fifty);
System.out.println(" Number of 20 denomination = " + twenty);
System.out.println(" Number of 10 denomination = " + ten);
System.out.println(" Number of 5 denomination = " + five);
}
}
Thanks

Hi Friend,
A union B:
import java.util.*;
public class SetsUnion {
public static void main(String[] args) {
Set a = new HashSet();
a.add(1);
a.add(2);
a.add(3);
Set b = new HashSet();
b.add(2);
b.add(3);
b.add(4);
Set s=new HashSet(a);
s.addAll(b);
System.out.println("Set A: "+a);
System.out.println("Set B: "+b);
System.out.println();
System.out.println("A U B is: "+s);
}
}
Thanks

**Hi Friend, This is the Simple version of above Transpose program ( using single array variable )**
/* author Udhayakumar date 18-12-2010*/
import java.util.Scanner;
class Transpose {
public static void main(String []ar)
{
int rows,cols;
int[][] matrix;
Scanner input = new Scanner(System.in);
System.out.println("Enter the Number of Rows");
rows = input.nextInt();
System.out.println("Enter the Number of Columns");
cols = input.nextInt();
matrix = new int[rows][cols];
System.out.println("Enter the Input for matrix");
for(int i = 0;i<rows;i++)
for(int j=0;j<cols;j++)
matrix[i][j] = input.nextInt();
System.out.println("The matrix is : ");
for(int i = 0;i<rows;i++)
{
for(int j=0;j<cols;j++)
{
System.out.print(matrix[i][j]+" ");
}
System.out.println();
}
System.out.println("The Transpose matrix is : ");
for(int i = 0;i<rows;i++)
{
for(int j=0;j<cols;j++)
{
System.out.print(matrix[j][i]+" ");
}
System.out.println();
}
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.