Eric Edwards

Ranch Hand
+ Follow
since Feb 12, 2000
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Eric Edwards

Originally posted by mandy fern:
public class number
{
public int[][] array2D = {
{ 1, 2, 3 ,4 , 5},
{ 6, 7, 8, 9, 10},
{ 11, 12, 13, 14, 15},
{ 16, 17, 18, 19, 20}
};
{
int a= Console.readInt("add a number");
array2D[0][0]=a;
int b= Console.readInt("add a number");
array2D[0][1]=b;
int c= Console.readInt("add a number");
array2D[0][2]=c;
int d= Console.readInt("add a number");
array2D[0][3]=d;
int e= Console.readInt("add a number");
array2D[0][4]=e;
int f= Console.readInt("add a number");
array2D[1][0]=f;
int g= Console.readInt("add a number");
array2D[1][1]=g;
int h= Console.readInt("add a number");
array2D[1][2]=h;
....etc

My question is:Is there a way to shorten this or do I have to to do this
for every component of the array?


Instead of reading each number into an int and then moving it into an element of your array, couldn't you read a number from console directly into the arrary element. That way you could put this in a loop and use a variable in each of the two elements of your array and just increment them each time you add another number.
I think this would work.
23 years ago

Originally posted by Buck_Webb:
I am looking at a copy of "just JAVA 2", Fourth Edition.
On page 384 it shows a table for the Java.util API. In the table is listed the area of Calendar,TimeZone,SimpleTimeZone.
On page 404 is the following code:
TimeZone z_ect = TimeZone.getTmeZone("ECT");
GregorianCalendar g2 = new GregorianCalendar(z_ect);
g2.set(89, 10, 9, 19, 0); // Berlin Wall //Down Nov 9 1989 7pm
g2.set(89, Calendar.NOVEMBER, 9, 19,0); //better
I don't know if this is what you need, but give it a try.
Good Luck!
Eric
[This message has been edited by Eric Edwards (edited July 13, 2001).]

23 years ago
My question has to do with coding a progress bar using swing.
I have looked in several sources and all that I have learned so far is that it must be done using threads, but I am having a problem tying the thread(s) together with the JProgress Bar and the data. What is the best way to accomplish this task.
24 years ago
My question has to do with coding a progress bar using swing.
I have looked in several sources and all that I have learned so far is that it must be done using threads, but I am having a problem tying the thread(s) together with the JProgress Bar and the data. What is the best way to accomplish this task.
[This message has been edited by Eric Edwards (edited April 10, 2001).]
24 years ago
Try this. I wrote this program to store a Double, but you can easily change it to an Integer to suit your needs. Notice the casting at the end.
Hope this helps.
import java.util.*;
public class VectorDouble
{
public static void main(String[] args)
{
Vector v = new Vector();
Enumeration e = v.elements();

for(int i = 0; i < 10; i++)
v.addElement(new Double(i * 1.2));

while(e.hasMoreElements())
{
Double o = (Double)e.nextElement();
double i = o.doubleValue();
System.out.println((i * 2));
}
}
}
24 years ago
int methodName() is expecting to return an integer value.
double methodName() is expecting to return a double.
void methodName() is not expecting to, nor will it let you, return anything.
Say you have a method that you want to print a value to the screen, or print out a record, you could use a void method with no return because it is all being done within that method. If you are using another method to do some action and are passing it a value from this method, you have to show the return type as part of your method( int, double, String, etc ).
I hope this has helped and not confused.
24 years ago


[/B]


In Visual Age, two things will happen.
The console will come up on your screen, behind whatever screen you have open at the time, and a console icon will appear on your status bar. Click on either one--and your output will be revealed.
Have you tried using "Scrapbook" in VisualAge. It is a window that allows you to try out some code you have written without writing a whole program. Go to window, scrapbook.
Good Luck!
24 years ago

Originally posted by kaffo lekan:
Hello
i need to know if a final variable can be changed at runtime.
Yes/No , please explain more.


Declaring a variable as final forbids modification of the variable at runtime. Any attempt to modify the value of a final instance variable after it is initialized is a syntax error.
Hope this helps.
24 years ago

Originally posted by gayathri bhushan:
Your class path should begin with .;C and so on.
You must put a .; before the C in your clas path for it to work.
Good Luck!

24 years ago

Originally posted by greggg smith:
I just bought the book after going through "Just Java 2".
It appears to be well done.
What I like about it is the code examples, the different approach to teaching Java, and especially the exercises at the end of each chapter.
Yes, it is laid out like a text book, but it is good for self-teaching.
I bought it at Barnes & Noble for $68.
Well worth it!

24 years ago

Originally posted by John Collie:
I ran your program as is and it works fine.
You need to run this program from a DOS command line.
I compiled your program and typed in:
java bank 4000 1700
It returned the correct information.
One thing though, class names should begin with a capital letter.
class bank should be class Bank.
Good Luck!

24 years ago
There is nothing wrong with your code.
The reason for the output is the way your computer handles math -- in particular -- double and float.
When I did a similar program on my computer, I got the same result.
You can fix your output to however many decimal places you want by rounding or formatting.
Hope this helps.
24 years ago
I am not familiar with Star Office.
Is it a stand alone product or should it be used in conjunction with Microsoft Office products?
24 years ago

Originally posted by Asheesh_talwar:
I am getting a string with follwing formats
23434
2.32453
223,324,343.34532424
324,343.34532424
2.3453E-01
32,456.9
0
1.0
Note:The Number can be negative also.
First I want to check whether the number is postive or negative
Secondly I want to round the value to two decimal place.
Thirdly I want to display the number in the million format.
Regards
Asheesh


Try this!
example:
double x = 134.5678923;
NumberFormat nf = NumberFormat.getNumberInstance();
nf.setMaximumFractionDigits(2);
String fx = nf.format(x); // this will print with two decimal places.
java.text has all kinds of number formatting available.
24 years ago

Originally posted by Asheesh_talwar:
Eric there is a problem with the solution that U have given
It will give correct o/p if we give two command line parameters.
The program will fail if we give less than two or greator than two parameters.
If we want it to work for any number of parameters then I think this will do.
class AddString
{
private void sumReturn(String args[])
{
String str = new String();
int i = 0;
if (args.length > 0)
{
for (int j = 0; j < args.length; j++)
{
str=str+args[j];
}
for(i = 0; i < args.length - 1; i++)
{
System.out.print(args[i] + "+");
}
System.out.println(args[i] + " = " + str);
}
}
public static void main(String args[])
{
AddString a = new AddString();
a.sumReturn(args);
}
}

Regards
Ashish
[Added spaces after '<' and elsewhere so that browsers don't confuse your code with HTML - Jim]
[This message has been edited by Jim Yingst (edited December 09, 2000).]


Yes, you are correct. There are many ways to do this. I thought about this, and he was concerned mainly with the logic of a loop, and not of the command line being read in for any number of parms, so, to simplify things, I did it my way.
Regards,
Eric
24 years ago