Java has many statements, among which input statements are one of the most basic operations. Below I will take you through how to write input code.
First of all, before you perform the input operation, you must add the following two packages to the package queue of the Java program.
First import java.io.*; and java.util.*; into the Java code.
import java.util.*; import java.io.*;
char c=(char)System.in.read();
is to enter a single character;
int a=cin.nextInt();
is to enter an integer;
##double b=cin.nextDouble();is to enter an Double-precision floating point number
import java.io.*; import java.util.*; public class Main{ public static void main(String[] args)throws IOException{ char c=(char)System.in.read();//输入单个字符 System.out.println(c); } }Give another example:
import java.io.*; import java.util.*; public class Main{ public static void main(String[] args)throws IOException{ Scanner cin=new Scanner(System.in); int a=cin.nextInt();//输入一个整数 System.out.println(a); double b=cin.nextDouble();//输入一个双精度的浮点数 System.out.println(b); String str=cin.next();//输入一个单词,遇到分号则输入终止 System.out.println(str); String str2=cin.nextLine();//输入一行,中间可有多个空格 System.out.println(str2); } }
The above is the detailed content of What is the java input statement?. For more information, please follow other related articles on the PHP Chinese website!