Advertisement
Guest User

Untitled

a guest
Sep 28th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.06 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. /**
  4.  *
  5.  * @author Mattis
  6.  */
  7. public class Nopat {
  8.     public static void main(String[] args){
  9.         boolean jatka = true;
  10.         Scanner sc = new Scanner(System.in);
  11.        
  12.         heitaNoppaa();
  13.         while(jatka){
  14.             System.out.print("Heitetänkö uudelleen (k/e)? ");
  15.             String vastaus = sc.nextLine();
  16.             if(vastaus.equals("e")){
  17.                 jatka=!jatka;
  18.             }
  19.             else if(vastaus.equals("k")){
  20.                 heitaNoppaa();
  21.             }
  22.             else{
  23.                 System.out.println("Anna vastaus muodossa (k/e).");
  24.             }
  25.         }
  26.  
  27.     }
  28.    
  29.     public static void heitaNoppaa(){
  30.         int nopanHeitto = (int)(Math.random()*6)+1;
  31.  
  32.         for(int i=0; i<6; i++){
  33.             System.out.print(nopanHeitto);
  34.             nopanHeitto = (int)(Math.random()*6)+1;
  35.             if(i<5){
  36.                 System.out.print(", ");
  37.             }
  38.             else if(i==5){
  39.                 System.out.println("");
  40.             }
  41.         }
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement