Παρασκευή 30 Οκτωβρίου 2009

Ένα πρόγραμμα που χρησιμοποιεί δομή while ... continue ... break

import java.util.*;
import java.io.*;
public class game1{
public static void main (String args[]) throws IOException{
InputStreamReader input=new InputStreamReader(System.in);
BufferedReader line=new BufferedReader(input);
int a,b,c;
int c1;
int sostes=0;
int lathos=0;
String s;
// δημιουργούμε μία επανάληψη και τερματίζεται με χρήση των continue και break;
while(1==1) {
a=(int) Math.round(Math.random()*10);
b=(int) Math.round(Math.random()*10);
System.out.print(a+"+"+b+"=");
s=line.readLine();
c=Integer.parseInt(s);
if(c==a+b) {
System.out.println("Σωστά...."+a+"+"+b+"="+(a+b));
sostes++;}
else {
System.out.println("Λάθος ..... "+a+"+"+b+"="+(a+b));
lathos++;}
System.out.print("Πατήστε 1 για επανάληψη :");
s=line.readLine();
c1=Integer.parseInt(s);
if(c1==1) continue;
break;
}
System.out.println("Σωστές : "+sostes+ " Λάθος :"+lathos);
} //Kleisimo main
}//Kleisimo class

Δεν υπάρχουν σχόλια: