0
My problem is that the result shows me only a not OK in all cases, and this is just a class
import java.util.Scanner; public class arrayd { Scanner in=new Scanner(System.in); String array []= new String [2]; public void reed() { for (int i = 0; i < array.length; i++) { System.out.println("enter::"); array[i]=in.next(); } compare(array); } public void compare(String array[] ) { for (int j = 0; j < array.length; j++) { System.out.println("enter::"); array[j]=in.next(); } for (int k = 0; k < array.length; k++) { if (array[k] .equals(array)) { System.out.println(" ok"); } else { System.out.println(" not ok"); } } } }
8 Answers
+ 1
So you have 2 elements in String array <array> and you want to check whether those 2 elements were equal or is it something else?
I'm still not getting what you want to compare actually ...
+ 2
Why there is no main method though?
What you mean by "comparing the elements of two arrays"? you only have 1 String array named <array>.
It seems you read <array> elements twice, once in reed() method, and once in compare() method.
+ 1
Can you explain to me what you're doing with this code? I'm not getting the idea of it.
+ 1
I understand you now, I realized my mistake, I need to know another matrix so that I can compare, thank you
+ 1
Es -x10
If you want to compare two arrays then you can do this:
Arrays.equals(arr1, arr2)
0
Here I am comparing the elements of two arrays by string and this class
0
Es -x10
array is a collection of String
Check your this comparison
array[k].equals (array)
Do you think this is right?
0
public class master {
public static void main(String[] args) {
array a = new array();
a.reed();
}
}
this is main and I want to compare these arrays.. Can I or not ??