Created
September 28, 2011 21:31
-
-
Save matnel/1249317 to your computer and use it in GitHub Desktop.
Esimerkki spagettia sisältävästä koodista.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Esimerkki { | |
public static void main(String[] args){ | |
int valinta = Pop.valitseNappula("Valitse:", "kivi", "paperi", "sakset" ); | |
double vastaus = Math.random(); | |
if (vastaus < 1.0/3.0 ){ | |
vastaus = 0; | |
} else if (vastaus < 2.0 / 3.0){ | |
vastaus = 1; | |
} else { | |
vastaus = 2; | |
} | |
// aloita tarkastelu! | |
if(valinta == 0){ | |
if(vastaus == 0){ | |
Pop.tell("Valitsen kiven. Tasapeli."); | |
} else if (vastaus == 1){ | |
Pop.tell("Valitsen paperin. Voitin."); | |
} else { | |
Pop.tell("Valitsen sakset. Voitit."); | |
} | |
} else if(valinta == 1){ | |
if(vastaus == 0){ | |
Pop.tell("Valitsen kiven. Voitit."); | |
} else if (vastaus == 1){ | |
Pop.tell("Valitsen paperin. Tasapeli."); | |
} else { | |
Pop.tell("Valitsen sakset. Voitin."); | |
} | |
} else { | |
if(vastaus == 0){ | |
Pop.tell("Valitsen kiven. Voitin."); | |
} else if (vastaus == 1){ | |
Pop.tell("Valitsen paperin. Voitit."); | |
} else { | |
Pop.tell("Valitsen sakset. Tasapeli."); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment