import java.io.*;
class TanpaArray
{
public static void main(String[]args)
{
int max= Integer.MIN_VALUE;
int min= Integer.MIN_VALUE;
int n=1, x, jml=0;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Masukkan data ke-"+n+":");
try
{
while((x=Integer.parseInt(br.readLine()))!=0)
{
if(x>max) max=x;
if(x<min) min=x;
jml+=x;
System.out.println("Masukkan angka ke-"+(++n)+"[ketik 0 untuk STOP]:");
}
}
catch(Exception e)
{
}
double rata2=(double) jml/(n-1);
System.out.println("Total:"+jml);
System.out.println("Rata-rata:"+rata2);
System.out.println("Angka terkecil:"+min);
System.out.println("Angka terbesar::"+max);
}
}
Output
class TanpaArray
{
public static void main(String[]args)
{
int max= Integer.MIN_VALUE;
int min= Integer.MIN_VALUE;
int n=1, x, jml=0;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Masukkan data ke-"+n+":");
try
{
while((x=Integer.parseInt(br.readLine()))!=0)
{
if(x>max) max=x;
if(x<min) min=x;
jml+=x;
System.out.println("Masukkan angka ke-"+(++n)+"[ketik 0 untuk STOP]:");
}
}
catch(Exception e)
{
}
double rata2=(double) jml/(n-1);
System.out.println("Total:"+jml);
System.out.println("Rata-rata:"+rata2);
System.out.println("Angka terkecil:"+min);
System.out.println("Angka terbesar::"+max);
}
}
Output
No comments:
Post a Comment