Skip to main content

Featured

How to make a simple calculator with GUI in JAVA (using Netbeans)?

First of all create a new package , then create a simple class. Then create a new JFrame Form class. On the right side you will find every tool needed like buttons textfield radio buttons etc. We'll need the buttons and text field and a JLabel Drag and drop required buttons you want to appear on the calculator eg. 1,2,3,4,5,6,7,8,9,0,+,-,*,/,=,AC,OFF arrange them all then on double clicking any button you will enter the source code tab, for digits 0-9 you have to write this code:         String Number =answer.getText() +  one.getText();         answer.setText(Number); Here answer is the jTextFields variable name you can right click the text field and click change variable name. similarly you have to set the code for every digit then for operations you have to write the code: for "+" operation: firstnumber = Double.parseDouble(answer.getText());         jLabel1.setText(answer.getText()+"+"); ...

User is required to input 2 numbers then program will check their equality.

User is required to input 2 numbers then program will check their equality.



In this example we will make a program which will tell if 2 numbers are equal , smaller or greater .
thats all and we are also going to use while loop so that program don't terminate by itself.

Here are Screenshots of my program below.









and heres the code.
Just copy and paste it in the visual studio code input box



#include <iostream>
using namespace std;
int main()
{
	int m;
	int n;

	cout<<"        \n\n  Enter first number : ";
	cin>>m;
	cout<<"        \n\n  Enter second number : ";
	cin>>n;
while(m)
{
while(m==n)
{
	if(m==n)
	{
		cout<<"  \n\n  Both numbers are equal  \n\n";
	}

	cout<<"        \n\n  Enter first number : ";
	cin>>m;
	cout<<"        \n\n  Enter second number : ";
	cin>>n;

}
	while(m!=n)
	{
		if(m>n)
{
	cout<<"        \n\n  First number is greater than second      \n\n  ";
		}
		if(m<n)
		{
			cout<<"        \n\n  Second number is greater than first       \n\n ";
		}


		cout<<"        \n\n  Enter first number : ";
	cin>>m;
	cout<<"        \n\n  Enter second number : ";
	cin>>n;

	}
}
	return 0;
}

Comments