Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to store a String in an Int Array?
    text
    copied!<p>I have a question. My teacher has asked as part of my assignment, to replace all 0's (zero's) with asterisk's (*'s) in my array. </p> <p>This is an example of the output of my program:</p> <pre><code>Best Tour: #31 Number of Moves: 57 ===================================== 1 16 57 6 0 36 47 0 56 7 0 3 46 5 32 37 17 2 15 8 33 30 35 48 14 55 22 45 4 49 38 31 23 18 13 50 9 34 29 42 54 51 24 21 44 41 26 39 0 12 19 52 25 10 43 28 0 53 0 11 20 27 40 0 ===================================== </code></pre> <p>Basically, everywhere there is a zero, he wants it to instead show an asterisk. This is an int array. I have tried creating a String with the value " * ". Then I tried parsing it into an int, but I get:</p> <pre><code>Exception in thread "main" java.lang.NumberFormatException: For input string: "*" </code></pre> <p>Any other suggestions I should try out? </p> <hr> <p>Thank you guys so much! I was just not looking at things correctly. After reading some comments, I realized that it didn't make much sense to try to change the zero's to asterisk's in the array itself. </p> <p>So I modified my printArray() method, so that in any instance of 0, it will print *; else it just prints whatever number is supposed to be there.</p> <p>Here is what it looks like now:</p> <pre><code>Best Tour: #45 Number of Moves: 58 ===================================== 1 42 13 18 31 44 27 * 58 11 32 43 14 17 30 45 41 2 57 12 19 26 15 28 56 33 10 5 16 29 46 * 3 40 55 34 9 20 25 50 * 37 4 53 6 49 22 47 39 54 35 8 21 24 51 * 36 * 38 * 52 7 48 23 ===================================== </code></pre> <p>You all are so helpful, and very quick I might add! Thank you so much!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload