Mencari nilai maksimum dari bilangan random 1 – 100


import javax.swing.*;
public class Maksimum
{
public static void main (String[ ] args)
{
int[ ] nilai = new int [10];
int nilaiMaks;

// Memperoleh bilangan random
for (int i = 0; i < 10; i++)
nilai[i] = (int) (100 * Math.random());

// Mencari maksimum
nilaiMaks = nilai[0];
for (int i = 0; i nilaiMaks)
nilaiMaks = nilai[i];
}
System.out.println(“Nilai maksimum = ” + nilaiMaks);
}
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s