1import java.util.Scanner;
2public class SumDigit {
3 public static void main(String[] argh){
4 System.out.println("Enter int");
5 Scanner input = new Scanner(System.in);
6 int n = input.nextInt();
7 int sum = 0 ;
8 int i = 0;
9 print( i =Sum_of_digits(sum,n));
10 }
11
12 public static int Sum_of_digits(int sum,int n){
13 if(n<=0)
14 return sum ;
15 sum += n%10;
16 return Sum_of_digits(sum,n/10);
17 }
18
19 public static void print(int n){
20 System.out.print(n);
21 }
22}
1import java.io.*;
2public class sd
3{
4 public static void main(String [] args)throws IOException
5 {
6 InputStreamReader hi = new InputStreamReader(System.in);
7 BufferedReader in = new BufferedReader(hi);
8 System.out.println("Enter the number");
9 int num=Integer.parseInt(in.readLine());
10 int sum=0;
11 while(num>=0)
12 {
13 int rem=n;
14 sum+=rem;
15 int quo=n/10;
16 n=quo;
17 }
18 System.out.println(sum);
19 }
20}
1import java.util.Scanner;
2
3public class Main {
4
5 public static void main(String[] args) {
6
7 Scanner scanner = new Scanner(System.in);
8
9 System.out.print("Enter two numbers: ");
10 int num1 = scanner.nextInt() , num2 = scanner.nextInt();
11
12 int sum = num1 + num2 ;
13 System.out.printf("The sum of %d and %d is %d",num1, num2, sum);
14 }
15}
1static void M1(int num1, int num2) {
2 int sum = num1 + num2;
3 System.out.println("sum of " + num1 + " and " + num2+ " = " + sum);
4 }
5
6 public static void main(String[] args) {
7 // using Methods
8 Scanner input = new Scanner(System.in);
9 int num1,num2;
10 System.out.println("Enter a number: ");
11 num1 =input.nextInt();
12 System.out.println("Enter 2nd number: ");
13 num2 =input.nextInt();
14 input.close();
15 M1(num1, num2);
16 }
17}
1public class SumNatural {
2
3 public static void main(String[] args) {
4
5 int num = 100, sum = 0;
6
7 for(int i = 1; i <= num; ++i)
8 {
9 // sum = sum + i;
10 sum += i;
11 }
12
13 System.out.println("Sum = " + sum);
14 }
15}