Senin, 27 Mei 2013

array

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package arrayfinthaaa;

import java.util.Scanner;

/**
 *
 * @author Samsung1
 * 1
 */
public class Arrayfinthaaa
{
public byte banyak;
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args)
    {
        // TODO code application logic here
        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
Arrayfinthaaa pro = new Arrayfinthaaa();  //deklarasi Class Program

System.out.print("jumlah array = ");
pro.banyak = baca.nextByte(); //input mengunakan property Class program

nama = new String[pro.banyak]; //inisialisasi Array

System.out.println();
System.out.println("memasukkan nilai");


//mengisi Array
for (byte i = 0; i<pro.banyak; i++)
{

System.out.print("nilai angka ");
nama[i] = baca.next();
}

System.out.println();
System.out.println("membaca nilai");

//menampilkan Array

System.out.println("membaca nilai ");
for (byte i = 0; i<pro.banyak; i++)
{
int s = i+1;
System.out.println("nilai angka "+nama[i]);
}
}
}   

Tidak ada komentar:

Posting Komentar