File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes what's wrong with this code..coz when I compile it I get some starnge results Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "what Watch "what New topic
Author

what's wrong with this code..coz when I compile it I get some starnge results

vuthlarhi donald
Ranch Hand

Joined: Jul 31, 2006
Posts: 76
public class Main {

/** Creates a new instance of Main */
public Main(int...num) {
int i;
int sum = 0;
for(i=0;i<num.length;i++)
{
sum += num[i];
}
System.out.println(num);
}

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Main mt = new Main (12,14,14);

}

}
Balasubramanian Chandrasekaran
Ranch Hand

Joined: Nov 28, 2007
Posts: 215

I don't see anything wrong with your code.I just copied your code and it compiles and works good.

One thing is that instead of printing "num" value you can print "sum" value which give the sum of numbers you pass as parameters for Main.
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11161
    
  16

If you'd post the EXACT and COMPLETE text of the error message, it would greatly help in diagnosing the problem.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
 
 
subject: what's wrong with this code..coz when I compile it I get some starnge results
 
Similar Threads
can anyone help me to fix this little problem
Percentage issue
using rational class for summation series
Methods return array
when i run my virtual machine just keeps going, but no output.