This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
ConTable.java | |
* | |
* Copyright 2013 @ Sonu | |
* | |
*/ | |
/* package whatever; // don't place package name! */ | |
import java.util.*; | |
import java.lang.*; | |
import java.io.*; | |
/* Name of the class has to be "Main" only if the class is public. */ | |
class ConTable | |
{ | |
public static void main (String[] args) throws java.lang.Exception | |
{ | |
int rows,cols; | |
Scanner in = new Scanner(System.in); | |
System.out.println("Enter an number of rows"); | |
rows = in.nextInt(); | |
System.out.println("Enter number of columns"); | |
cols = in.nextInt(); | |
int [][] conTable = new int[rows+1][cols+1]; | |
/*Take the input*/ | |
for(int i=0;i<rows;i++) | |
{ | |
System.out.println("Enter"+(i+1)+" row data elements"); | |
for(int j=0;j<cols;j++) | |
{ | |
conTable[i][j]=in.nextInt(); | |
} | |
} | |
/*Preparing Contingency Table*/ | |
int gTotal=0; | |
for(int i=0;i<rows;i++) | |
{ | |
int rTemp=0,j=0,cTemp =0; | |
for(j=0;j<cols;j++) | |
{ | |
rTemp = rTemp + conTable[i][j]; | |
cTemp = cTemp + conTable[j][i]; | |
} | |
conTable[i][j] = rTemp; | |
conTable[j][i] = cTemp; | |
gTotal = gTotal + rTemp; | |
} | |
conTable[rows][cols] = gTotal; | |
System.out.println("**** Contingency Table ****"); | |
/*printing Contingency Table*/ | |
for(int i=0;i<=rows;i++) | |
{ | |
for(int j=0;j<=cols;j++) | |
{ | |
System.out.print(conTable[i][j]+"\t"); | |
} | |
System.out.println(); | |
} | |
System.out.println("==========X============ "); | |
} | |
} |
0 Comments