Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 我怎样才能使它更短更好?_Java_Arrays - Fatal编程技术网

Java 我怎样才能使它更短更好?

Java 我怎样才能使它更短更好?,java,arrays,Java,Arrays,我怎样才能使它更短更好 import java.util.Scanner; public class letter { public static void main(String args[]){ Scanner input = new Scanner(System.in); String 1 , 2 ,3 ,4 ,5 ,6 ,7 and so forth; System.out.print("Enter the number:

我怎样才能使它更短更好

import java.util.Scanner;

  public class letter {
     public static void main(String args[]){
        Scanner input = new Scanner(System.in);
        String 1 , 2 ,3 ,4 ,5 ,6 ,7 and so forth;
        System.out.print("Enter the number: \t");
        1 = input.nextInt();
        2 = input.nextInt();
        3 = input.nextInt();
        ...and so forth.

        if (1 == A){System.out.println("Your name is anything");}

您可以使用for循环和数组使其更加简单。首先声明数组int[]name=newint['要输入多少项'];然后使用一个for循环

for(int i = 0; i<name.length; i++){
name[i]=input.nextInt();
}

要访问数组中的项,请输入数组名,然后输入所需项的索引。在java数组中,从索引0开始,因此第一个元素的索引为0,即名称[2]将为您提供名称的索引2的内容。

java!=Javascript你怎么解释呢?对不起,我是新手,使用数组和循环。谷歌是你的朋友。这个程序应该做什么?这似乎不是一个语法正确的程序。先生,我怎么能pm你我只是想问更多先生,我怎么能pm你?任何gmail acc我都想问更多
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

  public static void main(String[] args) throws Exception {
  Step 1:  BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); //More suitable to read data than Scanner Class
    String input = reader.readLine(); //Use appropriate "reading" method for eg. readLine() for reading String

 Step 2 : Iterate according to your need and read data


  Step 3 :   reader.close(); //Close the BufferReader
  }
}