Some help in java? :)

Discussion in 'Computer Programming, Emulation, and Game Modding' started by Delta517, Nov 30, 2012.

Nov 30, 2012

Some help in java? :) by Delta517 at 7:43 PM (326 Views / 0 Likes) 4 replies

  1. Delta517
    OP

    Member Delta517 Its okay...Im a ninja ;)

    Joined:
    Nov 25, 2008
    Messages:
    1,327
    Country:
    Norway
    Hi! [​IMG] Im just learning to code and Im following Buckys tutorial on YouTube [​IMG] Im just up to part 18 so I really can't much, but I figured I'd try out something myself [​IMG]

    So basically I wanted to make a code where you wrote in your age and it would give you three different answers based on what you putted in [​IMG]

    Here's the code:

    import java.util.Scanner;

    class apples{
    public static void main(String args[]){
    Scanner ageInput = new Scanner(System.in);
    int age;

    System.out.println("Please enter your age here: ");
    age = ageInput.nextInt();

    if (ageInput.nextInt() >= 60)
    System.out.println("You are a senior citizien");
    else if (ageInput.nextInt() >=50)
    System.out.println("You are in your 50s");
    else
    System.out.println("You are a young buck");
    }
    }

    So the problem is that I have to insert three numbers before it will return any of the three answers that it should give [​IMG] Help, please? And please keep in mind that I'm a newbie at this xP
     
  2. Dermy

    Member Dermy GBAtemp Fan

    Joined:
    Jul 1, 2007
    Messages:
    314
    Country:
    United States
    Your if statements should have 'age' in them, not 'ageInput.nextInt()'. Right now you are telling the scanner to keep getting a new value from the user when you enter each conditional statment. Since you already got the value and stored it in the variable called age, you should use that as the comparison in your conditional statements.

    if (age >= 60)

    else if (age >=50)

    On a side note, you could change System.out.println("Please enter your age here: "); to System.out.print("Please enter your age here: "); so that when you enter the age it will stay on the same line as the message.
     
  3. Delta517
    OP

    Member Delta517 Its okay...Im a ninja ;)

    Joined:
    Nov 25, 2008
    Messages:
    1,327
    Country:
    Norway
    There! :D Thank you very much ^^ And also thanks for the tip! :D I see I still got a long way ahead of me, but atleast Im on the right path ^^
     
  4. Delta517
    OP

    Member Delta517 Its okay...Im a ninja ;)

    Joined:
    Nov 25, 2008
    Messages:
    1,327
    Country:
    Norway
    Another question :) I learned how to make a very basic calculator in the turoials, but I wanted it to show what numbers you entered in the equation(right word? xP).

    I tried this:

    import java.util.Scanner;

    class apples{
    public static void main(String args[]){
    Scanner inputNum = new Scanner(System.in);
    double fnum, snum, answer;

    System.out.print("Enter first number: ");
    fnum = inputNum.nextDouble();

    System.out.print("Enter second number: ");
    snum = inputNum.nextDouble();

    answer = fnum + snum;
    System.out.print(fnum "+" snum "=" answer);
    }
    }

    But it didn't work, si I was wondering if any of you could tell med how to make it show something like "5,7 + 3,4 = 9,1" at the end? :)
     
  5. Delta517
    OP

    Member Delta517 Its okay...Im a ninja ;)

    Joined:
    Nov 25, 2008
    Messages:
    1,327
    Country:
    Norway
    Cool, I figured it out! :D Its supossed to say like this "System.out.print(fnum + "+" + snum + "=" + answer);" :D
     

Share This Page