Click here to Skip to main content
15,896,118 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Java
 import java.util.Scanner;

public class Addingdigit {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		System.out.println("print the number");
		int m = sc.nextInt();
		// System.out.println("print the floating point number");
		// float f = sc.nextFloat();
		// int data =1546789;
		int add = 0;
		// float fadd =0.0f;
		while (m != 0) {
			add = add + m % 10;
			m = m / 10;

			/*
			 * fadd = fadd + f%10; f=f/10;
			 * 
			 */
		}

		// int length=String.valueOf(1546789).length();

		System.out.println(add);
		// System.out.println(fadd);
	}
}


What I have tried:

I have done this with int number but i'm not getting any logic to do the same with floating point number.
Posted
Comments
Peter_in_2780 10-May-16 1:47am    
This makes no sense. What format are you going to put your floating point number in? How many digits precision?
Patrice T 10-May-16 5:54am    
Got an example ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900