import java.io.DataInputStream;
class Calculate
{
                int c=0,a;
                void getData(int x)
                {
                                a=x;
                }
                int outData()
                {
                                for(int j=1;j<=a;j++)
                                                c+=j;
                                return c;
                }
}
class Sum
{
                public static void main(String args[])
                {
                                DataInputStream in=new DataInputStream(System.in);
                                int n,s=0;
                                try
                                {
                                                System.out.print("Enter A Number : ");
                                                n=Integer.parseInt(in.readLine());
                                                Calculate cal=new Calculate();
                                                cal.getData(n);
                                                s=cal.outData();
                                }
                                catch(Exception e) {}
                                System.out.println("Sum = "+s);
                }
}

JAVA 15.PNG

Advertisements