closer to point

package nambers; import java.util.Scanner; public class nambers { public static void main(String[] args){ for(int i=0; i!=-1; i++){ Scanner scan=new Scanner(System.in); System.out.println("enter number m"); double m=scan.nextDouble(); System.out.println("enter number n"); double n=scan.nextDouble(); System.out.println("enter point number "); double point=scan.nextDouble(); double difference1=Math.abs(m-point); double difference2=Math.abs(n-point); if (difference1<difference2){ System.out.println(m+ " is closer to "+ point); } else if (difference1>difference2){ System.out.println(n+ " is closer to "+ point); } else {System.out.println("numbers are equal"); } } } }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.