Jumat, 27 November 2009

Surce-Code Average

package average;

import javax.swing.JOptionPane;

public class Main {

public static void main( String args[] ){
String firstNumber;
String secondNumber;
String threeNumber;
String fourNumber;
String fiveNumber;
int number1;
int number2;
int number3;
int number4;
int number5;
int jumlah;
int average;

firstNumber =
JOptionPane.showInputDialog( "Masukkan nilai Pertama" );

secondNumber =
JOptionPane.showInputDialog( "Masukkan nilai Kedua" );

threeNumber =
JOptionPane.showInputDialog( "Masukkan nilai ketiga" );

fourNumber =
JOptionPane.showInputDialog( "Masukkan nilai keempat" );

fiveNumber =
JOptionPane.showInputDialog( "Masukkan nilai kelima" );

number1 = Integer.parseInt( firstNumber );
number2 = Integer.parseInt( secondNumber );
number3 = Integer.parseInt( threeNumber );
number4 = Integer.parseInt( fourNumber );
number5 = Integer.parseInt( fiveNumber );

jumlah = number1 + number2+number3+number4+number5;
average =(number1 + number2+number3+number4+number5)/5;

JOptionPane.showMessageDialog(null, "Jumlahnya adalah " + jumlah, "Results", JOptionPane.WARNING_MESSAGE );
JOptionPane.showMessageDialog(null, "Rata-ratanya adalah " + average, "Results", JOptionPane.WARNING_MESSAGE );
System.exit( 0 );
}
}

PrintScreen Output Nilai 1

PrintScreen Output Nilai 2

PrintScreen Output Nilai 3

PrintScreen Output Nilai 4

PrintScreen Output Nilai 5

PrintScreen Output Jumlah

Printscreen Output Average

Printscreen Input Average

Jumat, 13 November 2009

flowchart

flowchart output

bilangan berpangkat

SOURCE-CODE

package bil_pangkat;

import java.util.Scanner;

class Main{

public static void main (String[] args)

{

Scanner myScanner= new Scanner (System.in);

int pangkat = 0;

int i = 1;

int total = 0;

System.out.print("Masukkan nilai = ");

pangkat = myScanner.nextInt();

System.out.print("pangkat = ");

while(i <= pangkat)

{

System.out.print("i");

if (i

{

System.out.print("^");

System.out.print("+");

}

total = total+i*i;

i = i+1;

}

System.out.println("^");

System.out.println("total = "+ total);

}

}