ok we just started arrays yesterday and made us do a program..
this basically prints 2 lists of arrays that has 10 blocks with random numbers in each block (1-99)
it works but does anyone know how to make this code better? any suggestions?
its kind of ugly because of all the if conditionals though...
int x, y =0; int [] list; list = new int [10]; int [] list2; list2 = new int [10]; x =(int)(99*Math.random()+1); y=(int)(99*Math.random()+1); int array = 9; int [] list3; list3 = new int [10]; int [] list4; list4 = new int [10]; list[0] = x; x =(int)(99*Math.random()+1); list[1] = x; x =(int)(99*Math.random()+1); list[2] = x; x =(int)(99*Math.random()+1); list[3] = x; x =(int)(99*Math.random()+1); list [4] = x; x =(int)(99*Math.random()+1); list [5] = x; x =(int)(99*Math.random()+1); list [6] = x; x =(int)(99*Math.random()+1); list [7] = x; x =(int)(99*Math.random()+1); list [8] = x; x =(int)(99*Math.random()+1); list [9] = x; x =(int)(99*Math.random()+1); list2[0] = x; x =(int)(99*Math.random()+1); list2[1] = x; x =(int)(99*Math.random()+1); list2[2] = x; x =(int)(99*Math.random()+1); list2[3] = x; x =(int)(99*Math.random()+1); list2[4] = x; x =(int)(99*Math.random()+1); list2[5] = x; x =(int)(99*Math.random()+1); list2[6] = x; x =(int)(99*Math.random()+1); list2[7] = x; x =(int)(99*Math.random()+1); list2[8] = x; x =(int)(99*Math.random()+1); list2[9] = x; x =(int)(99*Math.random()+1); System.out.println("List 1 = " + list[0] + " " +list[1] + " " + list[2] + " " + list[3]+" " + list[4] + " " +list[5] + " " + list[6] + " " + list[7] + " "+ list[8] + " " + list[9]); System.out.println("List 2 = " + list2[0] + " " +list2[1] + " " + list2[2] + " " + list2[3]+" " + list2[4] + " " +list2[5] + " " + list2[6] + " " + list2[7] + " "+ list2[8] + " " + list2[9]); if(list[0] > list2[0]) list3[0] = list[0]; else list3[0] = list2[0]; if(list[1] > list2[1]) list3[1] = list[1]; else list3[1] = list2[1]; if(list[2] > list2[2]) list3[2] = list[2]; else list3[2] = list2[2]; if(list[3] > list2[3]) list3[3] = list[3]; else list3[3] = list2[3]; if(list[4] > list2[4]) list3[4] = list[4]; else list3[4] = list2[4]; if(list[5] > list2[5]) list3[5] = list[5]; else list3[5] = list2[5]; if(list[6] > list2[6]) list3[6] = list[6]; else list3[6] = list2[6]; if(list[7] > list2[7]) list3[7] = list[7]; else list3[7] = list2[7]; if(list[8] > list2[8]) list3[8] = list[8]; else list3[8] = list2[8]; if(list[9] > list2[9]) list3[9] = list[9]; else list3[9] = list2[9]; if(list[0] < list2[0]) list4[0] = list[0]; else list4[0] = list2[0]; if(list[1] < list2[1]) list4[1] = list[1]; else list4[1] = list2[1]; if(list[2] < list2[2]) list4[2] = list[2]; else list4[2] = list2[2]; if(list[3] < list2[3]) list4[3] = list[3]; else list4[3] = list2[3]; if(list[4] < list2[4]) list4[4] = list[4]; else list4[4] = list2[4]; if(list[5] < list2[5]) list4[5] = list[5]; else list4[5] = list2[5]; if(list[6] < list2[6]) list4[6] = list[6]; else list4[6] = list2[6]; if(list[7] < list2[7]) list4[7] = list[7]; else list4[7] = list2[7]; if(list[8] < list2[8]) list4[8] = list[8]; else list4[8] = list2[8]; if(list[9] < list2[9]) list4[9] = list[9]; else list4[9] = list2[9]; System.out.println(); System.out.println("List 3 = " + list3[0] + " " +list3[1] + " " + list3[2] + " " + list3[3]+" " + list3[4] + " " +list3[5] + " " + list3[6] + " " + list3[7] + " "+ list3[8] + " " + list3[9]); System.out.println("List 4 = " + list4[0] + " " +list4[1] + " " + list4[2] + " " + list4[3]+" " + list4[4] + " " +list4[5] + " " + list4[6] + " " + list4[7] + " "+ list4[8] + " " + list4[9]); } }