Results 1 to 8 of 8
  1. #1
    blazinhieu is offline Member
    Join Date
    Mar 2010
    Posts
    8
    Rep Power
    0

    Default input method help?

    Hi ! I want to write a java program that calculate age. What code do i need to use to let the user enter their birth year? (input method i think). Thanks

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,541
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by blazinhieu View Post
    Hi ! I want to write a java program that calculate age. What code do i need to use to let the user enter their birth year? (input method i think). Thanks
    If the user is male you can probably just politely ask; if the user is female you probably have to threaten her with a gun.

    kind regards,

    Jos

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by blazinhieu View Post
    Hi ! I want to write a java program that calculate age. What code do i need to use to let the user enter their birth year? (input method i think). Thanks

    A Scanner object would work nicely. As far as "what code" -- that's up to you since it's your assignment. What have you tried so far, and what has been the result?

  4. #4
    blazinhieu is offline Member
    Join Date
    Mar 2010
    Posts
    8
    Rep Power
    0

    Default

    Sorry i'm kinda stupid since i'm a beginner but what is "scanner"? :D , It's not an assignment :D, i saw my teacher's example code and i want to write a program that is similar to it (since i fall way behind in my class), this is my teachers code:
    Java Code:
    [COLOR="Green"]import javax.swing.*;
    public class Calculation{
      public static void main(String []args){
         [COLOR="Red"]new Calculation()[/COLOR];
      }
      public Calculation(){
        Cube c= new Cube();
        int i=5;
       [COLOR="Red"] int squareIt = c.square(i);[/COLOR]
        System.out.println(squareIt);
        [COLOR="Red"]int cubeIt = c.cube(i);[/COLOR]
        System.out.println(cubeIt);
      }
    }
    
    class Cube{
      public Cube(){}
      [COLOR="Red"]public int square(int i)[/COLOR]{
        return i*i;
      }
     [COLOR="Red"] public int cube(int i)[/COLOR]{
        return i*i*i;
      [/COLOR]}
    }
    But if you can explain to me how those red lines work then nevermind the assignment :D Thanks. please excuse my stupidity
    Last edited by blazinhieu; 03-12-2010 at 02:32 PM.

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

  6. #6
    blazinhieu is offline Member
    Join Date
    Mar 2010
    Posts
    8
    Rep Power
    0

    Default

    sorry ok i fixed it :D

  7. #7
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by blazinhieu View Post
    But if you can explain to me how those red lines work then nevermind the assignment :D Thanks. please excuse my stupidity
    What you're asking is how to call methods and constructors in Java, and the way to learn this is through your text books and notes. If you haven't found the Sun tutorials, please have a look as it will explain this better than any of us can:

    Trail: Learning the Java Language (The Java™ Tutorials)

    Best of luck!

  8. #8
    blazinhieu is offline Member
    Join Date
    Mar 2010
    Posts
    8
    Rep Power
    0

Similar Threads

  1. standard input stream storing to a generic method?
    By vendetta in forum New To Java
    Replies: 3
    Last Post: 01-29-2010, 08:13 PM
  2. More than one input in one private method
    By rice in forum New To Java
    Replies: 0
    Last Post: 10-02-2009, 05:08 AM
  3. Replies: 0
    Last Post: 09-21-2009, 11:33 AM
  4. Input parameter of Main method
    By Java Tip in forum Java Tip
    Replies: 1
    Last Post: 07-12-2008, 06:24 PM
  5. how to take input and verify input in Java programs
    By bilal_ali_java in forum Advanced Java
    Replies: 0
    Last Post: 07-21-2007, 08:46 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •