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 5 of 5

Thread: please help !need rush. i dont know how the computations should be done.. :(

  1. #1
    Junior Member
    Join Date
    Feb 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default please help !need rush. i dont know how the computations should be done.. :(

    create a program that will perform the following operation
    1. accept 1-5 letters.
    2. each letter corresponds to a number.
    3. generates the sum of the numbers selected.
    4.displays the average of the numbers selected.

    values of letter A=20 B=4 C=7 D=9 E=10 F=15 O=6 U=12 S=12
    either or joption o scanner ang gagamitin

    just a newbie with Data structure and algo please help to solve this .. ...

    public static void main(String[] args) {
    int A = 20,B = 4,C=7,D = 9, E = 10, F = 15, O = 6, U = 12, S = 12;
    int q;

    Scanner scan = new Scanner(System.in);

    System.out.println("Choose 2-5 letter from A,B,C,D,E,F,O,U,S");
    q= scan.nextInt();

    q = A + B;
    q = A + C;
    System.out.println("the sum of the enter letter is:"+q);

    should i continue this kind of equation?? or how should the computation should be done


  2. #2
    Junior Member
    Join Date
    Feb 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default can i ask how can a letter with value can be recognize in a program??

    can i ask how can a letter with value can be recognize in a program??

    1. accept 1-5 letters.
    2. each letter corresponds to a number.
    3. generates the sum of the numbers selected.
    4.displays the average of the numbers selected.

    values of letter A=20 B=4 C=7 D=9 E=10 F=15 O=6 U=12 S=12
    .. joption o scanner only can be use



    public static void main(String[] args) {
    int A = 20,B = 4,C=7,D = 9, E = 10, F = 15, O = 6, U = 12, S = 12;
    int sum,letters=0,q,w;

    Scanner scan = new Scanner(System.in);


    if (letters<2);
    System.out.println("Choose 2-5 letter from A,B,C,D,E,F,O,U,S");
    q = scan.nextInt () ;
    System.out.println("Choose 2-5 letter from A,B,C,D,E,F,O,U,S");
    w = scan.nextInt () ;
    sum = q + w;
    System.out.println("the sum of the letters is:"+sum);

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: can i ask how can a letter with value can be recognize in a program??

    int A = 20,B = 4,C=7,D = 9, E = 10, F = 15, O = 6, U = 12, S = 12;
    The names of variables are not useful when looking that user input.
    There are several ways to associate a letter input by a user with a value:
    One is to use a switch statement
    Another is to use a String and an array of the values with the letter's position in the String corresponding to the index into the array.
    Another would be a Map with the letter being the key and the value being the numeric value.
    If you don't understand my answer, don't ignore it, ask a question.

  4. #4
    Junior Member
    Join Date
    Feb 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default what wrong?? the value of the letter couldn't recognize

    how should the letter could be recognize?? public static void main(String[] args) {
    int A = 20,B = 4,C=7,D = 9, E = 10, F = 15, O = 6, U = 12, S = 12;
    int sum,letters=0,q,w;

    Scanner scan = new Scanner(System.in);

    System.out.println("Choose 2-5 letter from A,B,C,D,E,F,O,U,S");
    q = scan.nextInt () ;
    System.out.println("Choose 2-5 letter from A,B,C,D,E,F,O,U,S");
    w = scan.nextInt () ;
    if (letters<2);

    sum = q + w;
    System.out.println("the sum of the letters is:"+sum);




    the value of the letter couldn't recognize

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: can i ask how can a letter with value can be recognize in a program??

    the value of the letter couldn't recognize
    Please explain the problem.

    The code uses the wrong Scanner method to read a letter. nextInt() is for reading numbers.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Rush hour game
    By zerocos in forum What's Wrong With My Code?
    Replies: 46
    Last Post: January 25th, 2013, 06:05 PM
  2. Dont know how to recorrect
    By Asin in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 2nd, 2011, 12:59 PM
  3. I dont get it....please help
    By DestinyChick1225 in forum What's Wrong With My Code?
    Replies: 12
    Last Post: June 30th, 2010, 03:16 AM
  4. Dont laugh at me
    By Neblin in forum What's Wrong With My Code?
    Replies: 5
    Last Post: October 3rd, 2009, 08:18 AM