why my javacode always compile error

Write here if you have problems with your Java source code

Moderator: Board moderators

Post Reply
kojilin
New poster
Posts: 1
Joined: Tue Aug 27, 2002 4:05 pm

why my javacode always compile error

Post by kojilin » Tue Aug 27, 2002 4:08 pm

[java]import java.io.*;
import java.util.*;
import java.lang.*;
class Main
{

public static void main(String[] args)
{
Main myApp = new Main();
myApp.start();
}
Vector list[];
public static String readLine(int max)
{
byte lin[] = new byte[max];
int lg = 0;
int car = -1;
String line = "";
try{
while(lg < max){
car = System.in.read();
if(car == -1 || car == '\n')break;
lin[lg++] += car;
}
}
catch(Exception e){
return (null);
}
if ((car < 0) && (lg == 0)) return (null);
return (new String (lin, 0, lg));

}
public void start()
{
String input;
StringTokenizer idata;

int len = 0;
String action1 = "";
String action2 = "";
int from = 0;
int to = 0;


input = Main.readLine (255);
idata = new StringTokenizer(input);
len = Integer.parseInt(idata.nextToken());
list = new Vector [len];
for(int i = 0; i < len; ++i){
list = new Vector();
list.addElement(new Integer(i));
}
while ((input = Main.readLine (255)) != null){
idata = new StringTokenizer(input);
action1 = idata.nextToken();
if(action1.equals("quit"))
{
for(int i = 0 ; i < len; ++i){
System.out.print(i+":");
for(int j = 0; j < list.size(); ++j)
System.out.print(" "+list.elementAt(j));
System.out.println("");
}
return;
}
from = Integer.parseInt(idata.nextToken());
action2 = idata.nextToken();
to = Integer.parseInt(idata.nextToken());
if(action1.equals("move")){
if(action2.equals("onto"))
moveOnto(from, to, len);
else
moveOver(from, to, len);
}
if(action1.equals("pile")){
if(action2.equals("onto"))
pileOnto(from, to, len);
else
pileOver(from, to, len);
}
}
}
public void moveOnto(int from, int to, int len)
{
int xfromPlace;
int yfromPlace;
int xtoPlace;
int ytoPlace;

initial(from, len);
initial(to, len);

xfromPlace = findPlacex(from, len);
yfromPlace = findPlacey(from, len);
xtoPlace = findPlacex(to, len);
ytoPlace = findPlacey(to, len);

list[xtoPlace].addElement(list[xfromPlace].elementAt(yfromPlace));
list[xfromPlace].removeElementAt(yfromPlace);
}
public void moveOver(int from, int to, int len)
{
int xfromPlace;
int yfromPlace;
int xtoPlace;
int ytoPlace;

initial(from, len);

xfromPlace = findPlacex(from, len);
yfromPlace = findPlacey(from, len);
xtoPlace = findPlacex(to, len);
ytoPlace = findPlacey(to, len);
list[xtoPlace].addElement(list[xfromPlace].elementAt(yfromPlace));
list[xfromPlace].removeElementAt(yfromPlace);
}
public void pileOnto(int from, int to, int len)
{
int xfromPlace;
int yfromPlace;
int xtoPlace;
int ytoPlace;


initial(to, len);


xfromPlace = findPlacex(from, len);
yfromPlace = findPlacey(from, len);
xtoPlace = findPlacex(to, len);
ytoPlace = findPlacey(to, len);

int num = list[xfromPlace].size() - yfromPlace;
for(int i = 0; i < num; ++i){
list[xtoPlace].addElement(list[xfromPlace].elementAt(yfromPlace));
list[xfromPlace].removeElementAt(yfromPlace);}
}
public void pileOver(int from, int to, int len)
{
int xfromPlace;
int yfromPlace;
int xtoPlace;
int ytoPlace;



xfromPlace = findPlacex(from, len);
yfromPlace = findPlacey(from, len);
xtoPlace = findPlacex(to, len);
ytoPlace = findPlacey(to, len);

int num = list[xfromPlace].size() - yfromPlace ;
for(int i = 0; i < num; ++i){
list[xtoPlace].addElement(list[xfromPlace].elementAt(yfromPlace));
list[xfromPlace].removeElementAt(yfromPlace);}
}
void initial(int block, int len)
{

for(int i = 0; i < len; ++i){
for(int j = 0; j < list.size(); ++j){
if(((Integer)list.elementAt(j)).intValue() == block){
if(j != (list.size() - 1)){
for(int k = j + 1; k < list.size(); ++k ){
list[k].addElement(list.elementAt(k));
list.removeElementAt(k + 1);
}
}
}
}
}
}
public int findPlacex(int block, int len)
{
for(int i = 0; i < len; ++i){
for(int j = 0; j < list[i].size(); ++j)
{
if(((Integer)list[i].elementAt(j)).intValue() == block){

return i;
}
}
}
return 0;
}
public int findPlacey(int block, int len)
{
for(int i = 0; i < len; ++i){
for(int j = 0; j < list[i].size(); ++j)
{
if(((Integer)list[i].elementAt(j)).intValue() == block){

return j;
}
}
}
return 0;
}
}
[/java]
why i cant compile it
and it always no error message
did i use some API cant be compiled?????

thanks

Post Reply

Return to “Java”