TXT

sum3

By Peggy Webb,2014-05-22 21:01
14 views 0
sum3

import javax.swing.JOptionPane;

    public class sum3

     {

     public static void main(String args[])

     {

     String s=JOptionPane.showInputDialog("ÇëÊäÈëÕýÕûÊý:");

     int n = Integer.parseInt(s);

     int sum=0;

     for(int i=1;i<=n; i=i+1){

     sum=sum+i;

     }

     switch(n){

     case 1: JOptionPane.showMessageDialog(

     null, "1= " + sum,

     "Ç?nÏîµÄºÍ",JOptionPane.PLAIN_MESSAGE );

     break;

     case 2: JOptionPane.showMessageDialog(

     null, "1+2= " + sum,

     "Ç?nÏîµÄºÍ",JOptionPane.PLAIN_MESSAGE );

     break;

     case 3: JOptionPane.showMessageDialog(

     null, "1+2+3= " + sum,

     "Ç?nÏîµÄºÍ",JOptionPane.PLAIN_MESSAGE );

     break;

     default: JOptionPane.showMessageDialog(

     null, "1+2+...+"+s+"= "+ sum,

     "Ç?nÏîµÄºÍ",JOptionPane.PLAIN_MESSAGE );

     break;

     }

     System.exit(0);

     }

     }

    ;

Report this document

For any questions or suggestions please email
cust-service@docsford.com