Sunteți pe pagina 1din 3

import java.io.

*;
public class bufferedreader
{
public static void main(String args[])throws IOException //main class
{
BufferedReader watta = new BufferedReader(new InputStreamReader(System.in));
int indexNum[][] = new int[4][3];
//int arraySize=0;
System.out.print("Enter 12 integers: ");
for(int a=0;a<indexNum.length;a++)
{
for(int b=0; b<indexNum[a].length; b++)
{
indexNum[a][b]=Integer.parseInt(watta.readLine());
}
}
System.out.println("----------------------------------------------------");
System.out.println("Matrix:");
for(int a=0;a<indexNum.length;a++)
{
for(int b=0; b<indexNum[a].length; b++)
{
System.out.print(indexNum[a][b] + "\t");
}
System.out.println();
}
System.out.println("----------------------------------------------------");
System.out.println("Copying the elements to another Index:");
for(int a = 0; a < indexNum.length; a++)
{
for(int b = 0; b < indexNum[a].length; b++)
{
int indexNum2[][] = new int[4][3];
indexNum2[a][b] = indexNum[a][b];
System.out.print(indexNum2[a][b] + "\t");
}
System.out.println();
}
System.out.println("----------------------------------------------------");
sumrows(indexNum);
System.out.println("----------------------------------------------------");
sumcolumns(indexNum);
System.out.println("----------------------------------------------------");
largestrows(indexNum);
System.out.println("----------------------------------------------------");
largestcolumns(indexNum);
System.out.println("----------------------------------------------------");
maxV(indexNum);
System.out.println("----------------------------------------------------");
minV(indexNum);
System.out.println("----------------------------------------------------");
evenodd(indexNum);
System.out.println("----------------------------------------------------");
}
public static void sumrows(int indexNum[][]){
int sum1;
for(int a = 0; a < indexNum.length; a++){
sum1 = 0;
for(int b = 0; b < indexNum[a].length; b++)

sum1 = sum1 + indexNum[a][b];


System.out.println("sum of element of row" + (a+1) + " is " + sum1);
}
}
public static void sumcolumns(int indexNum[][]){
int sum;
for(int b = 0; b < indexNum[0].length; b++){
sum = 0;
for(int a = 0; a < indexNum.length; a++)
sum = sum + indexNum[a][b];
System.out.println("sum of element of column" + (b+1) + " is " + sum);
}
}
public static void largestrows(int indexNum[][]){
int largest;
for(int a = 0; a < indexNum.length; a++){
largest = indexNum[a][0];
for(int b = 0; b < indexNum[a].length; b++)
if(largest < indexNum[a][b])
largest = indexNum[a][b];
System.out.println("largest of element of row" + (a+1) + " is " + largest);
}
}
public static void largestcolumns(int indexNum[][]){
int largest;
for(int b = 0; b < indexNum[0].length; b++){
largest = indexNum[0][b];
for(int a = 0; a < indexNum.length; a++)
if(largest < indexNum[a][b])
largest = indexNum[a][b];
System.out.println("largest of element of columns" + (b+1) + " is " + largest);
}
}
public static void maxV(int indexNum[][]) {
int maxValue = indexNum[0][0];
for (int a = 1; a < indexNum.length; a++) {
for (int b = 0; b < indexNum[a].length; b++) {
if (indexNum[a][b] > maxValue) {
maxValue = indexNum[a][b];
}
}
}
System.out.println("largest of element of array: " + maxValue);
}
public static void minV(int indexNum[][]) {
int minValue = indexNum[0][0];
for (int a = 1; a < indexNum.length; a++) {
for (int b = 0; b < indexNum[a].length; b++) {
if (indexNum[a][b] < minValue) {
minValue = indexNum[a][b];
}
}
}
System.out.println("smallest of element of array: " + minValue);
}
public static void evenodd(int indexNum[][]){
for(int a=0; a<indexNum.length;a++){
for(int b=0; b<indexNum[a].length;b++){
if(indexNum[a][b]%2 == 0)

System.out.println(indexNum[a][b] + " is even number.");


else
System.out.println(indexNum[a][b] + " is odd number.");
}
}
}
}

S-ar putea să vă placă și