Page 2 of 2 FirstFirst 12
Results 21 to 36 of 36
  1. #21
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by wendysbiggy View Post
    I believe he meant Indent! haha
    Yes it's. Sorry about the misspell.

    Indent means, leave proper space in each line of the code.

    Read the following document just after finish this.

    Java Style Guide: Indentation

  2. #22
    justin1980 is offline Member
    Join Date
    Jan 2010
    Location
    Wisconsin
    Posts
    20
    Rep Power
    0

    Default

    What do you mean by count the number of digits? do you mean the count the characters in the string?

  3. #23
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  4. #24
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by justin1980 View Post
    What do you mean by count the number of digits? do you mean the count the characters in the string?
    Seems to me it's like that. Or may be he wants to count numbers only, not the letters. Anyway, OP has to clear up us on that.

  5. #25
    wendysbiggy is offline Member
    Join Date
    Jan 2010
    Posts
    10
    Rep Power
    0

    Default

    Quote Originally Posted by Eranga View Post
    That's the different thing pal. I just ask you to do it point out the error is.

    First you get the user input and seem that you tried to count the number of digit in a different method. So you have to call the relevant method with the correct parameter. That method return value print to the console. That what you've to do basically.
    Yes, so after the user inputs a string, I want it to be passed into the method NumberOfDigits(). but i dont know how.

    I already have it with a defined number but i get confused when using scanner.
    Java Code:
    import java.util.Scanner;
    
    class NumberOfDigits
    {
    public static void main(String args[])
    {
    System.out.println("The Number Of Digits Is  " + NumberOfDigits( -23457));
    }
    public static int NumberOfDigits(int n)
    {
    if(n<0) n = -n;
    int c = 1;
    while(n > 9)
    {
    c++;
    n = n/10;
    }
    return c;
    }
    }

  6. #26
    justin1980 is offline Member
    Join Date
    Jan 2010
    Location
    Wisconsin
    Posts
    20
    Rep Power
    0

    Default

    What you mean by that?
    I just meant that I should have known it was a misspell. i was apologizing for the dumb question.

  7. #27
    wendysbiggy is offline Member
    Join Date
    Jan 2010
    Posts
    10
    Rep Power
    0

    Default

    I want it to count the characters yes, as in there are 4 digits in "4532"

  8. #28
    justin1980 is offline Member
    Join Date
    Jan 2010
    Location
    Wisconsin
    Posts
    20
    Rep Power
    0

    Default

    you can use the string.length() to count the characters like.
    Java Code:
    Scanner in = new Scanner(System.in);
    System.out.print("Please enter a Number!");
    String a = in.nextLine();
    
    System.out.print("The Number Of Digits Is " + a.length());

  9. #29
    justin1980 is offline Member
    Join Date
    Jan 2010
    Location
    Wisconsin
    Posts
    20
    Rep Power
    0

    Default

    If there are spaces though, i think that string.length() will count spaces.

  10. #30
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by wendysbiggy View Post
    I want it to count the characters yes, as in there are 4 digits in "4532"
    Okay, what's the logic you've in your mind. What's the way you think of.

    Give a try lol.

  11. #31
    wendysbiggy is offline Member
    Join Date
    Jan 2010
    Posts
    10
    Rep Power
    0

    Default

    Quote Originally Posted by justin1980 View Post
    you can use the string.length() to count the characters like.
    Java Code:
    Scanner in = new Scanner(System.in);
    System.out.print("Please enter a Number!");
    String a = in.nextLine();
    
    System.out.print("The Number Of Digits Is " + a.length());
    This makes much more sense to me. Thank you. I think the problem was that i should have rewrote a whole new class when using it with scanner and start fresh. Thank you both a lot for help, i learned something.

  12. #32
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by justin1980 View Post
    If there are spaces though, i think that string.length() will count spaces.
    Yes, length() method counts everything on the specified string.

    I prefer if you can guide our OP rather than just giving him a code. :)

  13. #33
    justin1980 is offline Member
    Join Date
    Jan 2010
    Location
    Wisconsin
    Posts
    20
    Rep Power
    0

    Default

    I prefer if you can guide our OP rather than just giving him a code.
    Ok, sorry I was just trying to help.

  14. #34
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by justin1980 View Post
    Ok, sorry I was just trying to help.
    Yep, I know that. And don't worry, I'm not discourage you. But if anyone learn a lot from you, that's the your gain right. If you just give a code most the people not learns things from that, and I hope our OP is not like that. :)

  15. #35
    justin1980 is offline Member
    Join Date
    Jan 2010
    Location
    Wisconsin
    Posts
    20
    Rep Power
    0

    Default

    What does "OP" mean? I am new to forums so that might sound dumb.

  16. #36
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by justin1980 View Post
    What does "OP" mean? I am new to forums so that might sound dumb.
    Through out the forum I used to name as Original Poster in common way.

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Array count number Occurances
    By gwithey in forum New To Java
    Replies: 2
    Last Post: 04-17-2009, 08:34 PM
  2. how to use Scanner with a number
    By cew27 in forum New To Java
    Replies: 10
    Last Post: 04-03-2009, 06:23 PM
  3. Replies: 4
    Last Post: 03-28-2009, 04:58 PM
  4. Replies: 8
    Last Post: 02-04-2009, 08:55 PM
  5. Replies: 0
    Last Post: 11-20-2007, 04:59 PM

Tags for this Thread

Posting Permissions

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