|
-
Feb 1st, 2006, 04:53 PM
#1
Thread Starter
Hyperactive Member
[RESOLVED] Ok I need help
Last edited by vonoventwin; Feb 2nd, 2006 at 05:45 PM.
-
Feb 1st, 2006, 07:25 PM
#2
Re: Ok I need help and I'm willing to pay $25 via Paypal
Keep your money...it was fun
Code:
import java.io.*;
public abstract class App {
public static void main(String[] args) {
int ar[] = new int[50];
ReadFile("C:\\Temp.txt", ar);
sort(ar);
System.out.println("Minimum= " + ar[0]);
System.out.println("Maximum=" + ar[ar.length - 1]);
System.out.println("Mean= " + mean(ar));
System.out.println("Mode= " + modal(ar));
System.out.println("Median= " + median(ar));
System.out.println("Std Dev= " + stdDev(ar));
}
public static double mean(int ar[]) {
int sum = 0;
for (int i = 0; i < ar.length; i++) {
sum += ar[i];
}
return (sum / ar.length);
}
public static int modal(int a[]) {
int n;
int freq = 0;
int Mfreq = 0;
int Mn = a[0];
for (int i = 0; i < a.length; i++) {
n = a[i];
for (int j = 0; j < a.length; j++) {
if (a[j] == n) {
freq++;
}
}
if (freq > Mfreq) {
Mn = n;
}
}
return Mn;
}
public static int median(int a[]) {
if (a.length % 2 == 0) {
int x = a[a.length / 2];
int y = a[ (a.length + 2) / 2];
return (x + y) / 2;
}
else {
return a[ (a.length + 1) / 2];
}
}
public static double stdDev(int a[]) {
int s2 = 0;
int s = 0;
for (int i = 0; i < a.length; i++) {
s2 += (a[i] * a[i]);
s += a[i];
}
return Math.sqrt( (s2 - (s * 2) / a.length) / (a.length - 1));
}
public static void sort(int a[]) {
int tmp;
for (int i = 0; i < a.length; i++) {
for (int j = 0; j < a.length; j++) {
if (a[j] > a[j + 1]) {
tmp = a[j];
a[j] = a[j + 1];
a[j + 1] = tmp;
}
}
}
}
public static int ReadFile(String filename, int ar[]) {
File infile = new File(filename);
int value, n = 0;
try {
BufferedReader reader = new BufferedReader(new FileReader(infile));
String line = null;
while ( (line = reader.readLine()) != null) {
value = Integer.parseInt(line);
ar[n++] = value;
}
return n;
}
catch (IOException e) {
System.err.println("Problem reading input file!");
}
return n;
}
}
Last edited by ComputerJy; Feb 1st, 2006 at 07:32 PM.
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
-
Feb 2nd, 2006, 05:12 PM
#3
Re: Ok I need help and I'm willing to pay $25 via Paypal
The code I sent you is the source code
you only need to save it in a file called "App.java" case sensetive without the quotes
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|