תרגיל 22: הזוג הכי גדול פתרון בשפת Java:int counte...

תרגיל 22: הזוג הכי גדול פתרון בשפת Java:

int counter=0;
int max=0;

System.out.println("Please enter pair of numbers:");
int x= reader.nextInt(); // or input.nextInt();
int y= reader.nextInt(); // or input.nextInt();


int xMax = 0;
int yMax=0;
while( x%2 == y%2 ) // כל עוד שניהם זוגיים או שניהם אי זוגיים
{

if(counter ==0 || (x+y) > max)
{
xMax = x;
yMax = y;

max = xMax + yMax;
}
counter++;

System.out.println("Please enter pair of numbers:");
x= reader.nextInt(); // or input.nextInt();
y= reader.nextInt(); // or input.nextInt();

}

System.out.println("The number of pairs is "+counter+" and the biggest is "+xMax+" and "+yMax);