how to create a mutlipication table in java program for example:
enter x=5
enter y =6

output is:
1*6=6
2*6=12
3*6=18
4*6=24
5*6=30

1) Create a array, which represents a table.
2) use a for loop;

for(int i = 1; i != 5; i++)
    myArrayTable[i] = 6*i; //say, myArrayTable is already declared.

1) Create a array, which represents a table.
2) use a for loop;

for(int i = 1; i != 5; i++)
    myArrayTable[i] = 6*i; //say, myArrayTable is already declared.

I have a question:
Why didn't you use this at the for loop:

for(int i = 1; i < 5; i++)

1)
Class: Multiply
Attributes: int x
int y
Methods: getters&setters
Constructors
toString

in Main
create array or arraylist of the class Multiply
take in the 2 numbers into each
to print:
iterate through the array and print the "Multiply.toString()" and the "toString()" will include the "x*y = z" to form each line

I would recomend using the IDE's BlueJ or Netbeans (Netbeans does most of it for you hence is my favourite)

any errors in my repllies then pm me please as I am also a learner

sorry! I am new learner for java program, I still confuse about your answer. can you give me some example for this program, thanks...

They just gave you a more than sufficient reply. If you don't understand the reply either go study about for loops and arrays, or ask a specific question if there is something you don't understand. We can't read your mind.

I have a question:
Why didn't you use this at the for loop:

for(int i = 1; i < 5; i++)

late reply but its just preference at times.

A thing to note ( at least in c++) is that != is more generic than
'<' because '!=' works with containers like vectors, string map
while '<' is not compatible with all of them. I imagine that
java is similar. It also depends on context btw.

interesting point. I haven't seen the non-equals operator used as a loop conditional before. I have to admit that what you said makes sense. I would have never thought of it in that way before. But . . . what guarantee do you have that you are actually comparing values in c++? wouldn't a statement like objecta != objectb be interpreted as: The address where objecta resides is not equal to the address where objectb resides?
Besides, c++ allows you to overload your operators so there is no ambiguity. The classes you are talking about may have just implemented that.
But as far as comparing primitives? Sure != 5 looks hunky dory. I've been using comparison operators for the last 15 years, so I don't thnink I'll all of the sudden switch though.

>>
"what guarantee do you have that you are actually comparing values in c++?"
<<

In c++ the "!=" operator when used with container from std does not compare address like the "==" in java ( at times), it only compares
the values. The standard C++ library was implemented with generic in
mind.

In c++ the "!=" operator when used with container from std does not compare address like the "==" in java ( at times), it only compares
the values. The standard C++ library was implemented with generic in
mind.

Well, if that is the case, those operators would have had to have been overloaded for those operations, otherwise the comparitors would compare addresses. I would have to go and look at the library code, (I use DevC++) to check and see if that's the case. I'm pretty sure that for any object regardless if it's in a collection or not will have to have the comparitors overloded in addition to providing a deep copy constructor. Come to think of it, if you call something to the effect of:

someCollection<someClass> someObject[] = new someCollection<someClass>()[2];
someObject[0] = someData;
someObject[1] = otherData;

if (someObject[0] != someObject[1])
{
   std::cout << "AHHHHHH!!!! Run for your lives!!! ";
}

that operator will be called from the overloaded operator defined in someClass, not someCollection. What I was saying, without knowing if someObject overloads !=, you have no guarantee that you are comparing someData and otherData. If not you will be comparing the dereferenced addresses of each object. So in java, this is one of the reasons that all classes derive from Object. That way, they can implement the equals() method to ensure that you are comparing by value and not by reference.
Also, c++ calls generic types template types. But you knew that.
So . . . should this thread be moved to c++ or did LKH get his answer? Sorry for the rambling.

Edited 7 Years Ago by eggmatters: n/a

>>last 15 years
Wow, I have just programming for about 2 yrs on/off so you have a lot more knowledge than me. Nevertheless I would still like to debate even though if I may be wrong, if that's OK with you.

>>Well, if that is the case ...<snipped>
<<

I see what you mean, let me rephrase what I meant to say, my words
weren't being clear. A reason why a person might use "!=" versus
"<" would rely mainly in its context. For example, != is more general
when iterating through a container, as not all iterator define the <
operator. For example, vector and map would work with != but not <
operator in C++. But I do not mean that != is more general than <
every time nor should it be used in cases like you have shown. To
answer the question for javaAddict, i used != because in a for loop it
might be more general at times, and just thought I would switch it up
a bit.

>>
Also, c++ calls generic types template types.
<<
Yea, but I was talking about generic in a sense of overall not just meta programming, sorry I should have been more clear, again.

Well, you seem to know a lot more after 2 years than I did. As a comparitor, we typically know how operators behave on primitive types. But I think we both have the same understanding when the types are complex. An equals sign can't "magically" grab all of the data an object has and figure out if they are equal or not. That has to be implemented somewhere.
I was just digressing more out of boredom than anything. I guess I'm like a baseball purist when it comes to programming. Plus, 98 percent of all my coding errors come from improperly implemented loop conditions. As a matter of fact, that reminds me. I have some bugs to clean up. Hopefully LKH figured out how to implement his / her multiplication table.

Comments
I agree; his strategy logically makes sense, but doesn't work in Java. != doesn't call equals()
This article has been dead for over six months. Start a new discussion instead.