dimanche 25 mars 2018

how to do if not in inputkan data will be error with JOptionPane

Hi I am a beginner in programming, I am having a little trouble when creating a program where if entered the data will appear next input and if not input will appear warning message message.

import javax.swing.*;
public class JoptionInputDialogBisa {
    public static void main (String [] args)
    {
        JOptionPane jop = new JOptionPane ();

        String nama = JOptionPane.showInputDialog(null,"Masukkan Nama : ");
        double tb = Double.parseDouble(JOptionPane.showInputDialog(null,"Masukkan Tinggi Badan : "));
        double bbi = (tb-100)*0.9;
        String cetak = "Dsts User\nNama : "+nama+"\nTinggi Badan :"+tb+" cm\nBerat Badan Ideal : "+bbi+" kg";
        jop.showMessageDialog(null,cetak,"Hasil Berat Badan Ideal",jop.INFORMATION_MESSAGE);
    }

}

Aucun commentaire:

Enregistrer un commentaire