Results 21 to 36 of 36
- 01-20-2010, 04:38 AM #21
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
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
- 01-20-2010, 04:38 AM #22
Member
- Join Date
- Jan 2010
- Location
- Wisconsin
- Posts
- 20
- Rep Power
- 0
What do you mean by count the number of digits? do you mean the count the characters in the string?
- 01-20-2010, 04:39 AM #23
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
- 01-20-2010, 04:40 AM #24
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
- 01-20-2010, 04:41 AM #25
Member
- Join Date
- Jan 2010
- Posts
- 10
- Rep Power
- 0
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; } }
- 01-20-2010, 04:42 AM #26
Member
- Join Date
- Jan 2010
- Location
- Wisconsin
- Posts
- 20
- Rep Power
- 0
I just meant that I should have known it was a misspell. i was apologizing for the dumb question.What you mean by that?
- 01-20-2010, 04:42 AM #27
Member
- Join Date
- Jan 2010
- Posts
- 10
- Rep Power
- 0
I want it to count the characters yes, as in there are 4 digits in "4532"
- 01-20-2010, 04:45 AM #28
Member
- Join Date
- Jan 2010
- Location
- Wisconsin
- Posts
- 20
- Rep Power
- 0
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());
- 01-20-2010, 04:46 AM #29
Member
- Join Date
- Jan 2010
- Location
- Wisconsin
- Posts
- 20
- Rep Power
- 0
If there are spaces though, i think that string.length() will count spaces.
- 01-20-2010, 04:50 AM #30
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
- 01-20-2010, 04:51 AM #31
Member
- Join Date
- Jan 2010
- Posts
- 10
- Rep Power
- 0
- 01-20-2010, 04:51 AM #32
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
- 01-20-2010, 04:53 AM #33
Member
- Join Date
- Jan 2010
- Location
- Wisconsin
- Posts
- 20
- Rep Power
- 0
Ok, sorry I was just trying to help.I prefer if you can guide our OP rather than just giving him a code.
- 01-20-2010, 04:59 AM #34
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
- 01-20-2010, 05:06 AM #35
Member
- Join Date
- Jan 2010
- Location
- Wisconsin
- Posts
- 20
- Rep Power
- 0
What does "OP" mean? I am new to forums so that might sound dumb.
- 01-20-2010, 05:11 AM #36
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Similar Threads
-
Array count number Occurances
By gwithey in forum New To JavaReplies: 2Last Post: 04-17-2009, 08:34 PM -
how to use Scanner with a number
By cew27 in forum New To JavaReplies: 10Last Post: 04-03-2009, 06:23 PM -
How to count the number of specific object in a Vector collection?
By johnsienk in forum New To JavaReplies: 4Last Post: 03-28-2009, 04:58 PM -
[SOLVED] How to count the number of words in a string
By andy5605 in forum New To JavaReplies: 8Last Post: 02-04-2009, 08:55 PM -
Using java.util.Scanner to search for a String in a String
By Java Tip in forum Java TipReplies: 0Last Post: 11-20-2007, 04:59 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks