The Artima Developer Community
Sponsored Link

Java Answers Forum
help!: a loop problem

4 replies on 1 page. Most recent reply: Nov 22, 2002 7:32 AM by Daniel Ray

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 4 replies on 1 page
Rachid

Posts: 2
Nickname: hemtah
Registered: Nov, 2002

help!: a loop problem Posted: Nov 22, 2002 3:20 AM
Reply to this message Reply
Advertisement
Hello,

if someone can help me, that will be great.

i got to class, one main and one a class

>>> in my class i have this bit of code:

...

public void setSize (int number)

{
size = number;
}

public int getSize()

{
return size;
}




...
public void displayOriginal()

{
for (int i=0; i<size; i++)
{
System.out.println("\t"+mm1+"\t "+mm2);
}


>>> in my main class i got:

System.out.print("Enter the number of vertices between 3 to 25: ");
size = BasicIO.readInt();
mm.mm1 = new double [size];
mm.mm2 = new double [size];
mm.setSize(size);

...
switch(menuOperation)
{
case 1: // list co-ordinates original polygon
mm.displayOriginal();

break;


So when i want to display my table i have an infinite loop,
what i have to do to avoid that?

thank you


Daniel Ray

Posts: 53
Nickname: budoray
Registered: Oct, 2002

Re: help!: a loop problem Posted: Nov 22, 2002 6:07 AM
Reply to this message Reply
An infinite loop? How did you get it to compile? double is a primitive not an object.


mm1 = new double [size];


double[] mm1;
mm1 = size;

Maybe you're using Double from java.lang.Double. If so, then try

Double[] mm2;
mm2 = new Double(size); // use a loop to initialize the values.

Notice that your set and get size method should return a double or a String instead of an int. That's what the Double constructor takes.

Ray

Daniel Ray

Posts: 53
Nickname: budoray
Registered: Oct, 2002

Re: help!: a loop problem Posted: Nov 22, 2002 6:10 AM
Reply to this message Reply
This should read

mm1 = new double [size]; // Can't do.

double[] mm1; // okay
mm1 = size; // okay

Rachid

Posts: 2
Nickname: hemtah
Registered: Nov, 2002

Re: help!: a loop problem Posted: Nov 22, 2002 7:27 AM
Reply to this message Reply
hello

thanks for your replies,

so :

mm.mm1 = new double [size];
mm is an object, mm1 is the intance of the object mm

i need to use "new" to input data in my array
because in my class program i have defined two arrays
mm1 and mm2, i want that those two arrays have the same size
that's why i initialise the array in my main class

Daniel Ray

Posts: 53
Nickname: budoray
Registered: Oct, 2002

Re: help!: a loop problem Posted: Nov 22, 2002 7:32 AM
Reply to this message Reply
Didn't catch that part, but yes, you are creating a new array and not a new double.

Ray

Flat View: This topic has 4 replies on 1 page
Topic: arrays + random access files Previous Topic   Next Topic Topic: classes and arrays

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use