Syntax Dasar Java

Contoh Syntax Dasar dalam Java

package javaapplication1;
import java.util.Scanner;

/**
*
* @author VAIO
*/
public class Main {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner input= new Scanner(System.in);
String a;
int c;
int d;
int e;
int total;
int rata;

//Inputan
System.out.print(“Masukkan nama anda = “);
a=input.next();
System.out.print(“Masukkan nilai 1= “);
c=input.nextInt();
System.out.print(“Masukkan nilai 2= “);
d=input.nextInt();
System.out.print(“Masukkan nilai 3= “);
e=input.nextInt();

//proses
total=c+d+e;
rata=(c+d+e)/3;
//Output
System.out.print(“Nama anda adalah = “+a);
System.out.print(“\nNilai 1 = “+c);
System.out.print(“\nNilai 2 = “+d);
System.out.print(“\nNilai 3 = “+e);
System.out.print(“\nTotal nilai anda = “+total);
System.out.print(“\nRata-rata anda = “+rata);

}

}

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s