T
TheGodfather
hey folks i did solve josephus problem to day , but when i made a
little change and i took some code from JosephusApp to josephus it is
all ruined and i dono why i ll post everything maybe u can help me ,
anybody please;
Josephus
//===================================================================
class Josephus
{
Node first;
Node last;
Node ring;
Josephus()
{
first = null;
last = null;
ring = null;
}
Node circle(int key)
{
Node first = new Node(key);
Node last = first;
first.key = key;
for (int j = key - 1; j > 0 ; j--)
{
Node ring = new Node(j);
ring.key = j;
ring.next = first;
first = ring;
}
last.next = first;
return last;
}
public void suicide()
{
Node reference = circle(A);
while (reference != reference.next) //when there are still
more than 1 person
for (int i = 1; i < B; i++)//you can still execute the B
person
reference = reference.next;
System.out.println( "-R.I.P # "+ reference.next.key );
reference.next = reference.next.next;
System.out.println();
System.out.println("Josephus has to take position ( " +
reference.key + " ) to survive!");
}
}
//===================================================================
JosephusApp
//===================================================================
import java.io.*;
//---------------
class JosephusApp
{
public static void main (String[] args) throws IOException
{
InputStreamReader inStream = new InputStreamReader(System.in);
BufferedReader stdin = new BufferedReader(inStream);
Josephus Josephus = new Josephus();
String inData;
int A;
int B;
System.out.println("Welcome to 'Josephus, a smart jew' problem
solver.");
System.out.println("**************************************************");
System.out.println("How Many Jews want to commit suicide
today?");
inData = stdin.readLine();
A = Integer.parseInt(inData);
if (A <=0)
{
System.out.println("Try a positive number!");
}
else
{
System.out.println();
System.out.println("Eliminate one every :");
inData = stdin.readLine();
B = Integer.parseInt(inData);
System.out.println();
if (B <=0)
{
System.out.println("Try a positive number!");
}
else
{
Josephus.suicide();
}
}
}
}
//===================================================================
THE ERROR
//===================================================================
--------------------Configuration: JDK version 1.3
<Default>--------------------
F:\Josephus.java:35: cannot resolve symbol
symbol : variable A
location: class Josephus
Node reference = circle(A);
^
F:\Josephus.java:37: cannot resolve symbol
symbol : variable B
location: class Josephus
for (int i = 1; i < B; i++)//you can still execute the B
person
^
2 errors
Process completed.
//===================================================================
Can anyone help Please guyz!!??
little change and i took some code from JosephusApp to josephus it is
all ruined and i dono why i ll post everything maybe u can help me ,
anybody please;
Josephus
//===================================================================
class Josephus
{
Node first;
Node last;
Node ring;
Josephus()
{
first = null;
last = null;
ring = null;
}
Node circle(int key)
{
Node first = new Node(key);
Node last = first;
first.key = key;
for (int j = key - 1; j > 0 ; j--)
{
Node ring = new Node(j);
ring.key = j;
ring.next = first;
first = ring;
}
last.next = first;
return last;
}
public void suicide()
{
Node reference = circle(A);
while (reference != reference.next) //when there are still
more than 1 person
for (int i = 1; i < B; i++)//you can still execute the B
person
reference = reference.next;
System.out.println( "-R.I.P # "+ reference.next.key );
reference.next = reference.next.next;
System.out.println();
System.out.println("Josephus has to take position ( " +
reference.key + " ) to survive!");
}
}
//===================================================================
JosephusApp
//===================================================================
import java.io.*;
//---------------
class JosephusApp
{
public static void main (String[] args) throws IOException
{
InputStreamReader inStream = new InputStreamReader(System.in);
BufferedReader stdin = new BufferedReader(inStream);
Josephus Josephus = new Josephus();
String inData;
int A;
int B;
System.out.println("Welcome to 'Josephus, a smart jew' problem
solver.");
System.out.println("**************************************************");
System.out.println("How Many Jews want to commit suicide
today?");
inData = stdin.readLine();
A = Integer.parseInt(inData);
if (A <=0)
{
System.out.println("Try a positive number!");
}
else
{
System.out.println();
System.out.println("Eliminate one every :");
inData = stdin.readLine();
B = Integer.parseInt(inData);
System.out.println();
if (B <=0)
{
System.out.println("Try a positive number!");
}
else
{
Josephus.suicide();
}
}
}
}
//===================================================================
THE ERROR
//===================================================================
--------------------Configuration: JDK version 1.3
<Default>--------------------
F:\Josephus.java:35: cannot resolve symbol
symbol : variable A
location: class Josephus
Node reference = circle(A);
^
F:\Josephus.java:37: cannot resolve symbol
symbol : variable B
location: class Josephus
for (int i = 1; i < B; i++)//you can still execute the B
person
^
2 errors
Process completed.
//===================================================================
Can anyone help Please guyz!!??