mardi 10 février 2015

If/else statement [on hold]

I'm new here and I'm taking a AP Computer Science course, but this question has me stumped. Any hints or walk-throughs are appreciated! Consider the following method. For each call below, indicate what output is produced.



Public static void mystery1(int n) {
System.out.print(n + " ");

If (n > 0) {

n = n - 5;
}

If (n < 0) {
n = n + 7;

}
Else
{
n = n * 2;

}

System.out.println(n);

}

Mystery1(8);
Mystery1(-3);
Mystery1(1);
Mystery1(0);

Aucun commentaire:

Enregistrer un commentaire