Computer Science, asked by prasadshruti232, 5 months ago

write a program that will generate all the even number between x and y.get the values of x and y as inputs.x<y plz fast ans its urgent​

Answers

Answered by Oreki
1

import java.util.Scanner;

public class EvenInRange {

static void print(int x, int y) {

System.out.printf("%nEven numbers between %d and %d are - ", x, y);

for (int i = x + 1; i < y; i++)

if (i % 2 = = 0)

System.out.print(i + " ");

}

public static void main(String[ ] args) {

Scanner sc = new Scanner(System.in);

System.out.println("Enter x and y - ");

int x = sc.nextInt( ), y = sc.nextInt( );

if (x < y) print(x, y);

else if (x > y)print(y, x);

else System.out.println("Invalid Input, x can't be equal to y!");

}

}

Answered by anindyaadhikari13
2

Question:-

Write a program that will generate all the even number between x and y. Get the values of x and y as inputs. (x<y)

Code:-

import java.util.*;

class Even

{

public static void main(int x, int y)

{

System.out.println("The even numbers are...");

for(int i=x+1;i<y;i++)

{

if(i%2==0)

System.out.print(i+" ");

}

}// end of main

}// end of class

Similar questions