Re: Is My answers correct??
Hi Java.Coder(),
The things above are quite confusing. What are the things in red? Are they your answers? Or they are the actual errors? Or something else?
Can you simply post the exact code that your teacher gave you? Don't overwrite your answers in the same code, put them as a comment on a separate line.
For e.g.
Code java:
length double;
//double length;
where the portion after // is what you have corrected.
In short, properly format your question, so that it would be easy for us to understand it.
Plus post your code in the similar fashion as I have posted above using [highlight=java] Your Java code [/*highlight] (Remove the star[*] in closing bracket when you use it).
Hope you are clear with this.
Goldest
Re: Is My answers correct??
thank you goldes for your reply:)>-
the things in red is my answere, since he just asked to underline the error without any correction or justification
Code java:
Public Class box
{
x int [] = new int (5);
// int [] = new int[5]; -- two errors
int y [] = new int [10];
length double;
// double length
int width;
private static double f = 10
// ; missing
Box obj1 = new XYZ ();
// Box obj1 = new Box(); -- constructor name
public box();
// error -
public Box (double len, int wid, double f)
{
length = len;
width = wid;
f = ‘a’;
//f is double not char
}
public int setLength (int l);
// public void setLength(int l) -- two errors
{
length = l;
}
}
// extra bracket
}
I think the mentioned ten errors above is enough to get the full mark for this question
Re: Is My answers correct??
Well,
Frankly speaking we can assign a char into a double. The complier will not complain for that. It treats it as a ASCII value and prints it out easily.
Look at the below code,
Code java:
public class Box {
public static void main(String args[]) {
double d = 'x';
System.out.println("ASCII for small X: " + d);
int i = 'X';
System.out.println("ASCII for capital X: " + i);
}
}
When you run this, it will print,
Code java:
ASCII for small X: 120.0
ASCII for capital X: 88
The real gotcha in your code is the first line itself. The first line is violating the keywords of java in a wrong way. What you have mentioned is "Public Class box". This is NOT allowed. Public and Class are NOT keywords in java, they are in fact "public" and "class" [Notice the small p and small c]
So your error of assigning char into double is not actually an error, instead the first line itself is an error. Even the name of the class should be Box not box [notice capital B].
I hope now you know where you lost one mark.
Goldest
Re: Is My answers correct??
Here is a link in case if you are interested to know more about ASCII: ASCII-Table
This describes chars and their corresponding values in different formats.
Goldest
Re: Is My answers correct??
Many thanks and regards goldest
Re: Is My answers correct??