Java Codes

Posted: January 18, 2011 in Java

import java.util.*;

class apples{

public static void main(String args[]) {

FOR GENERATING RANDOM BITS

Random r = new Random();

for(int x=1; x<5; x++)

{

int i = r.nextInt(2);

System.out.print(i);

}

FOR INPUT FROM KEYBOARD

1. For Strings

System.out.print(“Enter your name: “);

Scanner whatever = new Scanner(System.in); System.out.println(whatever.nextLine());

2. For integers

Scanner lambda = new Scanner(System.in);

int num= lambda.nextInt();

CALCULATING EXPONENTIAL

System.out.println(“e^”+ num”= ” +Math.exp(num))

CALCULATING EXPONENTIAL POWER 1

System.out.println(“The value of e is ” + Math.E);

CALCULATING LOG

System.out.println(“log(” + j + “) is ” + Math.log(j));

CALCULATING POWER

System.out.println(“pow(” + j + “, ” + y + “) is ” + Math.pow(j, y));

CALCULATING SQUARE ROOT

System.out.println(“sqrt(” + j + “) is ” + Math.sqrt(j));

FOR log10

ans= Math.log10(ans);

ROUNDING OFF

ans=Math.round(ans);

REPAINT

public void update (Graphics page)
{
paint(page);
}

That way, instead of updating the whole page (which erases first), it just draws to it.

REFERENCES

http://www.java2s.com/Code/Java/Development-Class/ExponentialDemo.htm

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s