Home > Java > javaTutorial > body text

What is the java input statement?

little bottle
Release: 2020-09-17 10:56:21
Original
22509 people have browsed it

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.

What is the java input statement?

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.*;
Copy after login
  • 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

Give an example:

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);
    }
}
Copy after login

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);
    }
}
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!