-3

I want to make a user to enter integers separated with dot like (11.56.98) to use after that x=11 y=56 z=98

    `Scanner s = new Scanner(System.in);
    System.out.print("Enter Your number like (36.52.10): ");
    int x = s.nextInt();
    int y = s.nextInt();
    int z = s.nextInt();`

now how to usedelimiter will change whitespace to dot and how to return to whitespace again

Samer Essam
  • 25
  • 1
  • 5
  • Take value in String and then divide the value as per ur requirement – Kick Sep 15 '17 at 12:23
  • could you please clarify what you want to do? Your last sentence is very hard to read and (at least for me) impossible to understand. – Mischa Sep 15 '17 at 12:24
  • just use `string.split()` https://docs.oracle.com/javase/7/docs/api/java/lang/String.html#split(java.lang.String) – Achilles Sep 15 '17 at 12:25
  • [How do I use a dot as a delimiter?](https://stackoverflow.com/questions/31369131/how-do-i-use-a-dot-as-a-delimiter) [How do I use a delimiter in Java Scanner?](https://stackoverflow.com/questions/28766377/how-do-i-use-a-delimiter-in-java-scanner) – Bernhard Barker Sep 15 '17 at 12:32
  • *"how to return to whitespace again"* ... you call `useDelimiter(...)` again! – Stephen C Sep 15 '17 at 12:48

1 Answers1

1

If you want it in the same line use: s.next().

If you want the text in the next line you need to do: s.nextLine()

Whatever method you use it will return a java.lang.String.

You can use String[] numbers = yourString.split(".")

The array what you get if you split the string you can get all numbers:

int x = Integer.valueOf(numbers[0]);
int y = Integer.valueOf(numbers[1]);
int z = Integer.valueOf(numbers[2]); 
//Dont forget it can throw a NumberFormatException if the current String is not a valid number.
CodeMatrix
  • 2,080
  • 1
  • 15
  • 26