Note that there are some explanatory texts on larger screens.

plurals
  1. POPrinting Arrays from a method in Java
    primarykey
    data
    text
    <p>I am not sure how print the values of arrays when called from methods, I have to solve these:</p> <p>1- create an array consisting of 100 random integers in the range 100 to 500, including the end points. (This part i am OK, the next 2 points i am quite doubtful on how solve it)</p> <p>2- make a method to print the array, 5 numbers per line, with a space between each. (I got almost everything right except I don't know how Return the value, I tried <code>return System.outprint.....</code> but didn't work either anyway the method has a void some made it worse)</p> <p>3- make a method to print the smallest number in the array. (this i got no clue how to do it!)</p> <ol> <li>make a method to print the sum of all numbers in the array. (This I don't quite see why the "return ad;" is not working as most of the code seems correct to me at least hehe)</li> </ol> <p>This is my code so far:</p> <pre><code>package randomhundred; import java.util.Arrays; public class RandomHundred { private static int[] rand; public static void main(String[] args) { // TODO code application logic here //setting the 100 array /* PART I*/ int rand [] = new int [100]; int numb; for(int i=0; i&lt;rand.length; i++){ numb = (int) (100 + (Math.random() * ( (500 - 100) + 1))); numb = rand[i]; } } /* PART II */ public static void arai (){ for (int i=0; i&lt;100; i++){ System.out.print(rand[i] + " "); if( i%5 == 0){ System.out.println(); } else{ System.out.print(rand[i] + " "); } } /** PART IV */ public static int suma(){ int ad; for(int i=0; i&lt;100; i++){ ad =+rand[i]; } return ad; } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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