October 2017
Beginner
318 pages
7h 26m
English
So I guess we're going to need separate cases for each of the possible or valid input types, that is, capital F for Fahrenheit, C for Celsius, K for Kelvin. We should probably also handle a default case. Let's start off by writing the default case. We'll use System.exit and exit with 1, which is technically an error code:
switch(inputType)
{
case 'F':
case 'C':
case 'K':
default:
System.exit(1);
In this case, the program will just stop. Because it's the default case, we only expect to enter it if the user has failed to enter F, C, or K, which are our valid input ...
Read now
Unlock full access