Skip to content

Instantly share code, notes, and snippets.

@thehale
Created July 29, 2021 17:24
Show Gist options
  • Save thehale/ce83ede36338486dd4957d5f8fca31f5 to your computer and use it in GitHub Desktop.
Save thehale/ce83ede36338486dd4957d5f8fca31f5 to your computer and use it in GitHub Desktop.
import java.util.Scanner;
public class Scratch {
// Assign multiple double values from System.in
// without writing `nextDouble()` more than once.
public enum DoubleExample {
A, B, C;
public final double value;
private DoubleExample() { value = new Scanner(System.in).nextDouble(); }
}
// Entry point to demonstrate the example.
public static void main(String... args) {
System.out.println(DoubleExample.A.value);
System.out.println(DoubleExample.B.value);
System.out.println(DoubleExample.C.value);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment