How to use StringBurrer and Arrays.toString.

How to use StringBuffer and Arrays.toString.

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

How to use StringBurrer and Arrays.toString.
How to use EventBus3 and ThreadMode
How to use equality and equality (how to use equals)
How to use OrientJS and OrientDB together
How to set up and use kapt
How to use substring and substr methods
How to use @Builder and @NoArgsConstructor together
How to use Map
How to use rbenv
How to use letter_opener_web
How to use with_option
How to use fields_for
How to use java.util.logging
How to use map
How to use collection_select
How to use Twitter4J
How to use active_hash! !!
How to use MapStruct
How to use hidden_field_tag
How to use TreeSet
[How to use label]
How to use identity
How to use hashes
How to use JUnit 5
How to use Dozer.mapper
How to use Gradle
How to use org.immutables
How to use java.util.stream.Collector
How to use VisualVM
How to use Map
[Java] How to use FileReader class and BufferedReader class
[Ruby] How to use gsub method and sub method
How to use Segmented Control and points to note
How to use scope and pass processing (Jakarta)
[Java] How to use Calendar class and Date class
[Java] How to use Map
How to use Chain API
[Java] How to use Map
How to use Priority Queuing
[Rails] How to use enum
How to use java Optional
How to use JUnit (beginner)
How to use Ruby return
[Rails] How to use enum
How to use @Builder (Lombok)
[Swift] How to use UserDefaults
How to use java class
How to use Swift UIScrollView
How to use Big Decimal
[Java] How to use Optional ②
[Java] How to use removeAll ()
How to use String [] args
[Java] How to use string.format
How to use rails join
How to use Java Map
Ruby: How to use cookies
How to use dependent :: destroy
How to use Eclipse Debug_Shell
How to use Apache POI
[Rails] How to use validation
How to use Java variables