Apps/Gaming

Example of a delimited scanner class in Java

Scanner is an important class for accepting input in Java. In the sample code below we try to demonstrate how to use separators when scanning input. This method can be used in predefined cases where you know the dates and separators that you will get.

* / import java.util.Scanner; public class DelimiterInScanner {public static void main (String[] args) {DelimiterInScanner delimiterInScanner = new DelimiterInScanner (); delimiterInScanner.proceed (); } public void continue () {String deLimiterString = “deLimiter”; String inputString = “1 deLimiter ABC Corp. deLimiter $ 55 deLimiter”; Scanner-Scanner = new scanner (inputString) .useDelimiter (” s *” + deLimiterString + ” s *”); System.out.println (scanner.nextInt ()); System.out.println (scanner.next ()); System.out.println (scanner.next ()); Scanner.close (); }} / *

Here is the output you can expect when you run this code:

[[email protected]]# java DelimiterInScanner 1 ABC Corp. $ 55

Read more tutorials on Java programming.

Related posts

Scrum Best Practices

TechLifely

Quick Tip: How to Update the Last Modified Time in Java

TechLifely

Top 10 Programming Methods

TechLifely

Leave a Comment