sneaker 25 Junior Poster in Training Team Colleague

Since it is the first chapter it makes sense if you should practice on concatenate strings and the difference between print and println.

sneaker 25 Junior Poster in Training Team Colleague

You can also do it another way, if you want to :)

First you make a String variable that holds the value of the double variable you are working with. You do this by using the method Double.toString() and the parameter you put in can either be the value directly, or the name of a double variable to which you have assigned the value you are working with.

Like this:

String number = Double.toString(6.28);

Or, like this:

double d = 6.28;
String number = Double.toString(d);

You then make an int variable that holds the value from the method indexOf() where you put in the char '.' so this method can return the indexposition of that char.

Like this:

int i = number.indexOf('.');

After that you finish by using the substring method in the String class and print it out.
The substring method wants the indexpositon of the first char in the substring that shall (in this case) be printed.

You can do it directly in the System.out method.
Like this:

System.out.println(number.substring(i) + "");

This is the same as if you had written:

String s = number.substring(i);
System.out.println(s + "");

The printed result will be .28

Good luck :)

coil commented: good solution, well explained. +1
sneaker 25 Junior Poster in Training Team Colleague

When you want to read from or write to a file in Java you have to use different streams depending on what kind of file it is. You also have to take care of exceptions that can be thrown.
I hope this link will help you:
http://www.underground-systems.org/forums/showthread.php?5157-Small-and-random-pieces-of-basic-Java
I want you to look at post #3 in this thread. There is an example of a filehandler and the part that should be of interest for you is how to read and write from/to a textfile. This is of course if you decide to store your numbers in an array, which is the easiest way in my opinion. You can also store them as objects in a vector, but that would be a bit overkill.
The code is written by me (you can find similar examples by googling on filehandler) so you can use those parts you want as long as you are sure that you understand what is happening in the code.You should also read more in Java API and Java tutorials.

Good luck :)

sneaker 25 Junior Poster in Training Team Colleague

I am not sure this will work with SCSI but you could try.
It is a big i not a small L after hdparm -
sudo hdparm -I /dev/sda

( -I gives you detailed/current information directly from drive)

You can also search for scsi_id commands but they do not work on my computer so I can not help you with them.

sneaker 25 Junior Poster in Training Team Colleague

Alternativs:
3) uname -n
4) uname -s

grep is a command that returns a string with the desired text.
In my case the command ifconfig | grep "inet addr" gives me the same result as ifconfig | grep "inet" but ifconfig | grep "addr" gives an other result.

As long as you are not logged in as root or uses the sudo command you can play around and look at what you get for result.

Look in man pages to learn more.

for example ifconfig man
gives you information about ifconfig

and man man
gives you information about man pages

Quite from man pages with the Q key.

Use -help to show you more.
for example ifconfig -help
shows you available parameters like -a, -v, -s and what they stand for

Good luck :D

sneaker 25 Junior Poster in Training Team Colleague

I need to write a program that will output a list of all even numbers between 1-100. It needs to use a while loop then use a for loop. Any one got any help on how to do that?

If it is a task where you must have both kinds of loop you could do it like this:
While number is less than 100
check if it is even (see the answer BestJewSinceJC gave you)
put the even numbers in a array of int's
For every index in the int array make an outprint.

This is only one way to do it.
Good luck :)

sneaker 25 Junior Poster in Training Team Colleague

Hi :)

Maybe this can be of some use to you:

http://www.onesmartclick.com/programming/java.html
On this site there is a pdf file "Java to C++ Transition Tutorial"
I know that you are going the other way but when I looked (very briefly) it compared a lot of code snippets in both language, so that could be useful.

http://pages.cs.wisc.edu/~hasti/cs368/JavaTutorial/main.html
A Java tutorial whit five lessons and the first is Java vs C++.
It looks at C++ Arrays vs Java Arrays and C++ Classes vs Java Classes

sneaker 25 Junior Poster in Training Team Colleague

Hi

GridBagConstraints.NONE means that the item (text) can not grow.
Change .NONE to .BOTH and see what happens :D

Good luck :)

freelancelote commented: good comment +2
sneaker 25 Junior Poster in Training Team Colleague

Hi

Here is a place to read more about how an applet can read files on the local file system whit a link to a more thorough explanation of the applet security model
http://faq.javaranch.com/java/HowCanAnAppletReadFilesOnTheLocalFileSystem

But be careful.
James advise to load files from server is the best advice.

Good luck =)

sneaker 25 Junior Poster in Training Team Colleague

Why does the thread 3 execute before thread 2 though iam invoking it before thread 3?

Hi

There are two kinds of memory used in Java. Stack memory and heap memory. Stack memory stores primitive types and the addresses of objects. The object values are stored in heap memory but the address (reference) to the stored objects are stored on the stack.

The timer makes the "stop" after your thread is created so the timer that is created first like in

new Welcome(pmsg, "Thread 1", "Hellowa", 1000);

