Advertisement
Guest User

Untitled

a guest
Jul 26th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. import javax.swing.JOptionPane;
  2. public class Exercicio1 {
  3.  
  4.  
  5.  
  6. public static void main(String[] args) {
  7.  
  8.  
  9. //input usuario com int
  10. String numero1=JOptionPane.showInputDialog("Digite o primeiro número : ");
  11.  
  12. //confima se o usuario digitou apenas numeros nas duas etapas , caso nao retornara uma mensagem de erro .
  13. if(numero1.contains("[a-zA-Z]")==false) {
  14. int n1=Integer.parseInt(numero1);
  15. String numero2=JOptionPane.showInputDialog("Digite o segundo número : ");
  16. if(numero2.contains("[a-zA-Z]")==false) {
  17. int n2=Integer.parseInt(numero2);
  18. String msg = String.format("O resultado da soma dos dois números infomados é de %d",(n1+n2));
  19. JOptionPane.showMessageDialog(null, msg);
  20. }else {
  21. JOptionPane.showMessageDialog(null,"Porfavor digite apenas números");
  22. }
  23. }else {
  24. JOptionPane.showMessageDialog(null,"Porfavor digite apenas números");
  25. }
  26. }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement