Jumat, 13 November 2009

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);

}

}

Tidak ada komentar:

Posting Komentar