Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link
  1. +1 to @David Harkness and here is an example:

     final double original = 123456789123456789.0;
     double d = original;
     d = d + 1.000; // or d++
     System.out.println(d == original); // true
     System.out.printf("%f%n", original); // 123456789123456784,000000
     System.out.printf("%f%n", d);        // 123456789123456784,000000
    

And two references:

- [Why not use Double or Float to represent currency?][1]
- *Effective Java, 2nd Edition, Item 48: Avoid float and double if exact answers are required*
if (x % multiplier == 0) {
    primeLogger = primeLogger + 1.000;
} else {
    primeLogger = primeLogger + 0.000;
}

The else branch seems superfluous, I guess you could remove it:

    if (x % multiplier == 0) {
        primeLogger = primeLogger + 1.000;
    }
    
  1.   //first the class is declared
      public class startListingPrimeNumbers {
    

Later you'll find that comments like this one are just noise. It says nothing more than the code already does, it's obvious from the code itself that it's a class declaration, so I'd remove it. (Clean Code by Robert C. Martin: Chapter 4: Comments, Noise Comments)

1.

double multiplier;
...
for (multiplier = 1.000; multiplier <= (x); multiplier = multiplier + 1.000) {

The multiplier could be declared in the for loop.

    for (double multiplier = 1.000; multiplier <= (x); multiplier = multiplier + 1.000) {

(Effective Java, Second Edition, Item 45: Minimize the scope of local variables)

  1. Class names should be nouns, instead of verbs and the first letter should be uppercase:

Class and Interface Type Names

Names of class types should be descriptive nouns or noun phrases, not overly long, in mixed case with the first letter of each word capitalized.

Source: The Java Language Specification, Java SE 7 Edition, 6.1 Declarations

PrimeGenerator could be a good name for this class.

  1. +1 to @David Harkness and here is an example:

     final double original = 123456789123456789.0;
     double d = original;
     d = d + 1.000; // or d++
     System.out.println(d == original); // true
     System.out.printf("%f%n", original); // 123456789123456784,000000
     System.out.printf("%f%n", d);        // 123456789123456784,000000
    

And two references:

- [Why not use Double or Float to represent currency?][1]
- *Effective Java, 2nd Edition, Item 48: Avoid float and double if exact answers are required*
if (x % multiplier == 0) {
    primeLogger = primeLogger + 1.000;
} else {
    primeLogger = primeLogger + 0.000;
}

The else branch seems superfluous, I guess you could remove it:

    if (x % multiplier == 0) {
        primeLogger = primeLogger + 1.000;
    }
    
  1.   //first the class is declared
      public class startListingPrimeNumbers {
    

Later you'll find that comments like this one are just noise. It says nothing more than the code already does, it's obvious from the code itself that it's a class declaration, so I'd remove it. (Clean Code by Robert C. Martin: Chapter 4: Comments, Noise Comments)

1.

double multiplier;
...
for (multiplier = 1.000; multiplier <= (x); multiplier = multiplier + 1.000) {

The multiplier could be declared in the for loop.

    for (double multiplier = 1.000; multiplier <= (x); multiplier = multiplier + 1.000) {

(Effective Java, Second Edition, Item 45: Minimize the scope of local variables)

  1. Class names should be nouns, instead of verbs and the first letter should be uppercase:

Class and Interface Type Names

Names of class types should be descriptive nouns or noun phrases, not overly long, in mixed case with the first letter of each word capitalized.

Source: The Java Language Specification, Java SE 7 Edition, 6.1 Declarations

PrimeGenerator could be a good name for this class.

  1. +1 to @David Harkness and here is an example:

     final double original = 123456789123456789.0;
     double d = original;
     d = d + 1.000; // or d++
     System.out.println(d == original); // true
     System.out.printf("%f%n", original); // 123456789123456784,000000
     System.out.printf("%f%n", d);        // 123456789123456784,000000
    

And two references:

- [Why not use Double or Float to represent currency?][1]
- *Effective Java, 2nd Edition, Item 48: Avoid float and double if exact answers are required*
if (x % multiplier == 0) {
    primeLogger = primeLogger + 1.000;
} else {
    primeLogger = primeLogger + 0.000;
}

The else branch seems superfluous, I guess you could remove it:

    if (x % multiplier == 0) {
        primeLogger = primeLogger + 1.000;
    }
    
  1.   //first the class is declared
      public class startListingPrimeNumbers {
    

Later you'll find that comments like this one are just noise. It says nothing more than the code already does, it's obvious from the code itself that it's a class declaration, so I'd remove it. (Clean Code by Robert C. Martin: Chapter 4: Comments, Noise Comments)

1.

double multiplier;
...
for (multiplier = 1.000; multiplier <= (x); multiplier = multiplier + 1.000) {

The multiplier could be declared in the for loop.

    for (double multiplier = 1.000; multiplier <= (x); multiplier = multiplier + 1.000) {

(Effective Java, Second Edition, Item 45: Minimize the scope of local variables)

  1. Class names should be nouns, instead of verbs and the first letter should be uppercase:

Class and Interface Type Names

Names of class types should be descriptive nouns or noun phrases, not overly long, in mixed case with the first letter of each word capitalized.

Source: The Java Language Specification, Java SE 7 Edition, 6.1 Declarations

PrimeGenerator could be a good name for this class.

example fixed
Source Link
palacsint
  • 30.3k
  • 9
  • 81
  • 157
  1. +1 to @David Harkness and here is an example:

     Enterfinal expression:double 1.03-0original = 123456789123456789.420;
     Expression:double 1.03-0.42d = original;
     Preparedd expression:= d + 1.03-0.42
    000; Solving// expression:or 1d++
     System.03-0out.42
    println(d Solving== expression:original); 0.6100000000000001// true
     Answer:System.out.printf("%f%n", 0original); // 123456789123456784,000000
     System.6100000000000001out.printf("%f%n", d);        // 123456789123456784,000000
    

And two references:

- [Why not use Double or Float to represent currency?][1]
- *Effective Java, 2nd Edition, Item 48: Avoid float and double if exact answers are required*
if (x % multiplier == 0) {
    primeLogger = primeLogger + 1.000;
} else {
    primeLogger = primeLogger + 0.000;
}

The else branch seems superfluous, I guess you could remove it:

    if (x % multiplier == 0) {
        primeLogger = primeLogger + 1.000;
    }
    
  1.   //first the class is declared
      public class startListingPrimeNumbers {
    

Later you'll find that comments like this one are just noise. It says nothing more than the code already does, it's obvious from the code itself that it's a class declaration, so I'd remove it. (Clean Code by Robert C. Martin: Chapter 4: Comments, Noise Comments)

1.

double multiplier;
...
for (multiplier = 1.000; multiplier <= (x); multiplier = multiplier + 1.000) {

The multiplier could be declared in the for loop.

    for (double multiplier = 1.000; multiplier <= (x); multiplier = multiplier + 1.000) {

(Effective Java, Second Edition, Item 45: Minimize the scope of local variables)

  1. Class names should be nouns, instead of verbs and the first letter should be uppercase:

Class and Interface Type Names

Names of class types should be descriptive nouns or noun phrases, not overly long, in mixed case with the first letter of each word capitalized.

Source: The Java Language Specification, Java SE 7 Edition, 6.1 Declarations

PrimeGenerator could be a good name for this class.

  1. +1 to @David Harkness and here is an example:

     Enter expression: 1.03-0.42
     Expression: 1.03-0.42
     Prepared expression: 1.03-0.42
     Solving expression: 1.03-0.42
     Solving expression: 0.6100000000000001
     Answer: 0.6100000000000001
    

And two references:

- [Why not use Double or Float to represent currency?][1]
- *Effective Java, 2nd Edition, Item 48: Avoid float and double if exact answers are required*
if (x % multiplier == 0) {
    primeLogger = primeLogger + 1.000;
} else {
    primeLogger = primeLogger + 0.000;
}

The else branch seems superfluous, I guess you could remove it:

    if (x % multiplier == 0) {
        primeLogger = primeLogger + 1.000;
    }
    
  1.   //first the class is declared
      public class startListingPrimeNumbers {
    

Later you'll find that comments like this one are just noise. It says nothing more than the code already does, it's obvious from the code itself that it's a class declaration, so I'd remove it. (Clean Code by Robert C. Martin: Chapter 4: Comments, Noise Comments)

1.

double multiplier;
...
for (multiplier = 1.000; multiplier <= (x); multiplier = multiplier + 1.000) {

The multiplier could be declared in the for loop.

    for (double multiplier = 1.000; multiplier <= (x); multiplier = multiplier + 1.000) {

(Effective Java, Second Edition, Item 45: Minimize the scope of local variables)

  1. Class names should be nouns, instead of verbs and the first letter should be uppercase:

Class and Interface Type Names

Names of class types should be descriptive nouns or noun phrases, not overly long, in mixed case with the first letter of each word capitalized.

Source: The Java Language Specification, Java SE 7 Edition, 6.1 Declarations

PrimeGenerator could be a good name for this class.

  1. +1 to @David Harkness and here is an example:

     final double original = 123456789123456789.0;
     double d = original;
     d = d + 1.000; // or d++
     System.out.println(d == original); // true
     System.out.printf("%f%n", original); // 123456789123456784,000000
     System.out.printf("%f%n", d);        // 123456789123456784,000000
    

And two references:

- [Why not use Double or Float to represent currency?][1]
- *Effective Java, 2nd Edition, Item 48: Avoid float and double if exact answers are required*
if (x % multiplier == 0) {
    primeLogger = primeLogger + 1.000;
} else {
    primeLogger = primeLogger + 0.000;
}

The else branch seems superfluous, I guess you could remove it:

    if (x % multiplier == 0) {
        primeLogger = primeLogger + 1.000;
    }
    
  1.   //first the class is declared
      public class startListingPrimeNumbers {
    

Later you'll find that comments like this one are just noise. It says nothing more than the code already does, it's obvious from the code itself that it's a class declaration, so I'd remove it. (Clean Code by Robert C. Martin: Chapter 4: Comments, Noise Comments)

1.

double multiplier;
...
for (multiplier = 1.000; multiplier <= (x); multiplier = multiplier + 1.000) {

The multiplier could be declared in the for loop.

    for (double multiplier = 1.000; multiplier <= (x); multiplier = multiplier + 1.000) {

(Effective Java, Second Edition, Item 45: Minimize the scope of local variables)

  1. Class names should be nouns, instead of verbs and the first letter should be uppercase:

Class and Interface Type Names

Names of class types should be descriptive nouns or noun phrases, not overly long, in mixed case with the first letter of each word capitalized.

Source: The Java Language Specification, Java SE 7 Edition, 6.1 Declarations

PrimeGenerator could be a good name for this class.

Source Link
palacsint
  • 30.3k
  • 9
  • 81
  • 157

  1. +1 to @David Harkness and here is an example:

     Enter expression: 1.03-0.42
     Expression: 1.03-0.42
     Prepared expression: 1.03-0.42
     Solving expression: 1.03-0.42
     Solving expression: 0.6100000000000001
     Answer: 0.6100000000000001
    

And two references:

- [Why not use Double or Float to represent currency?][1]
- *Effective Java, 2nd Edition, Item 48: Avoid float and double if exact answers are required*
if (x % multiplier == 0) {
    primeLogger = primeLogger + 1.000;
} else {
    primeLogger = primeLogger + 0.000;
}

The else branch seems superfluous, I guess you could remove it:

    if (x % multiplier == 0) {
        primeLogger = primeLogger + 1.000;
    }
    
  1.   //first the class is declared
      public class startListingPrimeNumbers {
    

Later you'll find that comments like this one are just noise. It says nothing more than the code already does, it's obvious from the code itself that it's a class declaration, so I'd remove it. (Clean Code by Robert C. Martin: Chapter 4: Comments, Noise Comments)

1.

double multiplier;
...
for (multiplier = 1.000; multiplier <= (x); multiplier = multiplier + 1.000) {

The multiplier could be declared in the for loop.

    for (double multiplier = 1.000; multiplier <= (x); multiplier = multiplier + 1.000) {

(Effective Java, Second Edition, Item 45: Minimize the scope of local variables)

  1. Class names should be nouns, instead of verbs and the first letter should be uppercase:

Class and Interface Type Names

Names of class types should be descriptive nouns or noun phrases, not overly long, in mixed case with the first letter of each word capitalized.

Source: The Java Language Specification, Java SE 7 Edition, 6.1 Declarations

PrimeGenerator could be a good name for this class.