Java Beginner: Variable Initialization
I'm a total beginner in Java so bare with me. Here's a code snippet that
won't compile. I get an error on the last line claiming that the
dots_per_page variable wasn't initialized. This error goes away when I set
it equal to a value on the first line shown. Is there something I'm
overlooking? I didn't think that I would have to set it equal to a value
upon declaration. Thanks for any guidance.
long dots_per_page;
if (print_type == 'T' || print_type == 't') {
dots_per_page = 5000;
}
else if (print_type == 'I' || print_type == 'i') {
dots_per_page = 10000;
}
else {
System.out.println("You did not provide a valid option.");
}
System.out.println(dots_per_page);
No comments:
Post a Comment