Program Struktur Kontrol

 if

import java.io.*;

class BR{

public static void main (String[]args){

String input;

int num;

DataInputStream in = new DataInputStream(System.in);

System.out.println(“Masukan bilangan anda : “);

try{

input = in.readLine();

num = Integer.parseInt(input);

if (num > 0)

System.out.println(num+ “\tBilangan Positif”);

if (num < 0)

System.out.println(num+ “\tBilangan Negatif”);

}catch (Exception e){

Baca pos ini lebih lanjut

Iklan

Inputan Keyboard dengan menggunakan JOptionPane

import javax.swing.JOptionPane;
public class jp_option{
public static void main (String[]args){

String name, kelas;

name = JOptionPane.showInputDialog(“Please Enter your name”);
kelas = JOptionPane.showInputDialog(“Semester Berapa” +name);

String msg = “Hallo” + name + “!” + “\n” + “ow semester,,,,” + “!” + kelas + “!” + “\n” + “Semoga berhasil ya,,,,” + “!”;

JOptionPane.showMessageDialog(null, msg);
}

}

Program Inputan Keyborad dengan menggunakan Bufferedreader

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class soal_pertama{
public static void main (String args[]){

String a;
String b;

try{
System.out.println(“Masukan nama anda :”);
BufferedReader apa = new BufferedReader (new InputStreamReader (System.in));
a = “”;
a = apa.readLine();

System.out.println(“Masukan alamat anda :”);
BufferedReader opo = new BufferedReader (new InputStreamReader (System.in));
b =””;
b = opo.readLine();

System.out.println(“Nama anda adalah =” +a);
System.out.println(“Alamat anda adalah =” +b);

}catch (IOException e){
System.out.println(“Error!”);

}
}
}