Write a program that accept three decimals as input and outputs their sum.
Answers
import java.util.Scanner;
class Test
{
public static void main(String[] args)
{
Scanner input=new Scanner(System.in);
System.out.println("Enter 3 digit number:");
int n= input.nextInt();
int sum=0;
while (n != 0)
{
sum = sum + n % 10;
n = n/10;
}
System.out.println("Sum :"+sum);
}
}
Input :Enter 3 digit number:123
Output :Sum :6
If you find my answer helpful then mark me as brainliest! Thank you.
import java.util.*;
public class Sum
{
public static void main(String args[])
{
Scanner in=new Scanner(System.in);
//for taking input decimal numbers we have to accept the values either in float or in double.
//taking the input in float
float m,n,k, sum;
System.out.println("Enter the values");
m= in.nextFloat();
n=in.nextFloat();
k=in.nextFloat();
sum=(m+n+k);
System.out.println("The sum of the decimals is=" +sum);
}
}