- 4
Yo find the sum of any number of integers entered as comnand line argument , help of using array.
3 Respostas
+ 4
Please show your attempt
1. use split();
2. Use array
3. Enhanced for loop
+ 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);
}
}
0
Please give me the code