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()+"+"); ...

How to make a program to calculate TABLE of any number ?

Update: Updated while loop code to re ask for number which you want the table for
Today we will make a simple program which will calculate the table of any given number.

I'll use

1- For Loop
2- While Loop

Below are screenshots and C++ code of Table Maker using FOR Loop











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

 int a,b=1,c;
 
 
 cout << endl ;
 cout << " Enter the number for which you want the table ";
 cout << endl;
 cout << endl;
 cout << endl; 
 cin >> a;
 

 cout << endl ;
 for(b;b<=10;b++)
 {

 
 c=a*b;

 cout << left <<setw(35)  ;
 

 cout <<" \n "<<a<<" x "<<b<<" = "<<c<<" ";
 
 cout<<endl;
 
 }
 

return 0;

}


Now if you want to use the WHILE LOOP ,you just have to add a small change, the condition and also the increment
i.e
         b=b+1
Thats all. If you feel lazy just copy the code below. :)

Output display is same for both.



/* This is a table maker using while loop.
It will display tables of numbers of your choice.
*/

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

 int a,b=1,c;
 while(b!=0)
 {
 cout<<endl;
  cout<<" \n Enter the number for which you want table to be made: ";
 
 cin>>a;
 
 while(b<=10)
 {

 
 c=a*b;

 cout << left <<setw(35)  ;
 

 cout <<" \n "<<a<<" x "<<b<<" = "<<c<<" ";
 
 b++;
 cout<<endl;
 
 }
 b=1;
 
 }



return 0;

}

Comments