Anybody got any idea on how I can check if an array indexes(not just one index) are empty and if is empty or zero put a value there. And also if all the indexes are all not empty print an error.
Sorry unfortunately I can't give rep.
import java.util.Scanner;
public class Myhash {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int [] myData = new int[17];
int [] newData = new int [17];
System.out.println("Please enter 16 integer numbers");
for(int i= 0; i<myData.length; i++){
//System.out.print("Please enter 16 numbers");
Scanner input = new Scanner(System.in);
int data =input.nextInt();
myData[i]=data;
int num3 = data % 17;
newData[num3]=data;
}
System.out.println("These are the numbers you entered\n");
System.out.printf("%s%8s \n", "Index", "Value");
for(int t=0; t<myData.length; t++){
System.out.printf("%5d%8d\n", t, myData[t]);
}
System.out.println("\n");
System.out.println("The Hash Function:\n\n");
System.out.printf("%5s%8s \n", "Index", "Value");
for(int s=0; s<newData.length; s++){
System.out.printf("%5d%8d\n", s, newData[s]);
}
}
}
on here:
for(int s=0; s<newData.length; s++){
System.out.printf("%5d%8d\n", s, newData[s]);
}
how do check for more than one index(if empty? If the index is empty how do check for the next index and if that one is not empty how do i check the next one, etc?