473,461 Members | 1,797 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Two problems in debugging: results var "cannot be resolved" & if stmt syntax error

(There is another page that "number1", "number2" and "operator" come from)

Expand|Select|Wrap|Line Numbers
  1. <!doctype html public "=//W3C/DTD HTML 4.U Transitional//EN")
  2. <html>
  3. <head>
  4. <title>Simple Calculator</title>
  5. </head>
  6.  
  7. <%@ page import="java.lang.Double" %>
  8. <%@ page language="java" errorPage="" %>
  9.  
  10. <body>
  11.  
  12. <%
  13.     String num1=request.getParameter("number1");
  14.     String num2=request.getParameter("number2");
  15.     String operator=request.getParameter("operator");
  16.  
  17.     Double.parseDouble(num1);
  18.     Double.parseDouble(num2);
  19. %>
  20.  
  21. <h1>Simple Calculator</h1>
  22.  
  23. <%! public static double getResult(Double num1, Double num2, String operator)
  24. {    
  25.  
  26.     if(operator.equals("add")) {
  27.         double result=num1+num2;
  28.     } else if(operator.equals("subtract")) {
  29.         double result=num1-num2;
  30.     } else if(operator.equals("multiply")) {
  31.         double result=num1*num2;
  32.     } else {
  33.         double result=num1/num2;
  34.     }
  35. }
  36. %>
  37.  
  38.  
  39. <form action="lab02Form.jsp" method="get">
  40.  
  41. <table cellspacing="5">
  42.     <tr>
  43.         <td align="right">Enter a Number: </td>
  44.         <td><input type="text"name="num1" value="num1">
  45.         </td>
  46.     </tr>
  47.     <tr>
  48.         <td align="right">Enter Another Number: </td>
  49.         <td><input type="text"name="num2" value="num2">
  50.         </td>
  51.     </tr>
  52.     <tr>
  53.         <td align="right">Select an Operator: </td>
  54.         <td>
  55.         <select>
  56.         <option value="add">add</option>
  57.         <option value="subtract">subtract</option>
  58.         <option value="multiply">multiply</option>
  59.         <option value="divide">divide</option>
  60.         </select>
  61.         </td>
  62.     </tr>
  63.  
  64.     <tr>
  65.         <td align="right">Result: </td>
  66.         <td><input type="text"name="result" value="<%=result%">>
  67.         </td>
  68.     </tr>
  69.  
  70.     <tr>
  71.         <td></td>
  72.         <td><input type="submit" value="Reset">
  73.         </td>
  74.  
  75.         <td></td>
  76.         <td><input type="submit" value="Compute">
  77.         </td>
  78.     </tr>
  79. </table>        
  80.  
  81.  
  82. </body>
  83.  
  84. </html>
  85.  
Sep 23 '10 #1
1 1750
RamananKalirajan
608 512MB
You have done a mistake here

Expand|Select|Wrap|Line Numbers
  1. <input type="text"name="result" value="<%=result%">> 
actually it should be like this

Expand|Select|Wrap|Line Numbers
  1. <input type="text"name="result" value="<%=result%>" />
I dont find any problem with if statement.

Thanks and Regards
Ramanan Kalirajan
Sep 24 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: lawrence | last post by:
Google can't find me a good example of how to use the "if exists" syntax in MySql. Is it right that to use it this way: INSERT INTO IF EXISTS tMyTable VALUES("xxlk", "lkjlkjlkjljk") I want...
5
by: BJ | last post by:
The application I have been developing is great except one flaw. When Windows NT shuts down, it doesn't send the Event to my application (if it did, it would close all of the open forms and kill an...
5
by: NanQuan | last post by:
I'm hoping someone can help me solve this error since I am at a total loss here. Usually I don't bother posting on any forums or groups on the internet and prefer to solve stuff myself but this is...
1
by: cajunmaori | last post by:
I am having trouble downloading an excel report generated from our AS pages. We presumed it was something to do with the SSL certificate w just installed, so loaded the ForceSSL.inc script from...
0
by: Mark Phanides | last post by:
My ASP.NET application intermittantly (but always at same point) redirects to the 'Invalid Syntax Error' web page for some unknown reason. I've created a ASP.NET application written in VB.NET with...
1
by: Joe | last post by:
Hello All, I am trying to insert a record in the MS Access DB and for some reason I cannot get rid of error message, System.Data.OleDb.OleDbException: Syntax error in INSERT INTO statement. ...
3
by: shifty shaker | last post by:
I've modified sql text and now i'm getting a syntax error that I cannot figure out....anyone? error occurs at the Insert Into line but the entire function is given in case you need it. ---...
4
by: Don Lancaster | last post by:
I want to programically generate some JS variable names in a loop. The variables are NOT to be array values. The variable names might be eq0, eq1, eq2.... Inside an ii indexed loop, eval...
17
by: trose178 | last post by:
Good day all, I am working on a multi-select list box for a standard question checklist database and I am running into a syntax error in the code that I cannot seem to correct. I will also note...
5
by: rolltide | last post by:
I've seen many similar threads, but despite repeated efforts I cannot figure out my problem. I am running Access 2003, VB 6.5, Office XP Pro. Code excerpt is below (you can see where I've tried...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.