How to create an array of pairs with Java

1 Answer

0 votes
class Pair
{
    public int x, y;
  
    Pair(int x, int y) {
        this.x = x;
        this.y = y;
    }
}
  
public class MyClass
{
    public static void findPairs(Pair[] pairs) {
        for (Pair one_pair: pairs) {
            System.out.println("(" + one_pair.x + ", " + one_pair.y + ")");
        }
    }
  
    public static void main(String[] args)
    {
        Pair[] pairs = {
            new Pair(7, 2), new Pair(1, 8), new Pair(4, 6), new Pair(5, 1),
            new Pair(9, 3), new Pair(2, 7), new Pair(3, 5)
        };
  
        findPairs(pairs);
    }
}
 
 
 
 
/*
run:
 
(7, 2)
(1, 8)
(4, 6)
(5, 1)
(9, 3)
(2, 7)
(3, 5)

*/

 



answered Aug 6, 2022 by avibootz

Related questions

1 answer 116 views
116 views asked Aug 6, 2022 by avibootz
2 answers 198 views
1 answer 116 views
1 answer 121 views
1 answer 130 views
1 answer 112 views
...