Methods are a tool that allow us to break the control flow of our program. They let us declare little subroutines, or sometimes we can think of them as smaller programs, that we can reference in our program so that we don't have to write all of our program's logical code in one single block:
public class TemperatureConverter { public static void main(String[] args) { Scanner reader = new Scanner(System.in); char inputType; char outputType; float inputValue; float returnValue; System.out.print("Input type (F/C/K): "); inputType = reader.next().charAt(0); System.out.print("Output type (F/C/K): "); outputType = reader.next().charAt(0); System.out.print("Temperature: "); inputValue = reader.nextFloat(); } }
An example...