By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,646 Members | 1,481 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,646 IT Pros & Developers. It's quick & easy.

No output from return statement in method

P: 1
For some reason, there is no output coming from the return statement when i run the program, i don't see what i'm doing wrong.

Expand|Select|Wrap|Line Numbers
  1. public class Supermarkets 
  2. {      
  3.  
  4.     String[] cities = { "Miami", "Sunrise", "Hollywood" , "Tallahasse" , "Jacksonville" , "Orlando" , "Gainesville" , "Pensacola" , "Ocala" , "Sebring"};   
  5.     double[] profit = {10200000.00, 14600000.00, 17000000.00, 6000000.00, 21600000.00, 9100000.00, 8000000.00, 12500000.00, 2000000.00, 4500000.00};
  6.  
  7.     DecimalFormat d = new DecimalFormat();
  8.  
  9.  
  10.    String display()
  11.    {
  12.        String s = "";
  13.  
  14.        for(int i = 0; i < profit.length; i++)
  15.        {
  16.          //System.out.println(cities[i] + " " + d.format(profit[i]));
  17.            s = s + cities[i] + " " + profit[i] + "/n";      
  18.        }
  19.       return s;
  20.  
  21.    }
The system.out method does give output, but the return s does nothing. In the test class i call the method through:

Expand|Select|Wrap|Line Numbers
  1. public static void main(String[] arg)
  2.     {
  3.         Supermarkets beam = new Supermarkets();
  4.         beam.display();
  5.         }      
Any help please?
Nov 27 '12 #1
Share this Question
Share on Google+
1 Reply


Rangan
P: 8
display function returned value. But you didnt print that value.
System.out.println(beam.display());
Dec 5 '12 #2

Post your reply

Sign in to post your reply or Sign up for a free account.