import jeliot.io.*;
import java.util.Scanner;
public class MyClass {
public static void main() {
rumus tes = new rumus();
tes.masukan();
tes.kluaran();
return 0;
}
}
public class rumus
{
public final void masukan()
{
System.out.print("program menghitung rumus : 1-(1/2)+(1/3)-(1/4)+...+(1/n)");
System.out.print("\n");
System.out.print("\n");
System.out.print("masukkan nilai a : ");
a = Input.nextInt();
jumlah =0;
total =0;
rumus =-1;
}
public final void kluaran()
{
for(int j =1; j<=a; j++)
{
rumus =(rumus*(-1));
total =rumus/j;
jumlah+=total;
if(j ==1)
{
System.out.print("(");
System.out.print(total);
System.out.print(")");
}
if(j>1)
{
System.out.print("+(");
System.out.print(total);
System.out.print(")");
}
}
System.out.print("\n");
System.out.print("\n");
System.out.print("hasilnya : ");
System.out.print(jumlah);
}
private int a;
private double rumus;
private double jumlah;
private double total;
}
import java.util.Scanner;
public class MyClass {
public static void main() {
rumus tes = new rumus();
tes.masukan();
tes.kluaran();
return 0;
}
}
public class rumus
{
public final void masukan()
{
System.out.print("program menghitung rumus : 1-(1/2)+(1/3)-(1/4)+...+(1/n)");
System.out.print("\n");
System.out.print("\n");
System.out.print("masukkan nilai a : ");
a = Input.nextInt();
jumlah =0;
total =0;
rumus =-1;
}
public final void kluaran()
{
for(int j =1; j<=a; j++)
{
rumus =(rumus*(-1));
total =rumus/j;
jumlah+=total;
if(j ==1)
{
System.out.print("(");
System.out.print(total);
System.out.print(")");
}
if(j>1)
{
System.out.print("+(");
System.out.print(total);
System.out.print(")");
}
}
System.out.print("\n");
System.out.print("\n");
System.out.print("hasilnya : ");
System.out.print(jumlah);
}
private int a;
private double rumus;
private double jumlah;
private double total;
}
No comments:
Post a Comment