mutlipication table in java program

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Sep 2009
Posts: 5
Reputation: LKH is an unknown quantity at this point 
Solved Threads: 0
LKH LKH is offline Offline
Newbie Poster

mutlipication table in java program

 
-3
  #1
Oct 6th, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 1,468
Reputation: firstPerson is just really nice firstPerson is just really nice firstPerson is just really nice firstPerson is just really nice firstPerson is just really nice 
Solved Threads: 189
firstPerson's Avatar
firstPerson firstPerson is online now Online
Nearly a Posting Virtuoso
 
0
  #2
Oct 6th, 2009
1) Create a array, which represents a table.
2) use a for loop;

  1. for(int i = 1; i != 5; i++)
  2. myArrayTable[i] = 6*i; //say, myArrayTable is already declared.
1) Prove that the area of a circle is pi*r^2, where "r" is the radius of the circle.
2) Problem 2[b]solved by : jonsca
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 1,718
Reputation: javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all 
Solved Threads: 230
Featured Poster
javaAddict's Avatar
javaAddict javaAddict is offline Offline
Posting Virtuoso
 
0
  #3
Oct 6th, 2009
Originally Posted by firstPerson View Post
1) Create a array, which represents a table.
2) use a for loop;

  1. for(int i = 1; i != 5; i++)
  2. myArrayTable[i] = 6*i; //say, myArrayTable is already declared.
I have a question:
Why didn't you use this at the for loop:
  1. for(int i = 1; i < 5; i++)
Check out my New Bike at my Public Profile at the "About Me" tab
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 14
Reputation: 0805638 is an unknown quantity at this point 
Solved Threads: 0
0805638 0805638 is offline Offline
Newbie Poster

its easier using 2 classes.

 
0
  #4
Oct 6th, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 5
Reputation: LKH is an unknown quantity at this point 
Solved Threads: 0
LKH LKH is offline Offline
Newbie Poster
 
0
  #5
Oct 13th, 2009
sorry! I am new learner for java program, I still confuse about your answer. can you give me some example for this program, thanks...
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 1,658
Reputation: BestJewSinceJC is a splendid one to behold BestJewSinceJC is a splendid one to behold BestJewSinceJC is a splendid one to behold BestJewSinceJC is a splendid one to behold BestJewSinceJC is a splendid one to behold BestJewSinceJC is a splendid one to behold 
Solved Threads: 206
BestJewSinceJC BestJewSinceJC is offline Offline
Posting Virtuoso
 
0
  #6
Oct 13th, 2009
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.
Out.
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 1,468
Reputation: firstPerson is just really nice firstPerson is just really nice firstPerson is just really nice firstPerson is just really nice firstPerson is just really nice 
Solved Threads: 189
firstPerson's Avatar
firstPerson firstPerson is online now Online
Nearly a Posting Virtuoso
 
0
  #7
Nov 3rd, 2009
Originally Posted by javaAddict View Post
I have a question:
Why didn't you use this at the for loop:
  1. 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.
1) Prove that the area of a circle is pi*r^2, where "r" is the radius of the circle.
2) Problem 2[b]solved by : jonsca
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 63
Reputation: eggmatters is an unknown quantity at this point 
Solved Threads: 4
eggmatters eggmatters is offline Offline
Junior Poster in Training
 
0
  #8
Nov 3rd, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 1,468
Reputation: firstPerson is just really nice firstPerson is just really nice firstPerson is just really nice firstPerson is just really nice firstPerson is just really nice 
Solved Threads: 189
firstPerson's Avatar
firstPerson firstPerson is online now Online
Nearly a Posting Virtuoso
 
0
  #9
Nov 3rd, 2009
>>
"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.
1) Prove that the area of a circle is pi*r^2, where "r" is the radius of the circle.
2) Problem 2[b]solved by : jonsca
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 63
Reputation: eggmatters is an unknown quantity at this point 
Solved Threads: 4
eggmatters eggmatters is offline Offline
Junior Poster in Training
 
0
  #10
Nov 3rd, 2009
Originally Posted by firstPerson View Post
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:
  1. someCollection<someClass> someObject[] = new someCollection<someClass>()[2];
  2. someObject[0] = someData;
  3. someObject[1] = otherData;
  4.  
  5. if (someObject[0] != someObject[1])
  6. {
  7. std::cout << "AHHHHHH!!!! Run for your lives!!! ";
  8. }
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.
Last edited by eggmatters; Nov 3rd, 2009 at 3:18 pm.
Reply With Quote Quick reply to this message  
Reply

Message:




Views: 492 | Replies: 11
Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC