Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Character ammount
#1
I've just finished watching your tenth "Learning Java" part and I want to limit the character number to five digits only. 
I've tried this:
Code:
import java.util.*;
public class digitExtractorTester {
    static Scanner userInput = new Scanner(System.in);
    
    public static void main(String[] args){
        String rNumber = "12345";
        System.out.print("Enter a custom, five digit number: ");
        String nSequence = userInput.next();
        System.out.println(" ");
        if (nSequence.chars() != rNumber.chars()){
            System.out.println("Your input contains too many or too less digits.\nOnly five digit numbers are allowed.");
        }
        else{
        digitExtractor byMath = new digitExtractor(Integer.valueOf(nSequence));
        byMath.returnNumberSequenceByMath();
        System.out.println(" ");
        digitExtractor byChar = new digitExtractor(nSequence);
        byChar.returnNumberSequenceByChar();
        }
    }
}
But it doesn't seem to be working. Any suggestions?

Never mind. I solved my own problem.
If anyone's wondering, I was using chars() when I was supposed to be using length(). (Source of information)

Code:
nSequence.length() != rNumber.length()
"But I'll tell you what hermits realize. If you go off into a far, far forest and get very quiet, you'll come to understand that you're connected with everything." - Alan Watts
Reply


Messages In This Thread
Character ammount - by .righteous - 04-25-2016, 06:32 AM
RE: Character ammount - by brandonio21 - 04-28-2016, 02:13 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)