Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 9

TUGAS MEMBUAT PROGRAM

MENCARI NILAI TERBESAR


DAN MENENTUKAN NILAI
GANJIL GENAP (PBO)

Disusun Oleh :
Dwi Rahmadi

10.MI.0019

AMIK PGRI KEBUMEN


TA 2012/2013

Mencari Nilai Terbesar dengan JOptionPane


import javax.swing.JOptionPane;
/**
*
* @author Dwi Rahmadi
*/
public class Array {
public static void main (String [] args) {
int maks = 0;
int option = JOptionPane.YES_OPTION;

String nim = JOptionPane.showInputDialog ("Masukkan NIM anda");


String nama = JOptionPane.showInputDialog ("Masukkan Nama anda");

while (option == JOptionPane.YES_OPTION){


String data = JOptionPane.showInputDialog ("Masukkan nilai anda");

int nilai = Integer.parseInt (data);


option = JOptionPane.showConfirmDialog(null, " Masih ada data lagi ?");

if (maks < nilai) {


maks = nilai;
}
}
JOptionPane.showMessageDialog (null, "NIM : " + nim +
"\nNama : " + nama +

"\nNilai tertinggi : " + maks);


}
}

Screenshot

Mencari Nilai Terbesar dengan BufferedReader


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
/**
*
* @author ACER
*/
public class buffer {

public static void main(String [] args){


BufferedReader m = new BufferedReader(new
InputStreamReader(System.in));

String Input = "";


//int i = 0;
int a = 0;
int tampung[] = new int[10];

for (int i=0;i<tampung.length;i++){


try{
System.out.println("Masukkan Nilai Anda :");
Input = m.readLine();
tampung[i] = Integer.parseInt(Input);
if (tampung[i] > a) a = tampung[i];
}catch(IOException e){
System.out.println("Ada Kesalahan Program");
}
}

System.out.println("Angka Terbesar Anda adalah:"+ a );


}
}

Mencari Nilai Ganjil Genap dengan BufferedReader


import java.util.Scanner;

/**
*
* @author ACER
*/
public class tugas {
public static void main (String [] args) {
int awal, akhir, data;
Scanner dataInput = new Scanner(System.in);
System.out.print("Masukkan angka awal : ");
awal = dataInput.nextInt();
System.out.print("Masukkan angka akhir : ");
akhir = dataInput.nextInt();
System.out.println("========================");
System.out.print("Bilangan Genap : ");
for (int i = awal; i <= akhir; i++) {
if (i % 2 == 0) {
System.out.print(i + " ");
}
}
System.out.println();
System.out.print("Bilangan Ganjil : ");
for (int i = awal; i <= akhir; i++) {
if (i % 2 == 1) {
System.out.print(i + " ");
}
}
}
}

Flowchart
Mencari Nilai Terbesar

Mencari Nilai Ganjil dan Genap

You might also like