|
import javax.swing.JOptionPane; import java.util.Random; public class Oef1 {
public static void main(String[] args) { Random r = new Random( ); int getal = r.nextInt(10); int a=0, gok=100; while(gok !=getal){ String g= JOptionPane.showInputDialog("gok het getal "); gok=Integer.parseInt(g); if (gok<getal) JOptionPane.showMessageDialog(null,"hoger"); if (gok>getal) JOptionPane.showMessageDialog(null,"lager"); a++;} JOptionPane.showMessageDialog(null,"Je hebt het juiste getal geraden, het getal was "+getal+", je had hiervoor "+a+" pogingen nodig");}}
|