Lim Youjie

Greenhorn
+ Follow
since Dec 27, 2004
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Lim Youjie

Hmm my code is as below:

There is a linkedlist inside another linkedlist.

//Eliminate path that are long
while (iterator.hasNext())
{
BoardState boardstate = (BoardState) iterator.next();
LinkedList path = (LinkedList) boardstate.path;
Puzzle puzzle = (Puzzle) path.getLast();
int levelCount = boardstate.getLevel(puzzle);

ListIterator iterator2 = searchQueue.listIterator();

while (iterator2.hasNext())
{
BoardState boardstate2 = (BoardState) iterator2.next();
LinkedList path2 = (LinkedList) boardstate2.path;
Puzzle puzzle2 = (Puzzle) path2.getLast();
int levelCount2 = boardstate2.getLevel(puzzle2);

if (puzzle.equals(puzzle2))
{
if (levelCount >= levelCount2)
{
iterator.remove();
}
else
{
iterator2.remove();
}
}
}
}

18 years ago
Hi,

May I know whether there is any way to remove an element in a LinkedList while I was traversing through it?

I have tried it and was prompt NullPointerException.
18 years ago
Hi, i am using a reader object to read input.

int next = reader.read();
if (next != -1) //if not end of input
{
char c = (char) next; //cast "next" into character and store in "c"
System.out.println(c);
}

may i know what reader.read() will return when it is end of input and space?
18 years ago
Hi, i have encounter a problem when trying to use a Reader object. i cannot detect the end of file thus the whole word cannot be printed out. Hope someone will enlighten me.






import java.io.*;

public class Tokenizer
{
private Reader reader;

public Tokenizer(Reader r)
{
reader = r;
}

public String nextWord()
{
String word = "";
int next = 0;
char c = 'a';

try
{
while (next != -1)//while "next" not end of input
{
next = reader.read();
if (next != -1) //if not end of input
c = (char) next; //cast "next" into character and store in "c"
word = word + c; //add character to word
}
}
catch (IOException ex)
{
System.out.println("IOException occurs");
}
return word;
}

}
18 years ago
Hi,

may i know how to change the date format to CST of the Date object?

thanks.
18 years ago
how to set the size of the buttons in the toolbar. i try to set it by
button.setPreferredSize(new Dimension(50,50)), but i does not seem to work.
18 years ago
my code(cant work), flag variable is still 0 when its at the second loop

public void actionPerformed(ActionEvent e)
{
int flag = 0;
if (e.getSource() == buttonNumbers[0])
{
flag = 1;
System.out.println("1 is pressed");
}
if (e.getSource() == buttonPlay[0] && flag == 1)
{
System.out.println("1 is print");
System.out.println(flag);
flag = 0;
}
}
18 years ago
sorry i try but it dunn seem to work.

trying to create a set of buttons on the toolbar(with numbers from 1 to 9)
and another set of buttons in the center of the program.

For example when i click on the button labeled "1" on the toolbar, and then click on one of the buttons in the center of the program, the button will be labeled "1".
18 years ago
any samples for setting flag ... just a short code will do ...
18 years ago
may i know how to trigger an event when i clicked on a button and then clicked on another button(buttonPlay[0]).
I think my code is wrong but i dunn have any idea how to implement it. Thanks

public void actionPerformed(ActionEvent e)
{
if (e.getActionCommand().equals("1"))
{
if (e.getSource() == buttonPlay[0])
{
System.out.println("1 and buttonPlay[0] pressed");
}
}
}
18 years ago
for example.
System.out.print("Bold");

may i know how to customise the string. make bold or change its font type or size, etc.
18 years ago
My array is working fine but when i try to change to arraylist, i encounter an error msg. Can anybody help me?
thanks.

Using array:
deck[currentPosition] = deck[swapPosition];

Change to arraylist
deck.get(currentPosition) = deck.get(swapPosition)
error msg:unexpected type;required: variable,found
18 years ago
Below is my main method. i cant find out wats wrong. Thanks

InputStreamReader isr = new InputStreamReader (System.in);
BufferedReader kbd = new BufferedReader (isr);

System.out.print("Enter first integer number: ");
MyInteger a = new MyInteger(Integer.parseInt(kbd.readLine()));
System.out.print("Enter second integer number: ");
MyInteger b = new MyInteger(Integer.parseInt(kbd.readLine()));
System.out.println(a + "+" + b + " is: " + a.add(b));
System.out.println(a + "-" + b + " is: " + a.sub(b));
18 years ago
Thanks but although i get the desired results for add() but it does not work for sub();
For example for the 1st input i enter '9'
and 2nd input i enter '5'
for add() i get 14 ---> correct ans
but for sub() i get 9(14-5); --->do not know why the number variable used is 14 instead of 9.

Try to use this.number to solve but it din help.

//method for addition
public int add (MyInteger addednumber)
{
number = number + addednumber.number;
return number;
}

//method for subtraction
public int sub(MyInteger addednumber)
{
number = number - addednumber.number;
return number;
}

Thanks
18 years ago