Coding, Linux, Hacking Security, Learning!
Archive for March, 2010
matlab vector operator
Mar 26th
how to write data to file in java
Mar 22nd
<pre lang="java">
import java.io.*;
public class MyFirstFileWritingApp
{
// Main method
public static void main (String args[])
{
// Stream to write file
FileOutputStream fout;
try
{
// Open an output stream
fout = new FileOutputStream ("myfile.txt");
// Print a line of text
new PrintStream(fout).println ("hello world!");
// Close our output stream
fout.close();
}
// Catches any error conditions
catch (IOException e)
{
System.err.println ("Unable to write to file");
System.exit(-1);
}
}
}
</pre>
mysql update command or update syntax for zen cart
Mar 11th
update products set products_statues=’0′ where products_model >=’13888′ and products_model <= ‘13999′
java how to find array length
Mar 7th
String[] mystr = {"c++", "java", "php"} int leng = mystr.length System.out.format("The Java array length is %d", leng);
Java Generating random numbers
Mar 6th
Generating random numbers is simple. Provided as part of the java.util package, the Random class makes it easy to generate numbers. Start by creating an instance of the Random class
// Create an instance of the random class Random r = new Random();
Now, you must request a number from the generator. Supposing we wanted an integer number, we’d call the nextInt() method.
// Get an integer int number = r.nextInt();
Often you’ll want numbers to fall in a specific range (for example, from one to ten). We can use the modulus operator to limit the range of the numbers. This will give us the remainder of the number when divided by ten (giving us a range -9 to +9). To eliminate negative numbers, if the number is less than one we’ll add ten to it. This gives us random numbers between one and ten!
// Accept only up to ten int random_number = number % 10; if (random_number < 1) random_number = random_number + 10;
Creating random numbers in an application or applet really isn’t that difficult. Just remember to limit the range of your numbers, and to import the java.util.Random class.
Generating random numbers in Java
Mar 6th
you need header
java.util.Random;Random diceRoller = new Random();