Click to See Complete Forum and Search --> : small program but Iam beginner


Davinci_code
10-14-2006, 11:40 PM
Good evening

I am beginner in java and I faced a problem in solve my assignment so I need a help

Write a Java program to do the following: [9 marks]
a. read 10 integer numbers and store them in an array.
b. find the average of all the numbers stored in the array.
c. print the values of the array and the results of the sum, and average.
d. find the maximum number in this array.

I don’t know how read integer in java? it is an open education and there are no tutor to help me there is no hand books that explain java because the course is software system by java there are a long codes you cant not understand any things, so I read many sites and e-books to develop my knowledge but the assignment not similar to the activity on books
So please I need help

Khalid Ali
10-15-2006, 01:28 PM
Well we get homework questions every now and then, however, its in your benefit that if don't provide you a complete solution.
Here is what you can do to get better help..
Try to write whatever code you can and then post that here and ask for help on specific issues in that program.

1. create a java source file(with java file extension)
2. compile the java file (this will produce a *.class file format)
3. see if the desired results are produced.

Now look at all of the above steps and try to come up with your version of solution and I am certain one of us around here will be glad to guide you through..

Good Luck

Davinci_code
10-15-2006, 07:47 PM
you dont understand me how I write program without know the methods?????????????????????????????????????????

my book only methods that used are system.out.printIn , paint and how

to create variable use try... catch ...

my question what is the method and how I can use it to read the integer

to solve this question

Khalid Ali
10-16-2006, 10:24 AM
I do understand however, you don't.
Anyways, I'll try to explain the basic structure for u.
1. Create file and name it "Assignment.java" (without the qoutes and make sure extension is java, a file extension is the part that comes after the last decimal/dot character)
2. in this file make sure that class name is exactly as the files name

3. Then you will require a main method which has to be there for a stand alone desk top style java program
public static void main(String[] args){

}
4. Here is the complete logic and some pseudo code for you to work on. If this does not help, then I don't know what will (because I am not willing write the remaining part for you unless you tried something yourself). Good Luck

public class Assignment{
public static void main(String[] args) {
//declare a variable array, of type integer, that will hold 9 digits
//uncomment the line below to use this
//int[] userInput = {0,9,2,6,4,3,1,7,8,5};

//or you can get data input by the user using System.in
//to use the above format you will have to read up System.in in JAVA API's

//once you have all of the above then you can run a loop thru the array and
//perform your required tasks.. here is the logic how you can do that.
/*
int sum=0; //declare a int variable to hold sum of all ints
for each item in array{
get value from array to a local variable of type int
add this value to sum
sum+=n

}
find the average here (sum/array.length)
print the sum here
get the largest/lowest number from array here


*/

}
}

agent_x91
10-18-2006, 06:00 AM
only methods that used are system.out.printIn

Btw, it's System.out.println(), not In.

A quick hint, to get user input you import java.io.* and use something like:


public static final int NUM_VALUES=10;
int[] user_input=new int[10];

//....

BufferedReader input=new BufferedReader(new InputStreamReader(System.in));

for(int i=0;i<NUM_VALUES;i++)
{
user_input[i]=Integer.parseInt(input.readLine());
}


Adapt that to collect user input data.

acemo
10-18-2006, 11:48 AM
Well we get homework questions every now and then, however, its in your benefit that if don't provide you a complete solution.
Here is what you can do to get better help..
Try to write whatever code you can and then post that here and ask for help on specific issues in that program.

1. create a java source file(with java file extension)
2. compile the java file (this will produce a *.class file format)
3. see if the desired results are produced.

Now look at all of the above steps and try to come up with your version of solution and I am certain one of us around here will be glad to guide you through..

Good Luck

Now this is why i love this forum.
Other ppl scripts dont let u learn a thing. (unless u get the script + clear explenation of everything)
Here u get to use ur brains urself so u will actually learn things.

agent_x91
10-19-2006, 03:26 AM
Did I waste my effort then? :eek:

Davinci_code
10-21-2006, 09:22 PM
Hi

Thanks allot for all reply you help me to solve this question