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 295 views
295 views asked Nov 3, 2020 by avibootz
1 answer 297 views
1 answer 253 views
1 answer 279 views
1 answer 288 views
...