Results 1 to 11 of 11
  1. #1
    akocnivek is offline Member
    Join Date
    Oct 2012
    Posts
    10
    Rep Power
    0

    Default i really need ur help guys.

    hi guys.
    can u please help me in my project?
    i need a code for a java program that accepts input number and displays the largest among the individual digits of that input.
    The sample output is here.

    Input Number: 1234569822
    Largest Digit: 9


    We cant still use arrays guys because we didnt discuss it yet.
    Hope u can help me with this.
    for loop,while loop can do
    thanks.

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

    Default Re: i really need ur help guys.

    Do you know how to find the least significant digit of a number? e.g. for the number 12345, the least significant digit is 5.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    akocnivek is offline Member
    Join Date
    Oct 2012
    Posts
    10
    Rep Power
    0

    Default Re: i really need ur help guys.

    my bad.
    im really new to programming.
    i dont really know.
    hope u can help me

  4. #4
    penguinCoder is offline Member
    Join Date
    Oct 2012
    Location
    Tempe, Arizona
    Posts
    77
    Blog Entries
    12
    Rep Power
    0

    Default Re: i really need ur help guys.

    Hint: It involves modulus and the base of the number format you are using...
    Catching exceptions is for communists

  5. #5
    akocnivek is offline Member
    Join Date
    Oct 2012
    Posts
    10
    Rep Power
    0

    Default Re: i really need ur help guys.

    can u help me with the code?
    im really new to java programming,
    ^_^

  6. #6
    penguinCoder is offline Member
    Join Date
    Oct 2012
    Location
    Tempe, Arizona
    Posts
    77
    Blog Entries
    12
    Rep Power
    0

    Default Re: i really need ur help guys.

    What did you have completed? Do you know how modulus works?

    I can help you with the code, but I'm not going to write it all for you.
    Catching exceptions is for communists

  7. #7
    akocnivek is offline Member
    Join Date
    Oct 2012
    Posts
    10
    Rep Power
    0

    Default Re: i really need ur help guys.

    modulu sounds familiar but im going to check it.
    i really need ur help with this because im failing this subject.

  8. #8
    penguinCoder is offline Member
    Join Date
    Oct 2012
    Location
    Tempe, Arizona
    Posts
    77
    Blog Entries
    12
    Rep Power
    0

    Default Re: i really need ur help guys.

    Just break it down into more manageable sections. Rather then thinking about the entire project, think of it as four parts.

    A)Gather input from the user
    Using println() methods and the Scanner object.

    B)Perform math on the user input
    Using modulus (%), you can find the remainder.

    C)Perform some type of comparison to find the largest single digit number
    You could do this while doing the math, to save on variables, or save them all and do it later.

    D)Output the answer to the user


    Modulus is a tool that is used to find the remainder after a division occurs. Say you have 12/5, the answer would be 5 with 2 left over. If you used modulus, 12%5, the answer would be just the 2 left over. You can use this to find the least signigicant digit in a larger number. Say you have 25, and you wanted just the 5. Well since digits are base 10, you can just take the modulus of 25, 25%10, and you are just left with the 5.
    Catching exceptions is for communists

  9. #9
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: i really need ur help guys.

    Now also appearing at javaprogrammingforums.com

    @OP: If you are going to start a discussion in multiple places, please post links in each to the others. That way all the participants in the discussion know what else is being said.

    And it is a discussion: questions, replies, comments, thoughts and reflections - all occurring in both directions. What it is *not* is a homework service. Not here, and not at javaprogrammingforums.

    ---

    Have you thought about the problem? If so, it would be good to hear how you yourself (rather than a computer) would go about determining that 9 was the largest digit as you stated. Such a procedure (or algorithm) would form the basis of your code.

    Look up the modulus or remainder operator (%) and find out how it relates to the least significant digit. Try and incorporate that into your algorithm (recipe) for determining the largest digit, and let us know how you get on.
    Last edited by pbrockway2; 10-19-2012 at 09:12 AM.

  10. #10
    akocnivek is offline Member
    Join Date
    Oct 2012
    Posts
    10
    Rep Power
    0

    Default Re: i really need ur help guys.

    how about i want to input random numbers?

  11. #11
    akocnivek is offline Member
    Join Date
    Oct 2012
    Posts
    10
    Rep Power
    0

    Default Re: i really need ur help guys.

    import java.util.Scanner;
    class group{
    public static void main(String arng[]){
    int value[]= new int[5];
    int temp,i;
    Scanner data = new Scanner(System.in);
    System.out.println("Enter 5 element of array" );
    // Enhanced for loop
    for(i=0; i < 5; i++ ) value[i] = data.nextInt();
    // finding Largest number
    temp = value[0];
    for(i=0; i < 5; i++ )
    {
    if(temp > value[i])
    continue;
    else
    temp = value[i];
    }
    System.out.println("Largest number in array is "+temp);
    }
    }

    Output:-

    Enter 5 element of array
    25
    154
    28522
    218
    2564
    Largest number in array is 28522


    i tried this but how can i do it without arrays?
    and in a single 10 digits input how can i get the largest?
    like 9899823211
    how can i get 9?

Similar Threads

  1. Hello guys
    By RamaAditya in forum Introductions
    Replies: 2
    Last Post: 09-24-2011, 06:02 PM
  2. hey, guys
    By yvangkwheng in forum Introductions
    Replies: 1
    Last Post: 03-11-2010, 09:02 AM
  3. Hey guys!
    By Syntax in forum Introductions
    Replies: 0
    Last Post: 01-15-2010, 08:58 PM
  4. hi guys
    By jackson787 in forum Reviews / Advertising
    Replies: 0
    Last Post: 01-12-2010, 06:19 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
  •