1.

Write a program to enter a number and display the addition of all numbers from 1 to the given number

Answer»

import java.io.*;

class NUM

{BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

int n, SUM=0;

public VOID accept()throws IOException

{System.out.println("Enter a NUMBER");

n=Integer.parseInt(br.readLine());

}

public void calc()

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

{ sum=sum+d;

}

System.out.println(" The sum of numbers ="+sum);

}

}



Discussion

No Comment Found