import java.util.Scanner;

public class sfera {

public static void main(String[] args) {

//Langkah 1:Baca input dari pengguna
System.out.print("Masukkan nilai jejari: ");
Scanner input = new Scanner(;
final double PI = 3.14159;
double jejari = input.nextDouble();
double luas;
double isipadu;
//Langkah 2: kira luas
luas = 4 * PI * jejari * jejari;
//Langkah 3: kira isipadu
isipadu = (4.0/3.0) * PI * jejari * jejari * jejari;
//Langkah 4: Papar nilai luas dan isipadu
System.out.println("Luas : " + luas);
System.out.println("Isipadu : " + isipadu);



please help me...answer must in two decimal places?

where i should put this inside my program?

import java.textDecimalFormat;
double d = 8.9;
DecimalFormatdFormat=new Decimal Format("0.00");
Stringformatted String =dFormat.format (d);

depends where you want to access the formatter. If youonly want to access the formater in your main method then put it there or if you want it to access it in your whole class put it outside your main method.

The only advantage would be to be able to use it in all the methods of your class.

since theres only one method which is the main method then there is not an advantage. You can also use printF to format your output.

This article has been dead for over six months. Start a new discussion instead.