TXT

sum

By Leon Bennett,2014-05-22 21:01
15 views 0
sum

import javax.swing.JOptionPane;

    public class sum2

     {

     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)

     {

     int a=0;

     a=i*2;

     sum=sum+a;

     }

     int b=2*n;

     switch(n) {

     case 1: JOptionPane.showMessageDialog(

     null, "2= " + sum,

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

     break;

     case 2: JOptionPane.showMessageDialog(

     null, "2+4= " + sum,

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

     break;

     case 3: JOptionPane.showMessageDialog(

     null, "2+4+6= " + sum,

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

     break;

     default: JOptionPane.showMessageDialog(

     null, "2+4+...+"+b+"= "+ sum,

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

     break;

     }

     System.exit(0);

     }

    }

Report this document

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