java - Syntax Error, insert ". class" to complete expression 5 -
import java.util.random; public class randomwalker { public static void main(string[] args) { int n = integer.parseint(args[0]); int x = 0; int y = 0; int = 0; int distance = 0; random rand = new random(); system.out.println("(" + "0" + "," + "0" + ")"); while (i<n) { if (i=n) int val = rand.nextint(4) + 1; = i+1; if (val==1) { y = y+1; if (i = n - 1) { distance = ((math.pow((x-0), 2)) + (math.pow((y-0), 2))); system.out.println("squared " + "distance " + "= " + distance); } else { system.out.println("(" + x + "," + y + ")"); } } if (val==2) { x = x+1; if (i = n - 1) { distance = ((math.pow((x-0), 2)) + (math.pow((y-0), 2))); system.out.println("squared " + "distance " + "= " + distance); } else { system.out.println("(" + x + "," + y + ")"); } } if (val==3) { y = y-1; if (i = n - 1) { distance = ((math.pow((x-0), 2)) + (math.pow((y-0), 2))); system.out.println("squared " + "distance " + "= " + distance); } else { system.out.println("(" + x + "," + y + ")"); } } if (val==4) { x = x-1; if (i = n - 1) { distance = ((math.pow((x-0), 2)) + (math.pow((y-0), 2))); system.out.println("squared " + "distance " + "= " + distance); } else { system.out.println("(" + x + "," + y + ")"); } } } } }
hey guys trying make code relies on random number being generated between 1 , 4 , getting error above. working fine before added other stuff didn't involve random number generation.
fix huge amount of syntax errors type mismatches first, , follow elliott's advice on forgotten = in of if statements involving i , n, missing curly brace after it. there's missing curly brace @ end of program.
by way, forgot cast expression ((math.pow((x-0), 2)) + (math.pow((y-0), 2))) int. why - 0, way?
after that, problem disappears.
please debug as possible ability, before asking.
fixed code (i didn't run it, though)
import java.util.random; public class randomwalker { public static void main(string[] args) { int n = integer.parseint(args[0]); int x = 0; int y = 0; int = 0; int distance = 0; random rand = new random(); system.out.println("(" + "0" + "," + "0" + ")"); while (i<n) { if (i==n) { int val = rand.nextint(4) + 1; = i+1; if (val==1) { y = y+1; if (i == n - 1) { distance = (int)((math.pow((x-0), 2)) + (math.pow((y-0), 2))); system.out.println("squared " + "distance " + "= " + distance); } else { system.out.println("(" + x + "," + y + ")"); } } if (val==2) { x = x+1; if (i == n - 1) { distance = (int)((math.pow((x-0), 2)) + (math.pow((y-0), 2))); system.out.println("squared " + "distance " + "= " + distance); } else { system.out.println("(" + x + "," + y + ")"); } } if (val==3) { y = y-1; if (i == n - 1) { distance = (int)((math.pow((x-0), 2)) + (math.pow((y-0), 2))); system.out.println("squared " + "distance " + "= " + distance); } else { system.out.println("(" + x + "," + y + ")"); } } if (val==4) { x = x-1; if (i == n - 1) { distance = (int)((math.pow((x-0), 2)) + (math.pow((y-0), 2))); system.out.println("squared " + "distance " + "= " + distance); } else { system.out.println("(" + x + "," + y + ")"); } } } } } }
Comments
Post a Comment