• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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);

}

}
 
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you'd post the EXACT and COMPLETE text of the error message, it would greatly help in diagnosing the problem.
 
reply
    Bookmark Topic Watch Topic
  • New Topic