Skip to content

Instantly share code, notes, and snippets.

@khayyamsaleem
Created September 22, 2017 01:53
Show Gist options
  • Save khayyamsaleem/f22f8050e728336d5e49e174869a0b45 to your computer and use it in GitHub Desktop.
Save khayyamsaleem/f22f8050e728336d5e49e174869a0b45 to your computer and use it in GitHub Desktop.
import java.util.Scanner;
public class Coordinates {
public static void main(String[] args){
Scanner console = new Scanner(System.in);
System.out.println("x coordinate? ");
double x = console.nextDouble();
int neg;
if (x < 0.0) {
System.out.print("y coordinate? ");
double y = console.nextDouble();
if (y < 0.0) {
neg = 2;
System.out.println("negatives = " + neg);
} else {
neg = 1;
System.out.println("negatives = " + neg);
}
} else {
System.out.print("y coordinate? ");
double y = console.nextDouble();
if (y < 0.0) {
neg = 1;
System.out.println("negatives = " + neg);
} else {
neg = 0;
}
System.out.println("negatives = " + neg);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment