dynamic array
atau biasa disebut array dinamis,adalah array yang nilainya tidak punya jangkauan tetap
ini adalah contoh array dinamis dalam java :
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author matt
*/
import java.io.*;
public class dynamicarray
{
public static void main(String [] args)throws Exception
{
try {
DataInputStream dis = new DataInputStream(System.in);
int [] angka;
int Sumelemen=0;
do{
System.out.print("\n ketik jumlah elemen:");
Sumelemen=Integer.parseInt(dis.readLine());
if (Sumelemen > 0)
{angka = new int [Sumelemen];
for (int i = 0 ; i < Sumelemen; i++)
angka [i]=(int)(Math.random()*100);
System.out.print("Data acak " + Sumelemen + "elemen");
for (int i=0; i<Sumelemen; i++)
System.out.print(angka [i] + "");
}
System.out.println();
}while(Sumelemen > 0);
}catch(Exception e)
{
System.out.println("Error");
}
}
}
ini adalah contoh array dinamis dalam java :
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author matt
*/
import java.io.*;
public class dynamicarray
{
public static void main(String [] args)throws Exception
{
try {
DataInputStream dis = new DataInputStream(System.in);
int [] angka;
int Sumelemen=0;
do{
System.out.print("\n ketik jumlah elemen:");
Sumelemen=Integer.parseInt(dis.readLine());
if (Sumelemen > 0)
{angka = new int [Sumelemen];
for (int i = 0 ; i < Sumelemen; i++)
angka [i]=(int)(Math.random()*100);
System.out.print("Data acak " + Sumelemen + "elemen");
for (int i=0; i<Sumelemen; i++)
System.out.print(angka [i] + "");
}
System.out.println();
}while(Sumelemen > 0);
}catch(Exception e)
{
System.out.println("Error");
}
}
}
Komentar
Posting Komentar