blikk info infothek forum galerie sitemap

Überschrift

zur Aufgabenstellung

import java.io.BufferedReader;

import java.io.IOException;

import java.io.InputStreamReader;

 

public class Wuerfel_2 {

 

            public static void main(String[] args) {

                        boolean again = false;

                        BufferedReader eingabe = new BufferedReader (new

                        InputStreamReader(System.in));

                        do{

                        int summe1 = 0;

                        for(int i=0; i<3; i++){

                         int zahl = (int)(Math.random()*6)+1;              

                         int zahl2 = (int)(Math.random()*6)+1;

                       

System.out.println("Beim " + (i + 1) + ". Mal hat der Computer  " + zahl +" und " +zahl2 + " gewürfelt.");

         summe1 = summe1 + zahl2 + zahl;

                        }

System.out.println("Der Computer hat insgesamt " + summe1 + " gewürfelt");

                       

                        int summe2 = 0;

                        for(int i=0; i<3; i++){

                        int zahl = (int)(Math.random()*6)+1;              

                        int zahl2 = (int)(Math.random()*6)+1;

                       

System.out.println("Beim " + (i + 1) + ". Mal hast du  " + zahl +" und " +zahl2 + " gewürfelt.");

         summe2 = summe2+ zahl2 + zahl;

                        }

                        System.out.println("Du hast insgesamt " + summe2 + " gewürfelt");

                       

                       

                        if (summe1 > summe2) {

                                   System.out.println("Der Computer hat gewonnen!");

        } else if (summe2 > summe1) {

            System.out.println("Sie haben gewonnen!");  

        }else {

            System.out.println("Unentschieden!");

        }

                       

                        try{

System.out.println("Wollen Sie den Vorgang wiederholen?n ja=j nein=n");

                        String weiter = (eingabe.readLine());

                        if (weiter.compareTo("j") == 0){

                                   again =true;

                        }

                        else {

                                   again= false;

                        }

                        }catch (IOException z){

                                   System.out.println ("ERROR!");

                        }

                       

                        }while (again==true);

            }

 

}

Vitrugno Elian

nach oben