這裏是我的問題:我的for
循環應該在循環過程中旋轉,當它達到值7
時,它應該從1
開始。在java中的循環過程中旋轉for循環過程
和我的newcost
值應該始終在增加值。
這裏是我的代碼:
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import org.joda.time.DateTime;
import org.joda.time.Days;
public class PayCalculation {
int cost,cost1=0;
private String fromdate, todate, npersons, nrooms, rooms;
long newcost;
public String execute() throws Exception{
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
Date date1 = dateFormat.parse(fromdate);
//Date date2 = dateFormat.parse(todate);
Calendar c = Calendar.getInstance();
c.setTime(date1);
// c.setTime(date2);
int dayOfWeek1 = c.get(Calendar.DAY_OF_WEEK);
// int dayOfWeek2 = c.get(Calendar.DAY_OF_WEEK);
Date past = dateFormat.parse(fromdate);
Date today = dateFormat.parse(todate);
int days = Days.daysBetween(new DateTime(past), new DateTime(today)).getDays();
System.out.println(dayOfWeek1 + " day of the week");
System.out.println(days + " no of days");
int i;
for(i=0 ; i<=days ; i++){
System.out.println(i);
if(i==1 || i==7){
System.out.println("sun or sat");
cost1=1500;
// newcost=cost1;
}
if(i==2 || i==3 || i==4 || i== 5|| i==6){
System.out.println(" other days");
cost=1000;
// newcost=cost;
}
/*if(i==7){
System.out.println("i==7");
i=1;
}
*/ newcost=0+cost+cost1;
System.out.println(newcost+" new cost");
}
System.out.println(newcost);
return "success";
}
你的問題是什麼? –
那麼,下面的答案有幫助嗎? –