Day6 基本for语句
1、public 和 private :private 是声明私有类,私有类自己的类可以使用,而 public 公共成员的访问不仅可以来自外部,也可以来自内部;
1 public class ForStatement { 2 public static void main(String args[]) { 3 forStatementTest(); 4 } 5 6 private static void forStatementTest () { 7 int tempN = 10; 8 System.out.println("1 add to " + tempN + " is " + addToN(tempN)); 9 tempN = 0; 10 System.out.println("1 add to " + tempN + " is " + addToN(tempN)); 11 12 int tmepStepLength = 1; 13 tempN = 10; 14 System.out.println("1 add to " + tempN + " with step length " + tmepStepLength + " is: " + addToNWithStepLength(tempN, tmepStepLength)); 15 16 tmepStepLength = 2; 17 System.out.println("1 add to " + tempN + " with step length " + tmepStepLength + " is: " + addToNWithStepLength(tempN, tmepStepLength)); 18 } 19 public static int addToN(int paraN) { 20 int resultSum = 0; 21 for (int i = 1; i <= paraN; i++){ 22 resultSum += i; 23 } 24 return resultSum; 25 } 26 public static int addToNWithStepLength(int paraN, int paraStepLength) { 27 int resultSum = 0; 28 for (int i = 1; i <= paraN; i +=paraStepLength){ 29 resultSum += i; 30 } 31 return resultSum; 32 } 33 }
hhh写完了 开始写毕设

 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号