Selasa, 14 Mei 2013
array
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package proses5;
import java.util.Scanner;
/**
*
* @author acer
*/
public class Proses5 {
public byte banyak; //property
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Arr arre = new Arr(); //deklarasi Class Arr
arre.Masuk(); //panggil method Masuk dr class Arr
}
}
class Arr
{
public void Masuk()
{
Scanner baca = new Scanner(System.in);
String [] nama; //deklarasi Array
Proses5 pro = new Proses5 (); //deklarasi Class Program
System.out.print("masukkan banyak elemen array = ");
pro.banyak = baca.nextByte(); //input mengunakan property Class program
nama = new String[pro.banyak]; //inisialisasi Array
System.out.println();
//mengisi Array
for (byte i = 0; i<pro.banyak; i++)
{
int s = i+1;
System.out.print("masukkan nama maha siswa ke "+s+" = ");
nama[i] = baca.next();
}
System.out.println();
//menampilkan Array
for (byte i = 0; i<pro.banyak; i++)
{
int s = i+1;
System.out.println("nama maha siswa ke "+s+" adalah "+nama[i]);
}
}
}
// TODO code application logic here
Langganan:
Postingan (Atom)