A program that puts numbers in StringBuffer, separates them with commas, adds the numbers and displays them, and outputs the numbers obtained in the process as an array display. (There is no particular meaning)
import java.util.*;
public class Main {
public static void main(String[] args) {
StringBuffer sb = new StringBuffer();
for(int i = 0; i < 10; i++) {
sb.append(i+1).append(",");
}
String s = sb.toString();
String[] a = s.split(",");
int sum = 0;
for(String i : a){
if(Integer.parseInt(i) != a.length) {
System.out.print(i + " + ");
}
else {
System.out.print(i);
}
sum += Integer.parseInt(i);
}
System.out.println(" = " + sum);
System.out.println(Arrays.toString(a));
}
}
Recommended Posts