DSA Assignment 1
DSA Assignment 1
DSA Assignment 1
1 7 1 1 2 4
Student Id :
Email : [email protected]
Assignment No. :1
Submission Date :
Assignment 1
Write a Java program which a user can enter an index of an integer array in order to insert
or delete an item. The following program output can give you a better picture of how it
looks like.
Code:
// package indexinteger;
import java.util.Arrays;
import java.util.Scanner;
/**
*""
* @author user
*/
public class indexInteger {
return b;
}
// if the index is
// the removal element index
if (i == indexvalue) {
continue;
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner inp = new Scanner(System.in);
while (check) {
try {
System.out.println("Enter an index value to be insert");
int index = inp.nextInt();
if (index < b.length) {
check = false;
} else {
System.out.println("Enter again");
}
if (check == false) {
for (int i = 0; i < b.length; i++) {
if (i < index) {
b[i] = a[i];
} else if (i == index) {
b[i] = number;
} else {
b[i] = a[i - 1];
}
}
} catch (Exception e) {
System.out.println(e);
}
}
Output: