INPUTAN BERUPA NUMBER :
import java.io.*;
class zero{
public static void main(String[] args)throws IOException
{
System.out.print("Masukan Jari-jari :");
double p = 3.14;
String temp;
int bil = 0;
double luas = 0;
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader (isr);
temp=br.readLine();
try{
bil = Integer.parseInt(temp);
luas = p*bil*bil;
}
catch(NumberFormatException nfe){
System.exit(1);
}
System.out.println("Luas Lingkaran="+luas);
}
}
INPUTAN BERUPA CHAR :
import java.io.*;
class zero2{
public static void main(String[] args)throws IOException
{
System.out.print("Masukan Character :");
int karakter;
String str =" ";
boolean selesai = false;
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader (isr);
while(!selesai){
try{
karakter = System.in.read();
if (karakter<0 || (char) karakter =='\n')
selesai=true;
else if ((char)karakter !='\r')
str=str+(char) karakter;
}
catch(java.io.IOException e){
System.exit(1);
}
System.out.println("Data yang dimasukkan :"+str);
}
}
}
Langganan:
Posting Komentar (Atom)
Tidak ada komentar:
Posting Komentar