Program access the package
import static pack.Range.*; public class range1 { public static void main(String[] args) { for(int z:range(9)) //0...8 { System.out.print(z+" "); } System.out.println(); for(int i:range(5,10))//5..9 { System.out.print(i+" "); } System.out.println(); for(int z:range(5,20,3))//5..20 step 3 { System.out.print(z+" "); } } } /*output= 0 1 2 3 4 5 6 7 8 5 6 7 8 9 5 8 11 14 17 */
The range method is overloaded.The first overloaded form of range() just start at zero and produces values up to but not including the top end of the range.The second from start at the first values and goes until one less than the second .
Download the code from hear:
Attachment | Size |
---|---|
code.rar | 1.25 KB |