0% found this document useful (0 votes)
6 views6 pages

Java Statistics Calculator Program

The documents demonstrate how to calculate statistics like mean, median, mode and standard deviation from input data in Java. They also show how to calculate the transpose and multiplication of matrices, as well as factorial of a number.

Uploaded by

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

Java Statistics Calculator Program

The documents demonstrate how to calculate statistics like mean, median, mode and standard deviation from input data in Java. They also show how to calculate the transpose and multiplication of matrices, as well as factorial of a number.

Uploaded by

Kazahana Ryuzen
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

package firsttime;

import [Link];

public class rata2maxminstandardeviasi {


public static void main(String[] args){

[Link]("Jumlah bilangan = ");


double[] arraybilangan;
try (Scanner input = new Scanner([Link])) {
int bykdata = [Link]();
[Link]("\n");
arraybilangan = new double[bykdata];
for(int i = 0;i<bykdata;i++){

[Link]("Masukkan Data Ke- " + (i+1)+"\t : ");


arraybilangan[i] = [Link]();

} }
rata2maxminstandardeviasi sd = new rata2maxminstandardeviasi();

[Link]();
[Link]("Jumlah total bilangan = " +
[Link](arraybilangan));
double nilairatarata = [Link](arraybilangan);
[Link]("Rata-rata = " + nilairatarata);
[Link]("Maksimum = " + [Link](arraybilangan));
[Link]("Minimum = " + [Link](arraybilangan));
[Link]("Standart Deviasi = " + [Link](arraybilangan));

public int TotalJumlah(double [] data){


int result = 0;
for (int i = 0 ; i < [Link] ; i++){
result += data[i];
}
return result;
}
public double ratarata(double [] data){
return
TotalJumlah(data)/[Link];
}
public double Maximum(double [] data){
double Max = 0;
for (int i = 0 ; i < [Link] ; i++){
if (Max < data[i]){
Max = data[i];
}
}
return Max;
}

public double Minimum(double [] data){


double Min = 10000000;
for (int i = 0 ; i < [Link] ; i++){
if (Min > data[i]){
Min = data[i];
}
}
return Min;
}

public double hasil (double [] data){


double ratarata = ratarata(data);
double akarjum = 0;
for (int i=0;i<[Link];i++){
akarjum += [Link](data[i] - ratarata,2);
}
return
[Link](akarjum)/([Link]);
}}

///////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////

import [Link];
import [Link];
import [Link];
class Stat {
public static void main(String args[]) {
BufferedReader B=new BufferedReader (new InputStreamReader([Link]));
int arrInput []; arrInput = new int[100];
int arrUrut []; arrUrut = new int[100];
int arrModus [][]; arrModus = new int[100][3];
int inputCount=0;
int N;
int i, a, b, c, d, j, temp;

float jumlah;
float mean=0;
try {
[Link]("Masukkan banyaknya data : ");
N=[Link] ([Link]());
[Link]();
jumlah = 0;
try {
for (i=1; i<=N; i++) {
[Link]("Masukkan data ke " + i + " : ");
arrInput[i]=[Link] ([Link]());
jumlah = jumlah + arrInput[i];
arrUrut[i] = arrInput[i];
}
mean = jumlah/N;

for (a=1; a<=N; a++){


b=a;
while ((b>0 ) && (arrUrut[b]<arrUrut[b-1] )) {
temp = arrUrut[b];
arrUrut[b] = arrUrut[b-1];
arrUrut[b-1] = temp;
b--;
}
}
int Nm = N/2;
int median = arrUrut[(N+1)/2];
int lastEmpty = 1;
int posx;
for (i=1; i<=N; i++) {
posx = 0;
for (j=1; j<=N; j++) {
if (arrInput[i]==arrModus[j][1]) posx = j;
}
if (posx!=0) {
arrModus[posx][2]++;
} else {
arrModus[lastEmpty][1] = arrInput[i];
arrModus[lastEmpty][2] = 1;
lastEmpty++;
}
}
int modus = 0;
int banyak = 0;
for (i=1; i<=N; i++) {
if (arrModus[i][2]>banyak) {
modus = arrModus[i][1];
banyak = arrModus[i][2];
}
}
[Link]("\nData terurut::");
for (i=1; i<=N; i++) {
[Link](" "+ arrUrut[i]);
}
[Link]("\n");
[Link]("Mean = " + mean);
[Link]("Median = " + median);
[Link]("Modus = " + modus);
} catch (IOException e) {
[Link] ("Error!" +e);
}
} catch (IOException e) {
[Link] ("Error!" +e);
}
[Link](0);
}
}

///////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////

package firsttime;
import [Link].*;
public class transposeperkalian{
static int [][] hasilkali = new int [10][10];
public static void main (String[]args) throws Exception {
BufferedReader input = new BufferedReader (new InputStreamReader ([Link]));
[Link]("masukkan jumlah baris = ");
int baris = [Link]([Link]());
[Link]("masukkan jumlah kolom = ");
int kolom = [Link]([Link]());

int A [][] = new int [baris] [kolom];


for (int i=0;i<baris;i++)
{
for (int j=0;j<kolom;j++)
{
[Link]("masukkan A pada baris ke-"+(i+1)+" dan kolom ke-"+(j+1)+" = ");
A [i][j] = [Link]([Link]());
}
}
[Link]();

int B [][] = new int [baris] [kolom];


for (int i=0;i<baris;i++)
{
for (int j=0;j<kolom;j++)
{
[Link]("masukkan B pada baris ke-"+(i+1)+" dan kolom ke-"+(j+1)+" = ");
B [i][j] = [Link]([Link]());
}
}
[Link]();

[Link]("Matriks A");
for (int i=0;i<baris;i++)
{
[Link]("|");
for (int j=0;j<kolom;j++)
{
[Link](A[i][j]+" ");
}
[Link]("|");
}

[Link]("Matriks B");
for (int i=0;i<baris;i++)
{
[Link]("|");
for (int j=0;j<kolom;j++)
{
[Link](B[i][j]+" ");
}
[Link]("|");
}
[Link]();
[Link]("Matriks A Transpose");
for (int j=0;j<kolom;j++)
{
[Link]("|");
for (int i=0;i<baris;i++)
{
[Link](A[i][j]+" ");
}
[Link]("|");
}

[Link]("Matriks B Transpose");
for (int j=0;j<kolom;j++)
{
[Link]("|");
for (int i=0;i<baris;i++)
{
[Link](B[i][j]+" ");
}
[Link]("|");
}

[Link]("Perkalian Matriks Transpose");


for (int j=0;j<kolom;j++)
{
[Link]("|");
for (int i=0;i<baris;i++)
{
int hasilakhir = 0;
for (int k=0;k<kolom;k++)
{
hasilakhir += ((A[k][j]*B[i][k]));
}
hasilkali[i][j] = hasilakhir;
[Link](hasilkali[i][j]+" ");
}
[Link]("|");
}
}
}

///////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////

import [Link];
public class Faktorial {
public static void main(String[] args) {

long fak = 1;
int angka = 0;
[Link]("Masukkan angka : ");
Scanner in = new Scanner([Link]);
angka = [Link]();

for(int i=1; i<=angka; i++){


fak = i * fak;
}
[Link]("Faktorial dari "+angka+" adalah "+fak);
}
}

Common questions

Powered by AI

The programs use try-catch blocks to handle exceptions, specifically capturing IOExceptions when reading input. This prevents the programs from crashing due to input errors and instead prints the exception message, allowing for graceful handling of errors .

The program sorts the dataset using insertion sort and identifies the median as the middle element when the number of elements is odd, or the average of the two middle elements when even. Sorting ensures accurate determination of the central tendency, crucial for accurately describing dataset distributions .

The program uses insertion sort for arranging the dataset by iterating through the array, starting from the second element. For each element, it compares it backward through the sorted portion and inserts it at the correct position. This process ensures that, after each iteration, the array partition to the left is sorted .

The program determines the mode by iterating through the dataset and maintaining a frequency count for each unique number using a two-dimensional array 'arrModus'. Each entry stores a number and its count. The mode is identified as the number with the highest count .

The program employs an insertion sort algorithm on the input array before computing statistical values like mean, median, and mode. This sorted dataset is essential for calculating the median, which relies on ordered data .

The program calculates the total sum by iterating over the dataset, accumulating each entry. The average is then derived by dividing the sum by the dataset's length. A potential flaw is using an int for the sum, which may lead to integer overflow with large datasets .

The program first reads two matrices A and B from the user. It transposes matrix A by swapping rows with columns. It does the same for matrix B. To multiply the transposed matrices, it iteratively calculates the dot product of corresponding row and column vectors and saves the results into a result matrix .

BufferedReader is used for its efficiency in reading large data since it reads a character stream as opposed to Scanner, which parses primitive types and strings using regular expressions, making it slower with heavier I/O operations .

The factorial computation is done using a loop that multiplies a variable 'fak', initialized to 1, by each positive integer up to the input number 'angka'. The factorial is then displayed to the user .

The program calculates the standard deviation by first determining the average (mean) of the data set using the method 'ratarata'. It then calculates the sum of the squared differences between each data point and the mean ('akarjum'). Finally, it returns the square root of this sum divided by the number of data points .

You might also like