How to initialize StringBuffer with numbers in Java

1 Answer

0 votes
public class MyClass {
    public static void main(String args[]) { 
        StringBuffer sb = new StringBuffer(); 
        
        for (int i = 0; i < 7; i++) {
            sb.append(i).append(' ');
        }
  
        System.out.println(sb);
    }
}



/*
run:

0 1 2 3 4 5 6  

*/

 



answered Nov 3, 2020 by avibootz

Related questions

2 answers 196 views
196 views asked Nov 3, 2020 by avibootz
1 answer 206 views
1 answer 167 views
1 answer 174 views
1 answer 178 views
...