holds the time 1000 afterwards.

In the meantime the other thread objects are created and there references are put on a stack. The stack works after the LIFO principle (last-in-first-out) so when the first "stop" is over the stack releases the last inputted address first.

If you had 6 objects declared the same way, the output would be like:
Thread 1
Thread 6
Thread 5
Thread 4
Thread 3
Thread 2

If you had 6 objects where you declared the time on #1 to 0 and the rest as in your code to 1000, the output would be like:
Thread 1
Thread 2
Thread 6
Thread 5
Thread 4
Thread 3

If you create some more objects you can play around and see very clearly how it works if you put some objects to time 0 and some to time 1000 or 10000.

sneaker 25 Junior Poster in Training Team Colleague

Hi

I am not sure that I understand your problem.
Do you want the information to be showed in a text area in your GUI when someone select the proper menu? Or how do you mean?

Please explain a little bit more =)

sneaker 25 Junior Poster in Training Team Colleague

Explaination: Basically, when my channel1 JCheckBox is checked(selected), the electrodeNum should be equal to 1, but for some reason, electrodeNum still equals to 2. No compiling or runtime issues though. How can I fix this so that when JCheckBox channel1 is checked, the electrodeNum will be equal to 1, and thus, I get the following
gg.analyzeFile(filepath,1); instead of gg.analyzeFile(filepath,2);

I should first of all test if the event e is taken care of inside this method by putting a simple System.out.println() inside the if where you want electrodeNum to change to 1.

Think about where in this method you catch the event e.

Good luck =)

sneaker 25 Junior Poster in Training Team Colleague

If you declare the variable as final, it will work. Otherwise you won't be able to access from within an inner class. And I'd be wary of taking sneaker's advice because I'm not sure that it is completely correct. You might want to do more research if you are concerned about the issue.

PS an IDE like Eclipse would have suggested to you that you should make the variable final, and all you would have had to do is click the link on their suggestion and it would have done it for you.

My advise was to make the variable final =)

When MasterGoGo answered that he/she still was lost I assumed that it did not work and wondered what happened when the variable was declared final.
Since the variable never was declared private or protected I just assumed it was public. I never use anonymous inner classes and ordinary inner classes takes public variables so I was merely expressing my confusion, it was not meant as an advice.

Sorry if I did express myself vaguely and thank you BestJewSinceJC for making it clearer =)

sneaker 25 Junior Poster in Training Team Colleague

If it is declared as public then you should not get this error I believe, strange, but
what happens if you declare the variable as final? Does it work then?

sneaker 25 Junior Poster in Training Team Colleague

I must've forgot, the error is:

Hi
Anonymous inner classes require final variables because of the way they are implemented in Java. The anonymous inner class is using a copy. of the local variable. By declaring the variable final (means that the inner class can not change its value) it is guarantied that the inner class copy of a local variable will always match the actual value.

At java.sun.com you can read more about how it works, or try Google.

So probably you have declared the variable as private and that is why you get this message.

Hope this will help you =)

sneaker 25 Junior Poster in Training Team Colleague

yes i wrote a program to handle files (filehandler)

and my data saved as plain text (in human readable format)

i dont want to show this data in terminal ..i want to open the file that content my data .It's a txt

I was thinking about if you had built an applet or some GUI to show your text in, in a textfield for example, but it does not seem to be that way.
So I belive that solaheres answer will do the trick for you.

Good luck =)

sneaker 25 Junior Poster in Training Team Colleague

I wrote a program to write data in a text file to another text file .what i want to do is to open that modified second text file once I've entered data in to that

Have you written any filehandler?
Is your data saved as plain text (filename .txt) or as objects (filename .dat)?
Because you use different streams to read ".txt" or ".dat".

Is the data be to shown in a terminal whit System.out.print() or in an GUI or applet?

sneaker 25 Junior Poster in Training Team Colleague

Hi
I get the feeling that you are very new at programming Java and feel totally lost?
I will not give you the code to this problem because then you do not learn anything. But I will give you some clues of what to think about.

First make a class like "public class MyCalculation" whit a main inside like
"public static void main(String[]args)"

Now think of what variables do you need outside the method " public static boolean isEven(int i) " ?

Maybe an int i that can take some kind of input maybe from System.in ?
Maybe a boolean that can take the return from the method ?

Look in Java API and think about why your method has a boolean as return.
A boolean can be either false or true. How does the computer read if it is false or true?

Inside your method "public static boolean isEven(int i)" you can calculate your inputed int i whit help of modulus operator, % as suggested before. The result of this operation is what you shall return. Observe that the returning value is expected to be a boolean while the input parameter is expected to be an int.

Think of what the result of the modulus operator is if the number is even?
Do not forget to write the return statement.

When you have got the result I suppose you want to write it out, …

VernonDozier commented: Good first post. +21
KirkPatrick commented: Helpful and a nice attitude about helping. Nice job bud +1