Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: how to return value ..

  1. #1
    Junior Member
    Join Date
    Feb 2011
    Thanked 0 Times in 0 Posts

    Question how to return value ..

    Hi guys
    help me..in d following code i jus wish to use scanner to get input at d same time wanna return net salary,which s d deducted salary of tax..
    my return statement not working..some mistake i hav done ..suggest me a way to proceed
    Thanks in advance
    import java.util.*;
    class Employee
    double salary,tax;
    double netsalary()
    public static void main(String args[])
    double salary,tax;
    System.out.println("Enter salary");
    Scanner scan=new Scanner(System.in);
    if(salary>200000 && salary<250000)
    else if(salary>250000 && salary<300000)
    Employee e=new Employee();
    System.out.println("Net Salary = "+e.netsalary());
    Last edited by helloworld922; February 12th, 2011 at 03:15 PM.

  2. #2
    Member samfin's Avatar
    Join Date
    Dec 2010
    Manchester UK
    Thanked 5 Times in 4 Posts

    Default Re: how to return value ..

    Your netsalary() method is using the instance variables salary and tax which are initialised to 0 so when you do salary*tax it is 0*0=0
    The main method is using its own copy of the salary and tax variables you've declared at the start and these are the ones with the value assigned to them that you need to use. Basically you don't need the netsalary method or the instance variables.

Similar Threads

  1. return a day of the year
    By lipry in forum Java Theory & Questions
    Replies: 3
    Last Post: January 23rd, 2011, 05:10 PM
  2. Missing return statement
    By Stn in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 1st, 2011, 08:03 PM
  3. what is wrong with my return statement??????
    By amr in forum What's Wrong With My Code?
    Replies: 3
    Last Post: December 13th, 2010, 07:55 PM
  4. Problem with Return Function
    By Tracy22 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: October 26th, 2010, 03:32 PM
  5. ArrayList Unexpected Return
    By Cammack in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 31st, 2010, 09:23 PM