Sunday, September 28, 2014

Array Mahasiswa Dengan Scanner (Method)

5:29 AM Posted by beckti'velu No comments
package modif.array;

import java.util.Scanner;

public class ModifArray {
    public static String [] nrp = new String [100];
    public static String [] nama = new String [100];
    public static String [] nilai = new String [100];
    public static int data;

 
    public static void insertArray () {
    Scanner input = new Scanner(System.in);
    System.out.print("Masukkan Banyaknya Data : ");
    data = input.nextInt();
    for(int i=1;i<=data;i++){
    System.out.print("\tMasukkan NRP    : ");
    nrp[i] = input.next();
    System.out.print("\tMasukkan Nama   : ");
    nama[i] = input.next();
    System.out.print("\tMasukkan Nilai  : ");
    nilai[i] = input.next();
        }
    }
 
    public static void cetakArray () {
     System.out.println("| No | NRP\t| Nama\t\t| Nilai|");
     System.out.println("========================================");
     for(int i=1;i<=data;i++){
     System.out.print("| "+i+"  | "+nrp[i]+"\t| "+nama[i]+"\t        | "+nilai[i]+"   |");
     System.out.println(" ");}
     System.out.println("========================================");
    }

    public static void main(String[] args) {
        insertArray();
        cetakArray();
    }
 
}

0 comments:

Silahkan Tinggalkan Komentar Anda