fork download
  1. class Ideone
  2. {
  3. public static void main (String[] args) throws java.lang.Exception
  4. {
  5. int data1 = 5;
  6. double data2 = 100.001;
  7. String data3 = "Hello";
  8. int data4 = 25;
  9. String data5 = "World";
  10.  
  11. StringBuilder sb = new StringBuilder();
  12.  
  13. sb.append(data1);
  14. sb.append(data3);
  15.  
  16. // to go to next line
  17. sb.append("\n");
  18.  
  19. // append can be chained together
  20. sb.append(data2).append(data3).append(data5).append("\n");
  21.  
  22. for(int i=0; i<2; i++)
  23. sb.append(i).append("*2 = ").append(i*2).append("\n");
  24.  
  25. for(int i=2; i<4; i++)
  26. sb.append(i + "^2 = " + i*i + "\n");
  27.  
  28. // print the StringBuffer at the end
  29. System.out.println(sb);
  30. }
  31. }
Success #stdin #stdout 0.05s 4386816KB
stdin
Standard input is empty
stdout
5Hello
100.001HelloWorld
0*2 = 0
1*2 = 2
2^2 = 4
3^2 = 9