天天看点

java多个if语句的执行顺序_if语句 两个都为真先执行哪个 还是都执行

package array;

import java.io.BufferedReader;

import java.io.IOException;

import java.io.InputStreamReader;

public class linlin {

public static void main(String[] args) {

String s1="";

String s2="";

String s3="";

try{

BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

System.out.print("Age = ");

s1 = in.readLine();

System.out.print("Sex = ");

s2 = in.readLine();

System.out.print("Comm = ");

s3 = in.readLine();

}catch (IOException e){}

int age = Integer.parseInt(s1);

String sex = s2;

// int sex = Integer.parseInt(s2);

double comm = Double.parseDouble(s3);

System.out.println("The actual result is: "+Sample(age,sex,comm));

}

static double Sample(int age,String sex,double comm){

if (( age > 25 )&&( sex == "M" )){

comm = comm + 150;

}

if ((age > 50)||( comm > 2000.00)){

comm = comm - 200;

}

return comm;

}

}