Which of the following patterns should be used for the delimiter to read one character at a time using a Scanner object's next method? Scanner in = new Scanner(. . .); in.useDelimiter("[^0-9]+"); Scanner in = new Scanner(. . .); in.useDelimiter(""); Scanner in = new Scanner(. . .); in.useDelimiter("[^A-Za-z]+"); Scanner in = new Scanner(. . .); in.useDelimiter("[A-Za-z]+");

Respuesta :

Answer:

The method to this question can be defined as follows:

Scanner in = new Scanner(. . .);

in.useDelimiter("");

Explanation:

Following are the code to the question:

import java.util.*;    //import package for user input

public class Main //defining class Main

{    

public static void main(String ax[])//defining the main method

{    

   Scanner in = new Scanner("Database");//crearing Scanner class object that pass value in its parameter  

   in.useDelimiter("");  //using useDelimiter

   System.out.println(in.next()); //use print method to print single character value

}    

}    

Output:

D

Code explanation:

  • In the above code inside the main method scanner class object "in" is created that pass value "Database" in its parameter.  
  • In the next step, useDelimiter is used that uses the scanner class object and single space n its parameter.
  • In the last print, the method is used that prints object value.