i have an error of line 40 illegal start of expression
and line 73 class interface,or enum expected.

im making a 10 random numbers
display them
determine the largest and the smallest number of 10 random numbers

thanks..

import java.util.Random;

/** Generate random integers in a certain range. */
public final class RandomRange 
{
  
  public static final void main(String... aArgs){
    log("Generating random integers in the range 1..10.");
    
    int START = 1;
    int END = 10;
    Random random = new Random();
    for (int idx = 1; idx <= 10; ++idx)
    {
      showRandomInteger(START, END, random);
    }
    
    log("Done.");
  }
  
  private static void showRandomInteger(int aStart, int aEnd, Random aRandom)
  {
    if ( aStart > aEnd )
     {
      throw new IllegalArgumentException("Start cannot exceed End.");
    }
    //get the range, casting to long to avoid overflow problems
    long range = (long)aEnd - (long)aStart + 1;
    // compute a fraction of the range, 0 <= frac < range
    long fraction = (long)(range * aRandom.nextDouble());
    int randomNumber =  (int)(fraction + aStart);    
    log("Generated : " + randomNumber);
  }
  
  private static void log(String aMessage)
  {
    System.out.println(aMessage);
    {
    
    static int GetMax(int[] numbers)

    int maximum = numbers[0];

    for (int i = 1; i < numbers.Length; i++)
    {
        maximum = Math.Max(maximum, numbers[i]);
    }

    return maximum;
}

static int GetMin(int[] numbers)
{
    int minimum = numbers[0];

    for (int i = 1; i < numbers.Length; i++)
    {
        minimum = Math.Min(minimum, numbers[i]);
    }

    return minimum;
}

static void Main()
{
    int[] numbers = { 32, 17, 45,22,56,79,45,90, 10, 5 };
    int max = GetMax(numbers);
    int min = GetMin(numbers);
    Console.WriteLine(max);
    Console.WriteLine(min);
}
  }
}

And where is that error? Do not expect that people will do it instead of you. Put some effort in it...

Edited 5 Years Ago by peter_budo: n/a

This article has been dead for over six months. Start a new discussion instead.