TongHieuTichThuong

import javax.swing.JOptionPane;

public class TongHieuTichThuong{

public static void main(String args[]){

String result1, result2;

float output1 = 0, output2 = 0;

float tong = 0, hieu = 0, thuong = 0;

double tich = 0;

result1 = JOptionPane.showInputDialog("Hay nhap so thu 1:");

for (int index = 0; index < result1.length(); index++){

char c = result1.charAt(index);

if (Character.isDigit(c))

output1 = output1 * 10 + Character.digit(c, 10);

}

result2 = JOptionPane.showInputDialog("Hay nhap so thu 2:");

for (int index = 0; index < result1.length(); index++){

char c = result2.charAt(index);

if (Character.isDigit(c))

output2 = output2 * 10 + Character.digit(c, 10);

}

JOptionPane.showMessageDialog(null,"So thu nhat la " + output1 + " va so thu 2 la " + output2);

tong = output1 + output2;

hieu = output1 - output2;

tich = output1 * output2;

JOptionPane.showMessageDialog(null,"Tong 2 so la " + tong);

JOptionPane.showMessageDialog(null,"Hieu 2 so la " + hieu);

JOptionPane.showMessageDialog(null,"Tich 2 so la " + tich);

if (output2 !=0 ){

thuong = output1 / output2;

JOptionPane.showMessageDialog(null,"Thuong 2 so la " + thuong);

}

else return;

System.exit(0);

}

}

Bạn đang đọc truyện trên: AzTruyen.Top