How to input statements in java: 1. Enter a single character [char c=(char)System.in.read()]; 2. Enter an integer or string [int a=cin.nextInt()] ;3. You can use the BufferedReader class for input.
How to input statements in java:
If you want to input, please add two packages
import java.util.*; import java.io.*;
Please see the following example for inputting a single character
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); } }
Enter an integer or character (string)
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); } }
You can also use the BufferedReader class to input
import java.io.*; import java.util.*; public class Main{ public static void main(String[] args)throws IOException{ BufferedReader cin=new BufferedReader(new InputStreamReader(System.in)); String str=cin.readLine();//输入一行 System.out.println(str); String str2=cin.readLine(); int a=Integer.parseInt(str2);//将str2转换为int,并复制给a System.out.println(a); String str3=cin.readLine(); double b=Double.parseDouble(str3);//将str3转换为double,并复制给b System.out.println(b); } }
Related free learning recommendations: java basics
The above is the detailed content of How to enter statements in java. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Mac version
God-level code editing software (SublimeText3)

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Atom editor mac version download
The most popular open source editor