Answers for "java sum of number"

1

sum of two numbers in java

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);

        System.out.print("Enter two numbers: ");
        int num1 = scanner.nextInt() , num2 = scanner.nextInt();

        int sum = num1 + num2 ;
        System.out.printf("The sum of %d and %d is %d",num1, num2, sum);
    }
}
Posted by: Guest on June-23-2021
1

sum of digits in java

import java.io.*;
public class sd
{
  public static void main(String [] args)throws IOException
  {
     InputStreamReader hi = new InputStreamReader(System.in);
        BufferedReader in = new BufferedReader(hi);
        System.out.println("Enter the number");
        int num=Integer.parseInt(in.readLine());
    int sum=0;
    while(num>=0)
    {
      int rem=n;
      sum+=rem;
      int quo=n/10;
      n=quo;
    }
    System.out.println(sum);
  }
}
Posted by: Guest on November-06-2020

Code answers related to "java sum of number"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language