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.


>> REGISTER NOW TO START POSTING


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

Results 1 to 3 of 3

Thread: I dont see anything wrong with this(simple beginner code)

  1. #1
    Junior Member
    Join Date
    Sep 2012
    Posts
    14
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default I dont see anything wrong with this(simple beginner code)

    import java.util.Scanner;
    public class SetUpSite2
     
    {	
    	public static void main(String[] args)
    	{
    		final int FOUNDED_YEAR = 1977;
    		int currentYear;
    		int age;
     
    		Scanner input = new Scanner(System.in);
     
    		statementOfPhilosophy();
     
    		System.out.print("Enter the current year as a four digit number");
    		currentYear = input.nextInt();
    		age = calculateAge(FOUNDED_YEAR, currentYear);		// problem here
    		System.out.println("Founded in " + FOUNDED_YEAR);
    		System.out.println("Serving your for " + age + "years!");	
     
    	}
     
        public static void	statementOfPhilosophy()
    	{
    		System.out.println("Event Handlers Incorporated is");
    		System.out.println("dedicated to making your event");
    		System.out.println("a most memorable one.");
    	}
     
    		public static void calculateAge(int originYear, int currDate)
    	{
    		int years;
    		years = currDate - originYear;
    		return years;
    	}
     
    }

    I am not sure what is wrong with line 17, it says "incompatible data types" when everything I am using is 'int'
    I am also having trouble with my return line saying my return type is void.
    I appreciate the help, I am new to this site as well. Looking forward to being active here for my homework help and future projects to come.
    Last edited by helloworld922; September 26th, 2012 at 02:56 PM. Reason: please use [code] tags


  2. #2
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: I dont see anything wrong with this(simple beginner code)

    public static void calculateAge(int originYear, int currDate)
    The issue is where you declared your method. The return type is not an int.

  3. The Following User Says Thank You to helloworld922 For This Useful Post:

    Olympaphibian89 (September 26th, 2012)

  4. #3
    Junior Member
    Join Date
    Sep 2012
    Posts
    14
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default Re: I dont see anything wrong with this(simple beginner code)

    ah, thank you very much! I sat here staring at it for what seemed like an eternity and couldn't see the problem. I see it now, hidden in plain sight!!!

Similar Threads

  1. [SOLVED] What's wrong with my code?? (Total beginner)
    By TheProf in forum What's Wrong With My Code?
    Replies: 10
    Last Post: January 6th, 2012, 02:41 PM
  2. Please held. What is wrong with my code? I am a beginner ;)
    By mvonb17 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: December 30th, 2011, 05:33 PM
  3. Replies: 3
    Last Post: October 19th, 2011, 11:55 PM
  4. My code has error when its run....I dont understand what's wrong of it.
    By jacky@~ in forum What's Wrong With My Code?
    Replies: 3
    Last Post: October 11th, 2011, 07:48 AM
  5. My code have a simple error but i dont know how to solve it !!!
    By Blackhawk1993 in forum What's Wrong With My Code?
    Replies: 6
    Last Post: March 17th, 2011, 01:12 PM