Make em code short because I can.

This commit is contained in:
Siwat Sirichai 2020-10-22 16:37:18 +07:00
parent 1422069e8e
commit f4b576029a
2 changed files with 1 additions and 5 deletions

View File

@ -16,11 +16,7 @@ public class Replace {
return; //If a is a null pointer, return immediately to prevent a NullPointerException return; //If a is a null pointer, return immediately to prevent a NullPointerException
} }
//NOTE: return; (a return statement without a return value) in a method with no return type will break out of the method. //NOTE: return; (a return statement without a return value) in a method with no return type will break out of the method.
for(int i = 0;i<a.length;i++) { //loop from 0 to the length of array a, number of completed iteration is stored in i (type int) for(int i = 0;i<a.length;i++)System.out.format("%d%s",a[i],i==a.length-1?"\n":","); //Loop from i to a.length use a ternary operator to determine if value printed is the last one, if it is, create a new line , if not, insert a comma (')for(int i = 0;i<a.length;i++)System.out.format("%d%s",a[i],i==a.length-1?"\n":","); //Loop from i to a.length use a ternary operator to determine if value printed is the last one, if it is, create a new line , if not, insert a comma (')
System.out.print(a[i]); //print out the value of array a at index i
if(i<a.length-1)System.out.print(","); //print out a comma if the printed digit before it is not the last digit (last digit does not need a comma)
}
System.out.println(); //Create a newline to make the format looks uniform
} }
public static void main(String[] args) { public static void main(String[] args) {