Sunday, 29 September 2013

Java syntax issues

Java syntax issues

I would like to say I'm new to Java, so I'm wallowing in a lot of suck.
I'm trying to do a Josephus problem, but I'm not allowed to use code
snippets from other people. With this in mind, I have 27 errors in my
code, but can't figure out how to fix it. Would you wonderful people
explain to me why it won't compile. I want to see if my logic is flawed,
but I can't test it because it won't compile. Any other tips to make me
not suck so bad are more than welcome! Here is my code: import
java.util.*;
public class Josephus
{
public class Link
{
public int num;
public Link next;
public Link (int d)
{
num = d;
next = null;
}
}
public class Main
{
Scanner in = new Scanner(System.in);
System.out.println("How many players");
int numPlayers = in.nextInt();
Link first, last;
first = last = new Link (1);
for(int k=2; k<=numPlayers; k++)
{
last.next = new Link(k);
last = last.next;
}
last.next = first;
System.out.println("How many skips");
int m = in.nextInt();
for (int g=0; g<numPlayers; g++)
{
for (int k=0; k<=m; k++);
{
last = last.next;
}
last.next;
last = last.next;
}
}
}

No comments:

Post a Comment