Spiga

Java Programming | Determine if the Number is ODD or EVEN

This Java Program code is a program that list all ODD numbers between the two numbers you input. You must have Java 1.5 version to run this program. Insert this code into your text editor:

import java.util.*;

public class OddNumers {
public static void main(String[] args) {

Scanner reader = new Scanner(System.in);

int input , input2;

System.out.print(”Enter 1st number: “);
input = reader.nextInt();

System.out.print(”Enter 2nd Number: “);
input2 = reader.nextInt();

System.out.println(”The Odd numbers between” +input+ ” ” + input2 + ” are: ” );

while (input<=input2) {
if (input%2 != 0) {
System.out.print(input);
}
input++;
}

}
}

Output:

Enter 1st number: 1
Enter 2nd number: 10
The Odd numbers between 1 and 10 are: 3579

Just change the code if you want to display the Even numbers either.

Thanks!!!

0 comments: