Skip to content

Instantly share code, notes, and snippets.

@itsJarrett
Last active April 14, 2016 01:40
Show Gist options
  • Save itsJarrett/07a76fbee2bb9ffcb34e to your computer and use it in GitHub Desktop.
Save itsJarrett/07a76fbee2bb9ffcb34e to your computer and use it in GitHub Desktop.
Find out if two numbers have a middle!
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
middleNumber();
}
public static void middleNumber() {
Scanner s = new Scanner(System.in);
System.out.println("Enter the first number.");
double one = s.nextDouble();
System.out.println("Enter the second number.");
double two = s.nextDouble();
double number = one + two;
number = number / 2;
if (number % 1 == 0) {
System.out.println("Congratulations, those numbers have a middle! The middle number is " + number + "!");
} else {
System.out.println("Those two numbers have no middle :( !");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment