java - How to skip a print statement in loop -
i have 2 classes named test1 , test2.
class test1{ public void exe1(){ system.out.println("execute 1 time"); system.out.println("execute iterations"); system.out.println("execute last time"); } } class test2{ public statuc void main(string args[]){ test1 ts = new test1(); for(int i=0 ; i<=3;i++){ ts.exe1(); } } }
the ouput of result :
execute 1 time execute iterations execute last time execute 1 time execute iterations execute last time execute 1 time execute iterations execute last time
is possible in java output should :
execute 1 time execute iterations execute iterations execute iterations execute last time
i mean 1st print statement should execute @ 1st time , number of iterations may print , @ end last print statement should execute.
public void exe1(int i){ if(i==0) system.out.println("execute 1 time"); if(i==3) system.out.println("execute last time"); else system.out.println("execute iterations"); } for(int i=0 ; i<=3;i++){ ts.exe1(i); }
use in loop function argument.
Comments
Post a Comment