KeeganT

Ch6Ex6

Feb 20th, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.41 KB | None | 0 0
  1. package ch6ex6;
  2. import java.util.Scanner;
  3.  
  4. public class Ch6Ex6
  5. {
  6.     public static void main(String[] args)
  7.     {
  8.         Scanner sc=new Scanner(System.in);
  9.         System.out.print("Enter a positive integer: ");
  10.         String str=sc.nextLine();
  11.         int sum=0;
  12.         for(int c=0;c<str.length();c++)sum+=((int)integer.charAt(c)-48);
  13.         System.out.println("The sum of the digits is: "+sum);
  14.     }
  15. }
Advertisement
Add Comment
Please, Sign In to add comment