sum of output | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

sum of output

Hey How can we sum numbers in the output of code below. Thanks import java.util.Scanner; public class IDCode{ public static void main(String[] args){ Scanner input = new Scanner(System.in); System.out.println("Enter ID Code:"); int x = input.nextInt(); String s = Integer.toString(x); System.out.println(s.length()==10?true:false); int b = 0; int c = 10; int sum = 0; for(int i = 0; i < s.length();i++){ b = Integer.parseInt(""+s.charAt(i))*c; System.out.println(b); --c; } } }

9th Mar 2019, 8:09 AM
Amir
Amir - avatar
1 Answer
+ 2
sum += b; At the end of the loop.
9th Mar 2019, 11:19 AM
M_N