2016-06-29 11 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

配列とループを使用してください。そして、Googleはあなたの友人です。 –

答えて

0

forループと配列を使用すると、はるかに簡単にすることができます。まず、あなたは配列名を入れて、あなたがしたい項目のインデックス配列内のアイテムにアクセスするには

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

を言うforループを使用して、配列int[] name = new int['how many items you want to enter'];を宣言します。 Java配列ではインデックス0で始まるので、最初の要素は0のインデックスにあります。すなわち、name[2]は、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にもアクセスしたい – Hysteria

関連する問題