Hi
I am new to java and i want to learn how to code in java. i have started creating some small programs. I am trying to code a program that takes a integer and returns odd and even values upto that number. I am posting my code please check it out. Thanks in advance.
Code:
public class OddEvenNum
{
public static void main(String[] args)
{
int i;
char choice;
Scanner scn = new Scanner(System.in);
do
{
System.out.println("Welcome to odd and even number checker please enter a number");
i = scn.nextInt();
if(i%2 == 0; i++)
{
System.out.println("Even number is :" + i);
}
else
{
System.out.println("Odd number is :" + i);
}
System.out.println("Would you like to try another number? :");
choice = scn.next() .charAt(0);
}while (choice == 'y' || choice == 'Y');
}
}
Bookmarks