Need help on solving this Arrays problem using java

27 Views Asked by At

Make an array of integer (score) with 10 members. Randomize the content with value between 0-100. For each of the member of array, visualize the value using “-” for each ten. For example: score[0] = 55 will be visualized as “-----" (Using Java).

public class w9lab1 {
    public static void main(String args[]) {
      double[] temperature = new double[7];
      for (int i = 0; i < 7; i++) {
           temperature[i] = Math.random()*100;
      }
      for (int i = 0; i < 7; i++) {
           System.out.println(temperature[i]);
      }
     
      double totalTemperature = 0;
      for (int i = 0; i < 7 ; i++) {
            totalTemperature += temperature[i];
      }
      double maxTemperature = temperature[0];
      for (int i = 1; i < 7; i++){
            if (temperature[i] > maxTemperature){
            maxTemperature = temperature[i];
        }
      }
        System.out.println("Temperatur maximum adalah " + maxTemperature);
    }
}
1

There are 1 best solutions below

0
bighugedev On
import java.util.Random;
import java.util.Arrays;

public class w9lab1 {
    public static void main(String[] args) {
        Random random = new Random();
        int[] score = new int[10];
        for (int i = 0; i < score.length; i++) {
            score[i] = random.nextInt(101);
            for (int n = 1; n <= score[i] / 10; n++)
                System.out.print('-');
            System.out.println();
        }
        System.out.println(Arrays.toString(score));
    }
}