Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ch6ex6;
- import java.util.Scanner;
- public class Ch6Ex6
- {
- public static void main(String[] args)
- {
- Scanner sc=new Scanner(System.in);
- System.out.print("Enter a positive integer: ");
- String str=sc.nextLine();
- int sum=0;
- for(int c=0;c<str.length();c++)sum+=((int)integer.charAt(c)-48);
- System.out.println("The sum of the digits is: "+sum);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment