Yo find the sum of any number of integers entered as comnand line argument , help of using array. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 4

Yo find the sum of any number of integers entered as comnand line argument , help of using array.

4th Mar 2019, 1:28 PM
Rabi Sil
Rabi Sil - avatar
3 Answers
+ 4
Please show your attempt 1. use split(); 2. Use array 3. Enhanced for loop
4th Mar 2019, 2:00 PM
Muhd Khairul Amirin
Muhd Khairul Amirin - avatar
+ 1
import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String[] a = new String(sc.nextLine()).split(" "); int sum = 0; for(String x : a){ sum += Integer.valueOf(x); } System.out.print(sum); } }
5th Mar 2019, 1:09 AM
M_N
0
Please give me the code
4th Mar 2019, 3:12 PM
Rabi Sil
Rabi Sil - avatar