Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have the following java-program, that creates a random walk starting at (0,0) and continuing until x or y is greater than abs(n). First: I

I have the following java-program, that creates a random walk starting at (0,0) and continuing until x or y is greater than abs(n).

First: I get an error, when I try closing the Scanner by inserting "reader.close(); " in line 28. It says "Unreachable code". How can I fix that?

Second: Is it possible to create a different colour for the StdDraw.point when it reaches a point on one of the edges "n+1" or "n-1" ?

image text in transcribed

image text in transcribed

1 import java.util.*; 3 public class RandomWalkf 4 5 public static void main(String args)I 6 Scanner readernew Scanner(System. in); System.out.print("Enter the size of grid: "); // Taking input of the size of the grid 10 do [ try int n = reader.nextInt(); if(n 0) walk(n); System.out.printlnC"nEnter the size of grid: "); // Makes sure the program catches strings as an error. Prints error message and clears Scanner catch (InputMismatchException e) f 23 24 25 26 27 System.out.println("Input is not an integer. Please enter a positive (0 to terminate): "; reader.nextLineO } while (true); reader.slse) 28 29 30 31 public static void givePos(int X, int ) 32 //A function to print the position System.out, format(" Position-(Xd %d) ",X,Y); , 34

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Programming The Perl DBI Database Programming With Perl

Authors: Tim Bunce, Alligator Descartes

1st Edition

1565926994, 978-1565926998

More Books

Students also viewed these Databases questions

Question

What is the relationship between humans?

Answered: 1 week ago

Question

What is the orientation toward time?

Answered: 1 week ago