2016-06-29 81 views
-3

我怎样才能让它变得更短,更好?我怎样才能让它变得更短,更好?

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");} 
+3

___'Java!= JavaScript' ___ – Rayon

+0

你怎么解释它?对不起,我只是一个新手 – Hysteria

+0

使用数组和循环。谷歌是你的朋友。 –

回答

0

您可以使用for-loop和数组来使其更简单。首先声明数组int[] name = new int['how many items you want to enter'];然后用一个for循环,说

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

要访问你把数组名称,然后你想要的项目的索引数组中的项。在Java数组中,从索引0开始,所以第一个元素的索引为0,即name[2]会给你的索引name

+0

先生,我怎么可以,我只想问更多 – Hysteria

0
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 
    } 
} 
+0

先生,我可以如何下午你?任何gmail acc我jsut想问更多 – Hysteria

相关问题