Simple Java program

Hi all,

I know it's a silly question, but I just can't find a way to do it.

I need to write a program that read numbers (I don't know how many), separated by space, from a txt file.

The program needs to print to the screen the average of the numbers.

Thanks,

Yotam

[309 byte] By [Yotama] at [2007-11-26 21:29:27]
# 1
Do your own fscking homework.
bckrispia at 2007-7-10 3:09:53 > top of Java-index,Java Essentials,New To Java...
# 2
In the absence of a specific question... http://java.sun.com/docs/books/tutorial/getStarted/cupojava/win32.html http://java.sun.com/docs/books/tutorial/essential/io/index.html
jverda at 2007-7-10 3:09:53 > top of Java-index,Java Essentials,New To Java...
# 3
> Do your own fscking homework.You know, learning to use [url= http://www.adminschoice.com/docs/fsck.htm]fsck[/url] might not be a bad assignment.
DrLaszloJamfa at 2007-7-10 3:09:53 > top of Java-index,Java Essentials,New To Java...
# 4

> Hi all,

> I know it's a silly question, but I just can't find a

> way to do it.

>

> I need to write a program that read numbers (I don't

> know how many), separated by space, from a txt file.

>

>

> The program needs to print to the screen the average

> of the numbers.

>

>

> Thanks,

> Yotam

What have you read or studied to date, how much code have you written to date, what problem areas are there for you, and where have you looked for information?

abillconsla at 2007-7-10 3:09:53 > top of Java-index,Java Essentials,New To Java...
# 5

import java.util.*;

import java.io.*;

public class Test

{

public static void main(String args[]) throws Exception

{

Scanner scan = new Scanner(new File("G:/java files1/jmf/file.txt"));

int sum=0, count=0;

while(scan.hasNext("[0-9]+"))

{

sum+=Integer.parseInt(scan.next("[0-9]+"));

count++;

}

System.out.println("The Sum is "+(float)(sum/count));

}

}

qUesT_foR_knOwLeDgea at 2007-7-10 3:09:53 > top of Java-index,Java Essentials,New To Java...
# 6

> > import java.util.*;

> import java.io.*;

>

> public class Test

> {

> public static void main(String args[]) throws

> s Exception

> {

> Scanner scan = new Scanner(new File("G:/java

> va files1/jmf/file.txt"));

> int sum=0, count=0;

> while(scan.hasNext("[0-9]+"))

> {

> sum+=Integer.parseInt(scan.next("[0-9]+"));

> count++;

> }

> System.out.println("The Sum is

> is "+(float)(sum/count));

> }

> }

>

When I saw this post with code my next step was to check whether there was any dukes available. And of course there was. :-)

kikemellya at 2007-7-10 3:09:53 > top of Java-index,Java Essentials,New To Java...
# 7

> Hi all,

> I know it's a silly question, but I just can't find a

> way to do it.

>

> I need to write a program that read numbers (I don't

> know how many), separated by space, from a txt file.

>

>

> The program needs to print to the screen the average

> of the numbers.

>

>

import java.util.Scanner;

import java.io.*;

class ManySquares

{

public static void main (String[] args) throws IOException

{

Filefile = new File("myData.txt");// create a File object

Scanner scan = new Scanner( file );// connect a Scanner to the file

int num, sum, count =0;

double avg;

while( scan.hasNextInt() )// is there more data to process?

{

num = scan.nextInt();

sum = sum + num;

count++;

}

avg = sum/count;

System.out.println("The total is " + sum);

System.out.println("The total average is " + avg);

}

}

the code is not tested if you have any problems come back. it is good to make an array and then create different methods for average and sum

fastmikea at 2007-7-10 3:09:53 > top of Java-index,Java Essentials,New To Java...
# 8

> > import java.util.*;

> import java.io.*;

>

> public class Test

> {

> public static void main(String args[]) throws

> s Exception

> {

> Scanner scan = new Scanner(new File("G:/java

> va files1/jmf/file.txt"));

> int sum=0, count=0;

> while(scan.hasNext("[0-9]+"))

> {

> sum+=Integer.parseInt(scan.next("[0-9]+"));

> count++;

> }

> System.out.println("The Sum is

> is "+(float)(sum/count));

> }

> }

>

You know, this duke whoring made almost made sense when they were at least refered to as Dollars, but now it's just simply sleeping around and then getting a little star pasted to your forehead to show everybody that that's what you did.

Edit: And that obviously goes for the post directly before this one, too.

masijade.a at 2007-7-10 3:09:53 > top of Java-index,Java Essentials,New To Java...
# 9
Thanks!!
Yotama at 2007-7-10 3:09:53 > top of Java-index,Java Essentials,New To Java...
# 10

> Thanks!!

Yeah! Now think about the all stuff you have learned by getting someone else to write your code.

You know all the complier errors and exceptions are what drives the basic syntax home, you need to try and write your own code and make these mistakes, read up on what you need to do, try to code it, if you get stuck then post here your broken code. You will learn nothing with your current approach. You need to make mistakes to learn, and lots of them. So don't be shy and get on with it in future. What good is a block of code that you don't undertand that runs without error to you(Someone who is trying to learn Java)? .

kikemellya at 2007-7-10 3:09:53 > top of Java-index,Java Essentials,New To Java...
# 11
Don't waste your breath. Cheaters can't change their spots (like the pun?) and people who help them are plain fucktards!
floundera at 2007-7-10 3:09:53 > top of Java-index,Java Essentials,New To Java...
# 12
Let cheaters cheat! It will all come back at them sooner or later. Cheaters don't learn.
Lucas207a at 2007-7-10 3:09:53 > top of Java-index,Java Essentials,New To Java...
# 13

> Let cheaters cheat! It will all come back at them

> sooner or later. Cheaters don't learn.

I used to think that. But look around you. Newt Gingrich is going to run for

president, and he's just admitted to cheating on his wife at the same time

he was getting congress to impeach Bill Clinton for the affair with Monica

Lewinsky. Newt's defense? Since he wasn't caught he didn't have to lie,

and since he didn't lie, he wasn't as culpable as Clinton.

DrLaszloJamfa at 2007-7-10 3:09:53 > top of Java-index,Java Essentials,New To Java...
# 14
touche...
Lucas207a at 2007-7-10 3:09:53 > top of Java-index,Java Essentials,New To Java...
# 15
I think I would rather vote for that born-again minister who eventuallyadmitted to doing drugs and getting a "Christian Prostate Massage".
DrLaszloJamfa at 2007-7-21 18:18:58 > top of Java-index,Java Essentials,New To Java...
# 16

> Let cheaters cheat! It will all come back at them

> sooner or later. Cheaters don't learn.

Usually later, if at all, and usually not before making someone else's life a living hell (maybe even SomeoneElse's life). And in some places, rather than dealing with them, supervisors will send them to courses and lectures and conferences time and again to get them out of their hair. This will let their resume look really good (mangement-wsie) and give them a real chance to hold a position above you (for at least a litlle while). This sort of thing happens in the military all the time (you can't "fire" them in the military unless they actually cause some real harm).

masijade.a at 2007-7-21 18:18:58 > top of Java-index,Java Essentials,New To Java...
# 17
> I think I would rather vote for that born-again> minister who eventually> admitted to doing drugs and getting a "Christian> Prostate Massage".Thought you lived in the 'Great White North'?
abillconsla at 2007-7-21 18:18:58 > top of Java-index,Java Essentials,New To Java...
# 18

> > I think I would rather vote for that born-again

> > minister who eventually

> > admitted to doing drugs and getting a "Christian

> > Prostate Massage".

>

> Thought you lived in the 'Great White North'?

On American election day, for a mickey of rye, they press gang us onto

open back trucks and drive us down to voting stations.

In the last election I was Milagro Campo De La Haba

DrLaszloJamfa at 2007-7-21 18:18:58 > top of Java-index,Java Essentials,New To Java...
# 19

> > > I think I would rather vote for that born-again

> > > minister who eventually

> > > admitted to doing drugs and getting a "Christian

> > > Prostate Massage".

> >

> > Thought you lived in the 'Great White North'?

>

> On American election day, for a mickey of rye, they

> press gang us onto

> open back trucks and drive us down to voting

> stations.

> In the last election I was Milagro Campo De La Haba

Isn't tye what Canadian Whiskey (is it whisky or whiskey in Canada BTW?) is made of?

I meant rye

Message was edited by:

abillconsl

abillconsla at 2007-7-21 18:18:58 > top of Java-index,Java Essentials,New To Java...
# 20

> Isn't rye what Canadian Whiskey (is it whisky or whiskey in Canada BTW?) is made of?

Spelling: no 'e' in Canadian Whisky. The 'e' is only for Irish and American:

http://en.wikipedia.org/wiki/Whiskey#Names_and_spellings

<quote>

A mnemonic used to remember which spelling is used is that "Ireland" and

"United States" have at least one "e" in their names, while "Scotland", "Canada"

and "Japan" do not.

</quote>

In Canada, domestic whisky is often called "rye whisky", especially in

mixed drinks: "rye and ginger". It is made with some rye, although

American rye whiskey (which is getting easier to find these days) is

different and has more rye in it.

DrLaszloJamfa at 2007-7-21 18:18:58 > top of Java-index,Java Essentials,New To Java...
# 21

> > Isn't rye what Canadian Whiskey (is it whisky or

> whiskey in Canada BTW?) is made of?

>

> Spelling: no 'e' in Canadian Whisky. The 'e' is only

> for Irish and American:

>

> http://en.wikipedia.org/wiki/Whiskey#Names_and_spellin

> gs

>

> <quote>

> A mnemonic used to remember which spelling is used is

> that "Ireland" and

> "United States" have at least one "e" in their names,

> while "Scotland", "Canada"

> and "Japan" do not.

> </quote>

>

> In Canada, domestic whisky is often called "rye

> whisky", especially in

> mixed drinks: "rye and ginger". It is made with some

> rye, although

> American rye whiskey (which is getting easier to find

> these days) is

> different and has more rye in it.

Thought as much ... personally I prefer Scotch if I drink whisky.

abillconsla at 2007-7-21 18:18:58 > top of Java-index,Java Essentials,New To Java...
# 22
> Thought as much ... personally I prefer Scotch if I drink whisky.Don't get me started on single malts! I was once quite the single malt snob,although if you're mixing it, I'll even drink Chinese Scotch.
DrLaszloJamfa at 2007-7-21 18:18:58 > top of Java-index,Java Essentials,New To Java...
# 23

> > Thought as much ... personally I prefer Scotch if I

> drink whisky.

>

> Don't get me started on single malts! I was once

> quite the single malt snob,

> although if you're mixing it, I'll even drink Chinese

> Scotch.

Ha! ... I was a bit of a snob about that too. Wife recently got me a $90 bottle of The GlenLivet 25 yr old for a gift. I liked it of course ... but as I'm getting older my palate is becoming lesssensitive to all the complexities - so less reason to be the snob.

Message was edited by:

abillconsl

abillconsla at 2007-7-21 18:18:58 > top of Java-index,Java Essentials,New To Java...