JAVA基础:方法案例
方法设计技巧:
package com.itheima.Method; public class Method3 { public static void main(String[] args) { System.out.println(sum(10)); pan(5); } public static int sum(int n){ int sum=0; for (int i = 1; i <= n; i++) { sum +=i; } return sum; } public static void pan(int a){ String b=a % 2 == 0 ? "偶数" : "奇数"; System.out.println(b); } }