书P41例题
(1)方法表达式,这个好像比方法语句更复杂,但貌似更清晰。
public class Example3_1
{ static int square(int x)
{ int s;
s=x*x;
return (s);
}
public static void main(String[] args)
{
int n=5;int result=square(n);
System.out.println(result);
}
}
(2)方法语句,更简洁。
public class Example3__1
{ static void square(int x)
{ int s;
s=x*x;
System.out.println(s);
}
public static void main(String[] args)
{
int n=5;square(n);
}
}
一年微信支付现金及刷卡总支出也可以使用方法调用
public class Secondweek
{static void ultimate(int Yearlypayment)
{int total;
total=12*Yearlypayment;
System.out.println(total);
}
public static void main(String[] args)
{int Cashpayment=50000;
int Wechatpayment=80000;
int Cardpayment=10000;
int sum=Cashpayment+Wechatpayment+Cardpayment;
ultimate(sum);
}
}