• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

Problem with print

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[code=java][/code]
public class ProgrammingOnNumbers{
public static void main(String[]args){  
int m=4, n=9;  
System.out.println(sum);
}
/*
*Computes the sum of natural number larger the m and smaller than n
*/
public static int sumbetween(int m, int n){
int i = m+1;
int sum = 0;
while(i<n){
sum = sum + i;
i = i + 1;
}
return sum;
}
}

When the compiler say, ProgrammingOnNumbers.java4: error: cannot find symbol
System.out.println(sum);

Anyone there can see where the problem is? :-)
 
Rancher
Posts: 108
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. You are trying to print a variable "sum" that doesn't exist. I think you meant to call your method sumbetween there instead.
 
Sheriff
Posts: 6268
167
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch, Katrine Nicolaisen!

Thanks for trying to use code tags.  However, you didn't quite get it right.  The code goes between the opening and closing tags.  Use the Preview button (right next to the Submit button) to see if you have done everything correctly.

You can review how to UseCodeTags by clicking that link.
 
Ranch Hand
Posts: 392
4
Android Tomcat Server Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're not calling sumbetween method.
 
I AM MIGHTY! Especially when I hold this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!