jeudi 12 juillet 2018

How to compute negative numbers and print in if/else statements

I'm having trouble with a certain block of code

This is it: `

  // LADITUDE 1:
  System.out.println("Enter laditude 1:");
  int ladDDD = scan.nextInt();
  int ladMM = scan.nextInt();
  int ladSS = scan.nextInt(); 
  String ladD = scan.nextLine();
  if (ladD == "S"){
     double degreeslad1 = (ladMM/-60)+(ladSS/-3600)-ladDDD;
     System.out.println(degreeslad2);
  }else{
     double degreeslad = ladDDD+(ladMM/60)+(ladSS/3600);
     System.out.println(degreeslad2);
  }`

When I run it with the string input of "S" it returns a double that is not negative, and I need it to be negative (because S means south and south is negative). That's one issue, the other is when I use another letter it returns the same thing. I'm trying to get it so that if the user inputs S it computes a negative number and prints that in degrees. Also if they enter another letter it computes the second equation as a positive.

Aucun commentaire:

Enregistrer un commentaire