Saturday, March 13, 2010

GUI INPUT

GUI INPUT

import javax.swing.*;

public class Guiinput
{
public static void main(String args[])
{
int a,b,c;
String r,s;
r = JOptionPane.showInputDialog("Enter First Number: ");
a = Integer.parseInt(r);
s = JOptionPane.showInputDialog("Enter Second Number: ");
b = Integer.parseInt(s);
c=a+b;
JOptionPane.showMessageDialog(null,"The Sum of "+a+" and "+b+" is: "+c);
}
}



Friday, March 12, 2010

First GUI Program

First GUI Program

import javax.swing.*;
public class gui
{
public static void main(String args[])
{
JOptionPane.showMessageDialog(null,"First Java GUI Program");
}
}

NOTE: THIS WILL SIMPLY PRINT THE MESSAGE IN A DIALOG BOX.

Tuesday, March 9, 2010

Temperature Converter

Temperature Converter


public class Temprature
{
public static void main(String args[])
{
final double fahrenheit = 95.0;
double celsius;
celsius = (5.0/9.0) * (fahrenheit - 32.0);
System.out.println("\n\t\t\t::Fahrenheit -> Celsius::");
System.out.println("\tFahrenheit "+fahrenheit+" = "+celsius+" Celsius");
System.out.println("\n\t\t\t***THE END***");
}
}

NOTE: IN THIS PROGRAM WE USE "FINAL DOUBLE". FINAL KEYWORD IS USE TO DECLARE ANY CONSTANT.


SCALE CONVERTER

SCALE CONVERTER

import java.util.Scanner;
class Scale
{
public static void main(String args[])
{
double feet,meter;
System.out.println("\t\t\t\t::Feet To Meter::\n");
Scanner input = new Scanner(System.in);
System.out.println("Enter Number of Feet: ");
feet = input.nextDouble();
meter=0.305*feet;
System.out.println(feet+" Feet = "+meter+" Meters.");
}

}


Saturday, March 6, 2010

First Input

First Input
import java.util.Scanner;
public class Input
{
public static void main(String args[])
{
Scanner input= new Scanner(System.in);
int var;
System.out.println("Enter any Integer: ");
var = input.nextInt();
System.out.println("Your Entered: "+var);
}
}
"input.nextInt()" is used to specify that the input we will be taking is an Integer value. You can also try it with other data types like Double, Float, etc.
To take any string value use "input.nextLine()"
Note: input IS ANY VARIABLE YOU CAN NAME IT YOURSELFE.

Quadratic Equation Solving

Quadratic Equation Solving
public class Quadratic
{
public static void main(String args[])
{
double b, a, c, inSqr, total1, total2, toSqr; a = 5;
b = -7;
c = 2;
toSqr = (b*b)-(4*a*c); inSqr = Math.sqrt(toSqr);
total1 = ((-1*b)+inSqr)/(2*a);
total2 = ((-1*b)-inSqr)/(2*a);
System.out.println("\n\n\n\t\t\t::QUADRATIC EQUATION::");
System.out.println("Varibles");
System.out.println("\t-> a = "+a);
System.out.println("\t-> b = "+b);
System.out.println("\t-> c = "+c);
System.out.println("\n\nResult of Quadratic Equation [with +]: "+total1);
System.out.println(" ______________");
System.out.println("(-b)+/(b*b)-(4*a*c)");
System.out.println("-------------------- = "+total1);
System.out.println(" 2a ");
System.out.println("\n\nResult of Quadratic Equation [with -]: "+total2);
System.out.println(" ______________"); System.out.println("(-b)-/(b*b)-(4*a*c)");
System.out.println("-------------------- = "+total2); System.out.println(" 2a ");
System.out.println("\t\t\t***THE END***");
}
}

Friday, March 5, 2010

First Program

First Program
public class First
{
public static void main(String args[])
{
System.out.println("Hello Java.");
}
}
Save this program with the file name as "First.java"
This simple program will just show {Hello Java.} on screen.