Arama butonu
Bu konudaki kullanıcılar: 1 misafir
2
Cevap
396
Tıklama
0
Öne Çıkarma
Java basit sorum yardım
F
13 yıl
Yüzbaşı
Konu Sahibi

Create a new project Lab04c. Your program should take a number as an input, and calculate the Harmonic Sum of that number. Harmonic Sum formula is given below.


Sample run is shown below.

Enter a number: 1
Harmonic sum of 1.0 is 1.0.
Another sample run:

Enter a number: 10
Harmonic sum of 10.0 is 2.9289682539682538





YUKARIDAKİ PROGRAMI YAPMAYA CALISIYORUM HARMONİK ORTALAMA ALICAK. Yazdığım kod aşağıda . Variable answer ve cevap not have been initialized error u veriyor ne yapmalıyım



import java.util.Scanner;
/**
* Lab02c - Program is to illustrate basic operators
*
* @author yourName
* @version 1.00 2012/10/10
*/
public class Lab04c
{
public static void main(String[] args)
{
// CONSTANTS


// VARIABLES

int n;
int numb1=1;
int m=0;
int cevap;
int c=1;
int answer;

// PROGRAM CODE
Scanner scan = new Scanner(System.in);


System.out.println("Enter a number");
n=scan.nextInt();

while(n>m)
{
cevap=(1/c);
c++;
m++;


}
answer+=cevap;
System.out.println(answer);

}
} // end of class Lab02c