2012-02-27 78 views
1

我有一個text box(having name b),一個在index.jsp提交按鈕。我會再單擊submit我在服務器端find.jsp獲得該值通過後進入文本框的東西。在find.jsp我得到如下所示通過request.getParameter("b");值。在find.jsp calaculation完成:通過循環解決的java

double c=0; 
double d=0; 

7800.0/12 and 2640.0/12 are fixed.  

if request.getParameter("b")=1 then 

c=7800.0/12*5;// 5 is multiplied with above number(in first one) 

d=2640.0/12*5;// 5 is multiplied with above number(in second one) 

if request.getParameter("b")=2 then 

c=7800.0/12*8;// here 5 gets incremented by 3 and became 8(in first one) 

d=2640.0/12*8;// same also here(in second one) 

類似地,如果我將輸入20然後相應c和d將被計算。 如果其他任何值可以在客戶端輸入,並相應地c和d將在服務器端的計算,我不能使用。 我怎麼能實現它在一個循環?非常感謝

+0

請告訴我B和5之間的關係??? – 2012-02-27 06:23:38

+0

沒有關係。如果b = 1,那麼5將相乘,如果b = 2,則5增加3,所以8將像這樣相乘 – Tom 2012-02-27 06:24:46

+0

,並且如果b = 3?什麼方程mutipliedNumber = 5 + f(b)?? – 2012-02-27 06:25:48

回答

2

嘗試

double devide=2.0 
    devide = Integer.parseInt(request.getParameter("b"))*3+devide 

    c=7800.0/(12*devide); 
    d=2640.0/(12*devide); 
+0

嗯......我認爲這對他有效...... – 2012-02-27 06:29:41

+0

只是因爲你在b的每個增量處增加3,而在第一種情況下是5,所以2默認情況下 – 2012-02-27 06:33:56

+0

添加是它的工作:) – Tom 2012-02-27 06:35:02

1

您可以使用任意值計數低於一個邏輯。

int value = Integer.parseInt(request.getParameter("b")); 
double x=2.0; 
double valueForDevide = (value*3)+x; 

c=7800.0/(12*valueForDevide); 
d=2640.0/(12*valueForDevide);