Guest User

Untitled

a guest
Jan 22nd, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. import javax.swing.JOptionPane;
  2.  
  3.  
  4. public class SumNint {
  5. {public static void main (String [] args);
  6.  
  7. //sommare i primi n numeri interi a partire dal numero uno
  8. String num = JOptionPane.showInputDialog("Quanti sono i numeri?");
  9. int conta = 1;
  10. int somma = 0;
  11. int valore1 = Integer.parseInt(num);
  12.  
  13. {if (valore1 < conta + 1 )
  14. {
  15. somma = somma + conta;
  16. conta = conta + 1;
  17.  
  18.  
  19.  
  20.  
  21. }
  22. else
  23. JOptionPane.showConfirmDialog(null, somma);
  24. }
  25.  
  26. }}
Add Comment
Please, Sign In to add comment