Re: Arrays element Equals
Quote:
Originally Posted by
must0995
Hi
I can make equals of 2 arrays.
if (Arrays.equals(data1, data2)) {
but how can i make arrays of elements in the array.
Your assignment has nothing to do with this "making arrays of elements in the array". You simply would use for loops. Why not try to solve this and then if it doesn't work, show us what you've tried.
Re: Arrays element Equals
My friend
I cant solve becouse i do not have the experience of how to comare 2 element of one block eg.
{1,2,1} compre this with { 1,2,4,7, 1,2,1}
Only experience i got is using equals.
and i can only use it when i compare whole array list not the element.
eg. i can compare list{1,2,2,2} with list2{1,2,2,2}
by using if{arrays.equals{list,list1}
my quastion is:
how can i compare element element not array not array, how can i compre indside the array the element.
Re: Arrays element Equals
How do you access an element of an array? You use the [] notation with the name of the array and an index value:
theArrayName[theIndex]
Re: Arrays element Equals
please help..
i dont [inappropriate language deleted] understand this. i wasted now 5 hours on this quastion. and now i face 4 another quastion want me to compare a list of element with another list of array element.
Write a method called allLess that accepts two arrays of integers and returns true if each element in the first array
is less than the element at the same index in the second array. Your method should return false if the arrays are not
the same length
please understadn this. i do do do do not not not not have experience in java. i dont know whatt to useeeeeeee. and howwww to compare first element with another arrays element.
give me solution and i will solve all other quastion:
be fair.
1. i know i should use boolean.
2. i know i need loops
3. how the [inappropriate language deleted] can i make 2 loops goes indside 2 arrays . catch first element. then compare with another array's element.
this is not funny.
import java.util.Arrays;
public class k7Selfcheck13 {
public static void main(String[] args) {
int[] first = {1,2,3,4,5,6,7,8,9};
int[] seconed ={1,2,3,4,5,6,7,8,9};
allLess(first,seconed);
}
private static boolean allLess(int[] first, int[] seconed) {
boolean name = false;
for (int i = 0; i < first.length ; i++) {
for (int j = 0; j < seconed.length; j++) {
if(Arrays.equals(first,seconed)){
name = true;
}
}
}
return name;
}
}
Re: Arrays element Equals
Given an array, how do you access an element of that array?
This is the way: theArrayName[theIndex]
Now what if there is another array that you want to compare the elements of one array against the elements of the other?
How would you code a comparison of values if the values to be compared were in variables? Say abc vs def?
if( abc < def)
The elements of an array are the same as variables and can be used the same way as a variable:
if(anarray[indexToArray] < def)
For more on arrays: Arrays (The Java™ Tutorials > Learning the Java Language > Language Basics)
Re: Arrays element Equals
check this out
for ( int i = 0; int < (array.length-(shorter_array.length)); i++)
{
if(array[i]equals(shorter_array[i])
{
system.out.println("These two match"+array[i]);
}
}
Try somehting like this and you should be able to figure the rest out.
Re: Arrays element Equals
Quote:
Originally Posted by
Norm
Given an array, how do you access an element of that array?
This is the way: theArrayName[theIndex]
Now what if there is another array that you want to compare the elements of one array against the elements of the other?
How would you code a comparison of values if the values to be compared were in variables? Say abc vs def?
if( abc < def)
The elements of an array are the same as variables and can be used the same way as a variable:
if(anarray[indexToArray] < def)
For more on arrays:
Arrays (The Java™ Tutorials > Learning the Java Language > Language Basics)
ty man now i understand what u mean.
Re: Arrays element Equals
Quote:
Originally Posted by
zonic
... code deleted ...
Zonic, please don't spoon-feed answers here. It's a lazy way to answer as it's easy to create the codes, much easier than trying to explain to the poster how to fix it themselves, and the posters learn nothing but how to beg for code.