Soal :
Buatlah Program Mencari Nilai Maksimum dari 3 bilangan yang di inputkan.
Jawab :
package algoritma;
import java.io.*;
public class nilaimaksimaldari3data {
public static void main(String[] args){
BufferedReader dataKata =new BufferedReader (new InputStreamReader (System.in));
DataInputStream dataAngka = new DataInputStream (System.in);
int data1=0;
int data2=0;
int data3=0;
int maks=0;
System.out.println("masukkan bilangan ke 1");
try {
data1=Integer.parseInt(dataAngka.readLine());
} catch (IOException e) {
System.out.println("Terjadi Error");}
System.out.println("masukkan bilangan ke 2");
try {
data2=Integer.parseInt(dataAngka.readLine());
} catch (IOException e) {
System.out.println("Terjadi Error");}
System.out.println("masukkan bilangan ke 3");
try {
data3=Integer.parseInt(dataAngka.readLine());
} catch (IOException e) {
System.out.println("Terjadi Error");}
if(data1>data2){maks=data1;}else
{maks=data2;}
if(data3>maks){maks=data3;}
System.out.println("bilangan maksimal="+maks);
}
}
Screenshoot :
Program Mencari Nilai Maksimum dengan Java
This entry was posted on Saturday, 19 September 2015. You can follow any responses to this entry through the RSS 2.0. You can leave a response.
Powered by Blogger.