Design Java Netbeans 6.5.1 GUI application to find out that entered number is EVEN or ODD.

Q7. Design Java Netbeans 6.5.1 GUI application to find out that entered number is EVEN or ODD.

Sol:

Create a GUI application as per following screenshot.

Type the following code by double clicking BtnFind, button, below the line that says, ‘// TODO add your handling code here’

int num;

num=Integer.parseInt(txt1.getText());

if(num%2==0)

lblmsg.setText(“Number is EVEN.”); Read More …

Write a C++ program to accept a number and determine whether it is even or odd.

Q19. Write a C++ program to accept a number and determine whether it is even or odd.

Solution:

#include<iostream.h> //standard input/output header file

#include<conio.h> //for clrscr()

 

int main()

{

int a;

 

clrscr(); //for clearing the screen

 

cout<<“\n Enter a number: “;

cin>>a;

 

a%2==0? cout<<“\n It is an even number.” : cout<<“\n It is an odd number.”;

 

getch(); //holds the screen until any key is pressed

return 0; //makes main() finish

}

 

OUTPUT:

CASE 1:

Enter a number: 7

 

It is an odd number.

 

CASE 2:

Enter a number: 6

 

It is an even number.