java常用输入

很多知识来自:

https://blog.csdn.net/sinat_32561655/article/details/62892427

https://blog.csdn.net/wk51920/article/details/51998968

做题卡在输入hin蓝瘦了,总结了几种可能的输入。

1. 一串数字

import java.util.Scanner;
import java.util.Arrays;
public class Main {
	public static void main(String[] args)
	{
		Integer[] a;
		Scanner sc = new Scanner(System.in);
		System.out.print("please input an integer: ");
		int k = sc.nextInt();
		a = new Integer[k];
		System.out.print("please input integers: ");
		while(sc.hasNext())
		{
			for (int m = 0;m

2. 字符串 next

import java.util.Scanner;
import java.util.Arrays;
​public class Main {
	public static void main(String[] args)
	{
		String[] a;
		Scanner sc = new Scanner(System.in);
		System.out.print("please input an integer: ");
		int k = sc.nextInt();
		a = new String[k];
		System.out.print("please input integers: ");
		while(sc.hasNext())
		{
			for (int m = 0;m

3. 字符串 nextLine

import java.util.Scanner;
import java.util.Arrays;
​​public class Main {
	public static void main(String[] args)
	{
		String[] a;
		Scanner sc = new Scanner(System.in);
		System.out.print("please input an integer: ");
		int k = sc.nextInt();
		a = new String[k];
		System.out.print("please input integers: ");
		while(sc.hasNext())
		{
            String s = sc.nextLine(); // nextLine读取回车
			for (int m = 0;m

4. 二维数组

import java.util.Scanner;
public class Main{
    public static void main(String[] args)
	{
		String[][] a;
		Scanner sc = new Scanner(System.in);
		System.out.print("please input an integer: ");
		int k = sc.nextInt();
		a = new String[k][2];
		System.out.print("please input strings: ");
		String s = sc.nextLine();
		for (int m = 0;m

小白阶段,希望大家多多批评指正,我会改哒~

(待续)

你可能感兴趣的:(java,输入)