2017-06-20 8 views
0

私のプログラムでは、文字列の配列を作成する必要があります。この配列を使用すると、スキャナを使用して、コンソール内でテキストを100文字まで入力できます。私は、ユーザーが「stop」という単語を入力すると、入力されたすべての文字列(< = 100)を表示できるようにプログラムが必要です。スキャナを使用した文字列配列

誰もが私のためにプログラム全体を書いてくれるとは思っていませんが、ちょっとしたヒントかもしれません。

私はこれがかなり基本的だと確信していますが、私は非常にJavaに新しいので、私はこのモジュールを失敗することはできません、どんな助けも大いに感謝します!

package assignment2017; 

import java.util.Scanner; 

public class FootballResultsGenerator { 

    public static void main(String[] args) { 



     String m = (" : "); 
     String promptA = ("Goals scored by: "); 
     String resultA = ("Results: "); 
     String awayTeamGoals = ("the away teams scored: "); 
     String homeTeamGoals = ("the home teams scored: "); 
     String totalGoals = ("Total number of goals: "); 

       int numberOfGames=0; 

       String lineSplit = ("-------------------------------------------"); 
     //These are my teams. 

     //home 
     String ah = ("Tottenham Hotspur(Home)"); 
     String gh = ("Sunderland(Home)"); 
     String ch = ("Manchester City(Home)"); 
     String ih = ("Everton(Home)"); 
     String eh = ("Liverpool(Home)"); 
     String bh = ("Arsenal(Home)"); 
     String dh = ("Manchester United(Home)"); 
     String fh = ("Chelsea(Home)"); 
     String hh = ("West Bromwich(Home)"); 
     String jh = ("Stoke city(Home)"); 
     //away 
     String ba = ("Arsenal(Away)"); 
     String da = ("Manchester United(Away)"); 
     String fa = ("Chelsea(Away)"); 
     String ha = ("West Bromwich(Away)"); 
     String ja = ("Stoke city(Away)"); 
     String aa = ("Tottenham Hotspur(Away)"); 
     String ga = ("Sunderland(Away)"); 
     String ca = ("Manchester City(Away)"); 
     String ia = ("Everton(Away)"); 
     String ea = ("Liverpool(Away)"); 

     System.out.println("Football results generator"); 

     System.out.println(lineSplit); 

     //Tottenham 
     System.out.println (ah + " vs " + ba); 
     System.out.println(lineSplit); 
     numberOfGames++; 
     System.out.println(" -" + promptA + ah); 
     //scanner 
     Scanner scan = new Scanner(System.in); 
     int inputAH = scan.nextInt(); 


     //Arsenal 
     System.out.println(" -" + promptA + ba); 
     int inputBA = scan.nextInt(); 

     System.out.println(); 
     System.out.println (ch + " vs " + da); 
     System.out.println(lineSplit); 
     numberOfGames++; 
     //Man city 
     System.out.println(" -" + promptA + ch); 
     int inputCH = scan.nextInt(); 

     //Liverpool 
     System.out.println(" -" + promptA + da); 
     int inputDA = scan.nextInt(); 

     System.out.println(); 
     System.out.println (eh + " vs " + fa); 
     System.out.println(lineSplit); 
     numberOfGames++; 
     //chelsea 

     System.out.println(" -" + promptA + eh); 
     int inputEH = scan.nextInt(); 

     //sunderland 

     System.out.println(" -" + promptA + fa); 
     int inputFA = scan.nextInt(); 

     System.out.println(); 
     System.out.println (gh + " vs " + ha); 
     System.out.println(lineSplit); 
     numberOfGames++; 
     //West brom 

     System.out.println(" -" + promptA + gh); 
     int inputGH = scan.nextInt(); 

     //Everton 

     System.out.println(" -" + promptA + ha); 
     int inputHA = scan.nextInt(); 

     System.out.println(); 
     System.out.println (ih + " vs " + ja); 
     System.out.println(lineSplit); 
     numberOfGames++; 
     //Stoke 

     System.out.println(" -" + promptA + ih); 
     int inputIH = scan.nextInt(); 

     // 

     System.out.println(" -" + promptA + ja); 
     int inputJA = scan.nextInt(); 

     ////////////////////////////////////////////////////// second set of games 
     System.out.println (aa + " vs " + bh); 
     System.out.println(lineSplit); 
     numberOfGames++; 

     System.out.println(" -" + promptA + aa); 
     int inputAA = scan.nextInt(); 

     System.out.println(" -" + promptA + bh); 
     int inputBH = scan.nextInt(); 

     System.out.println (ca + " vs " + dh); 
     System.out.println(lineSplit); 
     numberOfGames++; 

     System.out.println(" -" + promptA + ca); 
     int inputCA = scan.nextInt(); 

     System.out.println(" -" + promptA + dh); 
     int inputDH = scan.nextInt(); 

     System.out.println (ea + " vs " + hh); 
     System.out.println(lineSplit); 
     numberOfGames++; 

     System.out.println(" -" + promptA + ea); 
     int inputEA = scan.nextInt(); 

     System.out.println(" -" + promptA + hh); 
     int inputHH = scan.nextInt(); 

     System.out.println (jh + " vs " + ga); 
     System.out.println(lineSplit); 
     numberOfGames++; 

     System.out.println(" -" + promptA + jh); 
     int inputJH = scan.nextInt(); 

     System.out.println(" -" + promptA + ga); 
     int inputGA = scan.nextInt(); 

     System.out.println (ia + " vs " + fh); 
     System.out.println(lineSplit); 
     numberOfGames++; 

     System.out.println(" -" + promptA + ia); 
     int inputIA = scan.nextInt(); 

     System.out.println(" -" + promptA + fh); 
     int inputFH = scan.nextInt(); 

     //Goals scored in total 

     int goalint = (inputAH + inputCH + inputEH + inputGH +inputIH + inputBA + inputDA + inputFA + inputHA +inputJA); 

     //Full results array 
     System.out.println(); 
     System.out.println(); 
     System.out.println(lineSplit); 
     System.out.println(resultA); 
     System.out.println(lineSplit); 
     System.out.println(); 
     //first Set Of Games 
     System.out.println(ah + m + ba + m + inputAH + m +inputBA); 
     System.out.println(ch + m + da + m + inputCH + m + inputDA); 
     System.out.println(eh + m + fa + m + inputEH + m + inputFA); 
     System.out.println(gh + m + ha + m + inputGH + m + inputHA); 
     System.out.println(ih + m + ja + m + inputIH + m + inputJA); 
     //second set of games 
     System.out.println(bh + m + aa + m + inputBH + m + inputAA); 
     System.out.println(dh + m + ca + m + inputDH + m + inputCA); 
     System.out.println(hh + m + ea + m + inputHH + m + inputEA); 
     System.out.println(jh + m + ga + m + inputJH + m + inputGA); 
     System.out.println(fh + m + ia + m + inputFH + m + inputIA); 

     System.out.println(); 
     // Goals scored... 
     System.out.println(lineSplit); 
     System.out.println(totalGoals + goalint); 
     System.out.println(homeTeamGoals + (inputAH + inputCH + inputEH + inputGH +inputIH) + " goals."); 
     System.out.println(awayTeamGoals + (inputBA + inputDA + inputFA + inputHA +inputJA) + " goals."); 
     // total number of matches 
     System.out.println("Number of games: " +numberOfGames); 

     //stop 
     String username = ("stop"); 
     String userName = ("Stop"); 

     System.exit(0); 

    }} 
+0

あなたはすでに私たちに見せることを試みましたか? –

+0

今まで何を試してみましたか – Akshay

+4

[宿題の助けを求める質問には、これまで問題を解決するために行った作業の要約と、あなたがそれを解決するのが難しい](https://stackoverflow.com/help/on-topic)。 – RealSkeptic

答えて

3

私はこれが役立つことを望みます。

String[] array = new String[100]; 
String str = null; 
Scanner sc = new Scanner(System.in); 
for (int i = 0; i < 100; i++) {  
    str= sc.nextLine(); 
    if(str.equals("stop")) { 
     break; 
    } 
    array[i] = str; 
} 
+0

これは実際に非常に役に立ちます!以前の配列の入力が表示されているときに「停止」とタイプすると、そのようにすることはできますか?本当にありがとう! – JHurst

+0

@JHurstあなたは誰でもスプーンを食べることは期待できません! [これを読む](https://www.mkyong.com/java/java-how-to-print-an-array/) – codeRock

関連する問題