//Addition
//Mag a-add ng dalawang integer from user's input
import javax.swing.JOptionPane;
//una, import muna ang gagamitin para sa JOptionPane
public class PangalanNgProject {
//Kelangan sakto sa filename kapag sinave na may .java extension
public static void main (String []args){
String number1,number2;
int unangNum,pangalawangNum,sum;
//magdeclare ng string at int na madali nyo maintindihan
number1=JOptionPane.showInputDialog("Unang number:");
//string for number1 "Unang number"
unangNum=Integer.parseInt(number1);
//convert string(number1) to integer(unangNum)
number2=JOptionPane.showInputDialog("Pangalawang number");
//string for number2 "Pangalawang number"
pangalawangNum=Integer.parseInt(number2);
//convert string(number2) to integer(pangalawangNum)
sum=unangNum+pangalawangNum;
//alam nyo na naman siguro mag add:)
JOptionPane.showMessageDialog(null,"Ang sagot ay:"+sum);
//bakit may keyword null? click mo ito!
}
}
Kapag subtract, multiplication or division palitan lang ng operation. O pwede din pag sama samahin nyo na lahat. At lagyan ng mga condition kung kailangan.
More examples by request, basta kaya gawin ni author:)
More lessons to come.
If you have more something to add ikakagalak ko po.
SHARE and LEARN!
No comments:
Post a Comment