M
MattandPauline
Hi
I'm new to Java programming and seem to have got stuck.
Please can anyone say what is wrong with my basic program below. I'm
trying to create an object array that holds tilda (~) characters :-
class Queueclass {
char queue[]; // name of queue
int cursor; // position at end of queue for adding extra nodes into
queue
//------------------Define Constructor------------------------
Queueclass (int size) {
queue = new char[size]; //create array in class
cursor = 0; // also sets end cursor element to 0
// initialising array
for (int x:queue)
queue[x]='~';
}
//-----------------End of Defining Constructor-------------------
//-----------------Define Methods--------------------------------
char display(int node){
return queue[node];
}
}
public class Queuecirc2 {
public static void main(String[] args) {
Queueclass queue1= new Queueclass(10); //define new object called
queue1
char ch; // character returned
// Checking default that defailt values of queue1 are set to
tilda's (~)
int x = 0;
do {
ch=queue1.display(x);
System.out.println("Character returned is :-" + ch);
x=x+1;
} while(x < 9);
}
}
Its as though my program is not following the do and for loops
properly. The output is :-
Character returned is :-~
Character returned is :-
Any help is much appreciated.
Kind Regards
Matt
I'm new to Java programming and seem to have got stuck.
Please can anyone say what is wrong with my basic program below. I'm
trying to create an object array that holds tilda (~) characters :-
class Queueclass {
char queue[]; // name of queue
int cursor; // position at end of queue for adding extra nodes into
queue
//------------------Define Constructor------------------------
Queueclass (int size) {
queue = new char[size]; //create array in class
cursor = 0; // also sets end cursor element to 0
// initialising array
for (int x:queue)
queue[x]='~';
}
//-----------------End of Defining Constructor-------------------
//-----------------Define Methods--------------------------------
char display(int node){
return queue[node];
}
}
public class Queuecirc2 {
public static void main(String[] args) {
Queueclass queue1= new Queueclass(10); //define new object called
queue1
char ch; // character returned
// Checking default that defailt values of queue1 are set to
tilda's (~)
int x = 0;
do {
ch=queue1.display(x);
System.out.println("Character returned is :-" + ch);
x=x+1;
} while(x < 9);
}
}
Its as though my program is not following the do and for loops
properly. The output is :-
Character returned is :-~
Character returned is :-
Any help is much appreciated.
Kind Regards
Matt