Display all elements of an array from 1-10 except 5 (use continue).




import java.util.*;
public class Continue {
public static void main(String[] args) {
int intArray[]={0,1,2,3,4,5,6,7,8,9};
Scanner input = new Scanner(System.in);
System.out.println("Array elements are");
for(int i=0; i<intArray.length; i++)
{
System.out.print(intArray[i]+" ");
}
System.out.println("Type the Number you want to skip");
int n = input.nextInt();
for(int i=0; i<intArray.length; i++)
{
if(n==i)
continue;
System.out.print(i+" ");
}
}

}

/*
Array elements are
0 1 2 3 4 5 6 7 8 9 Type the Number you want to skip
5
0 1 2 3 4 6 7 8 9
*/

Post a Comment

Copyright © Rough Record. Designed by OddThemes