So I'm trying to compare two arrays?

0 edward stuart · May 5, 2015
So basically I am trying to compare two Arrays, I need the users to enter in cost they would like and then I must take that and give them two options that are close to it . Any help in the correct direction would be nice thanks! 
import java.util.Scanner;
public class ES{

public static void main(String[] args) {
System.out.println("1.Deals Closet to your budget \n 2.Deals closet to your storage requirements \n 3.Special Offer \n");
Scanner keyboard =  new Scanner(;

String[]   names = { "Value", "Economy", "Deluxe", "Premium", "Ultimate"};
int[] amountOfRamInGBs = {1 ,  2, 3, 4, 8 };
int[] amountOfStorageInGB= {40, 60, 90, 120, 240 };
int[] bandwidthGBperMonth={1000,   2000, 3000, 4000, 8000 };
int[] costPerMonth =   {24, 32, 48, 64, 120 };
int[] userSpendingArray ;
int userInput = keyboard.nextInt();


System.out.println("Please enter the amount you would like to spend");
int UserSpending = keyboard.nextInt();
userSpendingArray = new int[UserSpending];

closetPrice(  amountOfRamInGBs, amountOfStorageInGB, bandwidthGBperMonth,  costPerMonth , UserSpending, userSpendingArray);


public static void closetPrice(int[] amountOfRamInGBs, int[] amountOfStorageInGB, int[] bandwidthGBperMonth, int[] costPerMonth, int userSpending , int[] userSpendingArray)
for(int counter=0;counter<costPerMonth.length;counter++)


Post a Reply


Oldest  Newest  Rating
+2 Sharon Fabin · May 8, 2015
idk how you want the comparison to be but if you want to compare 2 simple arrays you need to just make a for loop on one of them and then inside that make another for loop for the second array:
int arr1[],arr2[];

for(int i=0;i<arr1.length;i++){
for(int j=0;j<arr2.length;j++){
if(arr2[j]==arr1) return true;
+1 Nicholas Eason · May 8, 2015
I dont see a multi-dimensional array being confusing in this case though, Kuroodo. In my opinion, having 4 or 5 parallel arrays is more confusing than 1 multi-dimensional array.

However, I do agree that some Multi-dimensional arrays can be confusing to work with. Specifically ragged arrays... 
(i.e array[1].length = 1, array[2].length = 15)
0 Dol Lod · May 6, 2015
I think you should make clear what exactly you are doing. The only thing I got is "I am comparing 2 arrays" and I have no idea about what way you are comparing them or what you will do with the result?
0 edward stuart · May 6, 2015
Ask the user how much he would like to spend a month and print out the name of the two closest options available for this price.
0 Nicholas Eason · May 6, 2015
Instead of using 4 or 5 different arrays, why not make it a 2 dimensional array?
0 Kuroodo Ditory · May 8, 2015
Not sure about you Nicholas, but multi dimensional arrays can be confusing sometimes.
  • 1

Java / Android Development


Very popular language used to create desktop applications, website applets, and Android apps.

Bucky Roberts Administrator