When writing a program in Eclipse, we can use the scanner class if our variables are required to be entered manually.
The scanner class, which is a new utility for scanning input text. Because any data must be retrieved through a capturing group of the same pattern or by using a draw to retrieve parts of the text. You can then use a combination of regular expressions and methods to retrieve specific types of data items from the input stream. In this way, in addition to the ability to use regular expressions, the scanner class can optionally parse data for strings and basic types such as int and double. With scanner, you can write a custom parser for any text content you want to work with.
Note: Be sure to import java.util.Scanner under the package at the beginning of eclipse, otherwise Scanner cannot be called.
Gca
Package com.lovo.homework;
Enter a, then sequentially save A to Z data into an array, and traverse the
Print A to Z lowercase characters.
Import Java.util.Scanner;
public class Homework2016_11_17_1 {
public static void Main (string[] args) {
Scanner scn=new Scanner (system.in);
System.out.println ("Please enter string A:");
String M=scn.nextline ();//input string
String y=m.tolowercase ();
Char Chr=y.tochararray () [0];//converts a string to a character
for (int i = 0; i <; i++) {
System.out.println ("chr[" +i+ "]=" +CHR);
chr++;
}
}
}
In addition to the string, the other types can be entered, we just need to change the string m=scn.nextline () to int can enter an integer, the other is the same.
The use of the scanner class in Java