Difference between println() and print()
Different ways to print output in java
Way 1: println()
Below is the way to print elements of array on separate line
1 2 3 4 5 6 7 8 9 10 11 12 |
import java.util.*; public class Main { public static void main(String[] args) { String[] str1={"welcome","to","webencyclop"}; for(int i=0;i<str1.length;i++) { System.out.println(str1[i]); } } } |
Output:
1 2 3 |
welcome to webencyclop |
Way 2: print()
Below is the way to print elements of array in one line
1 2 3 4 5 6 7 8 9 10 11 12 |
import java.util.*; public class Main { public static void main(String[] args) { String[] str1={"welcome","to","webencyclop"}; for(int i=0;i<str1.length;i++) { System.out.print(str1[i] + " "); } } } |
Output:
1 |
welcome to webencyclop |