This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
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


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: 11356
    
  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
 
GeeCON Prague 2014
 
subject: what's wrong with this code..coz when I compile it I get some starnge results