Program penilaian menggunakan array dengan java
import java.util.Scanner;
public class Nilai
{
public static void main(String args [])
{
Scanner ud = new Scanner(System.in);
int n,i=0;
System.out.print("Masukkan jumlah data : ");
n=ud.nextInt();
System.out.println("");
int ti[]= new int [n];
int si[]=new int [n];
int th[]=new int [n];
int jumti[]=new int [n];
int jumsi[]=new int [n];
for(i=0;i<n;i++)
{
System.out.print("Masukkan nilai tahun : ");
th[i]=ud.nextInt();
System.out.print("Masukkan nilai ti : ");
ti[i]=ud.nextInt();
System.out.print("Masukkan nilai si : ");
si[i]=ud.nextInt();
System.out.println("");
}
System.out.println("Th/jur\tTI\tSI");
for(i=0;i<n;i++)
{
System.out.println(th[i]+"\t"+ti[i]+"\t"+si[i]);
jumti[i]=jumti[i]+ti[i];
jumsi[i]=jumsi[i]+si[i];
}
System.out.println("total\t"+jumti[i]+"\t"+jumsi[i]);
}
}
program diatas merupakan contoh program untuk input data nilai dengan array satu dimensi.
public class Nilai
{
public static void main(String args [])
{
Scanner ud = new Scanner(System.in);
int n,i=0;
System.out.print("Masukkan jumlah data : ");
n=ud.nextInt();
System.out.println("");
int ti[]= new int [n];
int si[]=new int [n];
int th[]=new int [n];
int jumti[]=new int [n];
int jumsi[]=new int [n];
for(i=0;i<n;i++)
{
System.out.print("Masukkan nilai tahun : ");
th[i]=ud.nextInt();
System.out.print("Masukkan nilai ti : ");
ti[i]=ud.nextInt();
System.out.print("Masukkan nilai si : ");
si[i]=ud.nextInt();
System.out.println("");
}
System.out.println("Th/jur\tTI\tSI");
for(i=0;i<n;i++)
{
System.out.println(th[i]+"\t"+ti[i]+"\t"+si[i]);
jumti[i]=jumti[i]+ti[i];
jumsi[i]=jumsi[i]+si[i];
}
System.out.println("total\t"+jumti[i]+"\t"+jumsi[i]);
}
}
program diatas merupakan contoh program untuk input data nilai dengan array satu dimensi.
Komentar
Posting Komentar