Storing a string and two doubles java

后端 未结 3 1798
野的像风
野的像风 2021-01-29 09:55

I have written a program which gives me three arrays.A string array and two dole arrays.... But I want to save them in one thing(I don\'t know if it would be an array or matrix)

3条回答
  •  悲哀的现实
    2021-01-29 10:30

    class Triple {
        private String name;
        private double d1;
        private double d2;
    
        public Triple(String name, double d1, double d2) {
            this.name = name;
            this.d1 = d1;
            this.d2 = d2;
        }
    }
    

    Then you can do

    Triple[] fruits = new Triple[3];
    fruits[0] = new Triple("Apple", 42.0, 13.37);
    

    I really suggest you to read a good tutorial on Object Oriented Programming, like my favorite, especially Chapter 25+.

提交回复
热议问题