|
thanks alot Mr. Cedric
the reason for this code is that l wonted to do CALCULATING IN JAVA?
l understand u completely but for now,how should l make the code work(l mean to initialize it)and not to fall back the way l was before?
thanks for ur alert for the tutorials.please help me for this one...
modified on Wednesday, January 19, 2011 9:57 AM
|
|
|
|
|
You can already fix the points I mentionned in my previous message, this was detailed enough for you to understand the problems.
You don't expect us to write the program for you, do you ?
|
|
|
|
|
thanks again..
l dont wont u to write all the program for for but to guide me Fix the errors is all what l need..but thanks alot for ur time becouse this's my first time of sending a code in this forum...
modified on Wednesday, January 19, 2011 10:02 AM
|
|
|
|
|
Try here[^] for some good tutorials that will help you with your problem.
I must get a clever new signature for 2011.
|
|
|
|
|
Mr. Cedric
please a question?
1- how should make the sign veriable work and?
2- how to initialize those to variables( num1 and num2)?
|
|
|
|
|
Initialize your variables at the beginning of the program by reading ONCE the command line arguments: only do this of course if the number of arguments match, otherwise you exit the program with an error.
BTW, you have another problem: you are expecting 3 command line arguments but you retrieve four of them (num3 is initialized with args[3], which is out of bounds).
|
|
|
|
|
//l've change the code but still 1 error has been occur
public static void main(String [] args)
{
String sign;
int num1;
int num2;
//int num3;
int ans;
System.out.print("Enter your Calculations =>: \n");
sign = in.nextLine();
if(args.Length == 3)
{
num1 = Integer.parseInt(args[0]);
sign = (args [1].equal("1"));
num2 = Integer.parseInt(args[2]);
//num3 = Integer.parseInt(args[3]);
System.out.println("Answer = "+ ans);
}else if(args[0].equal("+")) {
ans1 = num1 + num2;
System.out.println("num1 "+ "num2 " = ans);
}
else if(args[1].equal("-")) {
ans2 = num1 - num2;
System.out.println("num1 "- "num2 "= ans);
}
else if(args[2].equal("/")) {
ans3 = num1 / num2;
System.out.println("num1 "/ "num2 "= ans);
}
System.err.println("Try Again");
}
}
}
|
|
|
|
|
Please refer to the first part of my initial message (code formating and providing information about your problem).
You should put your else conditions inside the first if (and replace the first else condition by an else condition). In your example you are checking if you have 3 arguments and only if that's not the case you will check the sign argument.
|
|
|
|
|
Mr. Cedric,
I think u've tried alot best for me but l did try what u said and l got 3 error.
anyway,l appreciate very well for ur help since am a beginner in java and once l cant compile this code those not make me to stop learning?please if u get anytime,try and correct this code for another people to lean from it?
remain bless always from God..
I'll go back and learn the tutorials...thanks.
|
|
|
|
|
The tutorials (see the link I provided) will get you to the answers faster and better than struggling with the above sample. You obviously have some gaps in your knowledge of some of the basic concepts, and should learn and understand those first before you try to write a program like the one above. Starting at the beginning will get you up to speed much faster than trying to start from the middle.
I must get a clever new signature for 2011.
|
|
|
|
|
please if u get anytime,try and correct this code for another people to lean from it?
come on! If you're just searching for the code, go to google.
This is a simple code used in training throughout the world, nearly every learner has to do this task at a certain point while learning.
How are you trying to compile the code? You should use eclipse or netbeans - those are freeware and should help you a lot along your way.
What do those editors say if you try to compile your code? Most times it should be fairly easy to figure out the errors. Even automatic help is often granted!
regards
Torsten
I never finish anyth...
|
|
|
|
|
l've done it the code has compiled?
|
|
|
|
|
Mr. Cedric Moonen
bellow is the code that l did compile and it works perfectly..thanks alot..
public class Calculate {
public static void main(String[] args) {
double x,y;
if (args.length == 3)
{
x = Double.parseDouble(args[0]);
y = Double.parseDouble(args[2]);
if(args[1].equals("+"))
{
System.out.println("Answer = "+ (x + y));
}else
if(args[1].equals("-"))
{
System.out.println("Answer = "+ (x - y));
}else
if(args[1].equals("/"))
{
System.out.println("Answer = "+ (x / y));
}else
if(args[1].equals("x"))
{
System.out.println("Answer = "+ (x * y));
}
}else
System.out.println("Do it again......");
}
}
|
|
|
|
|
I had this delete button and when i click it this errors comes out.
java.lang.RuntimeException: Number of conflicts while synchronizing: 1 SyncResolver.DELETE_ROW_CONFLICT row 4 more than one row matched delete statement
how can i solve this?
|
|
|
|
|
You're trying to delete a row which is not identified clearly.
There are other rows, which also match your search pattern. So you need to change the way the rows are identified or the way of detecting the row, which has to be deleted.
regards
Torsten
I never finish anyth...
|
|
|
|
|
Hello guys!
I`m writing on a programming assignment and I`ve reached this question:
Describe the technique of layering I/O streams. Give some code for a client to show how this technique could be used to read doubles from files that arrive over a TCP/IP network in compressed form.
Even though I have some years of programming (not only Java), I'm not happy with my answer describing the layering.
As for the second part of the question, I don`t know how to read compressed data coming from Sockets...
Could you please help me with some insights and links?
Many thanks!
Shpid3r
|
|
|
|
|
|
Is there any automated way of doing indentation in my lengthy code?? i mean is there any option available in eclipse or either in Netbeans??
|
|
|
|
|
aesthetic.crazy wrote: i mean is there any option available in eclipse
In Eclipse there is an awesome feature that format your code properly automatically (indentation, position of brackets, spacing, ...). Without having anything selected in your editor, simply press ctrl + shift + F. If you have a piece of code selected, this will format only the selection.
|
|
|
|
|
Both NetBeans and Eclipse have this feature. It's not hard to find in either IDE, a few seconds browsing the menu options will reveal its location.
If you want to do this outside your IDE, Jalopy[^] is very good.
|
|
|
|
|
you can refactor your code in eclipse with a right click. There you can extract a interface or superclass, extract local variables and stuff like that.
But a good design is still most efficient...
regards
Torsten
I never finish anyth...
|
|
|
|
|
If in eclipse use the Format Code if u want to reformat the code writing , and if u only want to align the braces , simply select the piece u want to indent and select and press CTRL + I to indent the code.
|
|
|
|
|
How to convert ResultSet to Integer?
i do it this way however i encountered errors.
codes as follows:
rs = stmt.executeQuery("Select count(1) from INCIDENTDATA where INCIDENTID = 10");
Integer id = rs.getInt(1);
if( id == 0){
.
.
.
}
When i do a debug errors i encounted:
1. "id" is not a known variable in the current context.;
2. "rs" is not a known variable in the current context.;
http://img841.imageshack.us/img841/1965/exeerror.png[^]
needing help.
When i execute the SQL this is the screen shot : http://img502.imageshack.us/img502/8532/executey.png[^]
how do i get the value 0 so as to compare it if it is 0 then i will add the value 10 into the database?
modified on Sunday, January 16, 2011 11:25 PM
|
|
|
|
|
I have made changes to the codes. Right now i dont face any error but however i dont see the value that i have added, being added to the table.
public String add_btn_action() throws SQLException {
ResultSet rs = null;
Statement stmt = null;
Integer id;
String dbURL = "....";
String incidentId = (String) getIncidentidtxt().getValue();
Integer incidentIntId = Integer.parseInt(incidentId);
String incidentName = (String) getIncidentnametxt().getValue();
Connection con = DriverManager.getConnection(dbURL);
try{
stmt = con.createStatement();
rs = stmt.executeQuery("Select COUNT(1) from INCIDENTDATA where INCIDENTID = "+incidentIntId+"");
while(rs.next()){
id = rs.getInt(1);
if( id == 0){
getSessionBean1().updateIncident(incidentIntId, incidentName);
incidentdataDataProvider.refresh();
}
else{
Integer newIncidentID = incidentIntId + 1;
getSessionBean1().updateIncident(newIncidentID, incidentName);
instancedataDataProvider.refresh();
}
}
}
catch(Exception e){
e.getMessage();
}
return null;
}
Needing help..
|
|
|
|
|