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 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 TreeSet
[How to use label]
How to use identity
How to use hashes
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
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)
How to use java class
How to use Big Decimal
[Java] How to use removeAll ()
How to use String [] args
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
[Rails] How to use authenticate_user!
How to use GC Viewer
How to use Lombok now
[Creating] How to use JUnit
[Rails] How to use Scope
How to use and apply Java's JFrame / Canvas class
How to use the link_to method
[Rails] How to use gem "devise"