Friday, August 16, 2013

Exercise no. 13

 import javax.swing.JOptionPane;


public class Exercise13 {
 
    public static void main(String[]args)
    {
        int s=0,f=0;
        int d=1;

String userstring = JOptionPane.showInputDialog(null,"Enter number");

int userint = Integer.parseInt(userstring);


do{
  
 if(d%2==1)

 {
     s++;
 }

  if(s<=userint)
    
               {
        f+=s;
     
               }
  d=d+1;
}
while(s!=userint);

JOptionPane.showMessageDialog(null,"The sum of first is " + userstring + " and positive odd integer is : " + f);

    }

    }

No comments:

Post a Comment