Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Review my Java program..

 
dessa jones
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My homework assignment is as is below and the program. Please let me know if this is what the instructor is asking for when he states "procedures" within the program. I'm alittle confused as to what he is asking. Do I need to add more, am I on target, or completely wrong. The program is also below..
Program: Create a java program that uses arrays.
you must create a procedure and enter data into this array in the procedure. you must create another procedure and display the date entered from inside the other procedure.
class ArrayOps
{
// . . . previous methods could go here
// add up all the elements in an array
int sumElements ( int[] nums )
{
int sum = 0;
for ( int j=0; j < nums.length; j++ )
sum += nums[j];
return sum;
}
}
class ArrayDemo
{
public static void main ( String[] args )
{
ArrayOps operate = new ArrayOps();
int[] ar1 = { -20, 19, 1, 5, -1, 27, 19, 5 } ;
System.out.println("The sum of elements is: " +
operate.sumElements( ar1 ) );
}
}
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Procedures? You can start by explaining to your prefessor that they are called methods in Java. :roll:
 
Shashi Kanta
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Procedure means method in Java. It is a function you write to carry out certain common task.
I think what he wants is something like this:

Hope your instructor is satisfied with your assigment !!
Shashi
p.s: by the way are you still studying in a school or college? just curious !!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic