kode program:
/*
* To change
this template, choose Tools | Templates
* and open the
template in the editor.
*/
package
menentukanbilterbesardanterkceildarinbuahbil;
import java.util.*;
/**
*
* @author
BERLIAN PUTRI
*/
public class Main {
/**
* @param
args the command line arguments
*/
public
static void main(String[] args) {
//
TODO code application logic here
int n,i;
System.out.print("MENENTUKAN BILANGAN TERKECIL DAN TERBESAR DARI
SEJUMLAH BILANGAN");
System.out.print("\n******************************************************************");
System.out.print("\nMasukkan Jumlah bilangan yang akan
dimasukkan:");
Scanner
j=new Scanner (System.in);
n=j.nextInt();
int
x[]=new int[n];
for(i=0;i<=n-1;i++)
{
System.out.print("\nBilangan ke "+(i+1)+":");
x[i]=j.nextInt();
}
int
y=x[0];
for(i=0;i<=n-1;i++)
{
if(
y>= x[i])
y=x[i];
}
System.out.println("\nTerkecil
adalah="+y);
int z=x[0];
for(i=0;i<=n-1;i++)
{
if(
z<= x[i])
z=x[i];
}
System.out.println("Terbesar adalah="+z);
}
}
Output :
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- materikuliah -->
<ins class="adsbygoogle"
style="display:block"
data-ad-client="ca-pub-4341784261489537"
data-ad-slot="9822872809"
data-ad-format="auto"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
<!-- materikuliah -->
<ins class="adsbygoogle"
style="display:block"
data-ad-client="ca-pub-4341784261489537"
data-ad-slot="9822872809"
data-ad-format="auto"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
No comments:
Post a Comment