Skip to content

Instantly share code, notes, and snippets.

@au5ton
Last active August 29, 2015 14:08
Show Gist options
  • Save au5ton/d2c5c5f8b4f680a60fce to your computer and use it in GitHub Desktop.
Save au5ton/d2c5c5f8b4f680a60fce to your computer and use it in GitHub Desktop.
import java.util.Arrays;
import java.util.Scanner;
public class Chemistry
{
static Scanner console = new Scanner(System.in);
public static void main(String[] args)
{
for(;;)
{
System.out.print(">> ");
String str = console.nextLine();
String[] a = str.split(",");
System.out.println(Arrays.toString(a));
try
{
String mode = a[0];
double[] d = {Double.parseDouble(a[1]),Double.parseDouble(a[2])};
System.out.print("\n");
if(mode.equals("w2e"))
{
System.out.println(wavelengthToEnergy( f(d[0],d[1]) ));
}
else if(mode.equals("w2f"))
{
System.out.println(wavelengthToFrequency( f(d[0],d[1]) ));
}
else if(mode.equals("f2e"))
{
System.out.println(frequencyToEnergy( f(d[0],d[1]) ));
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
public static final double c = (3.0)*(double)Math.pow(10,8); //Speed of light
public static final double h = (6.626)*(double)Math.pow(10,-34); //Plank's constant
public static double f(double dec, double exp)
{
return (dec)*(double)Math.pow(10,exp);
}
public static double wavelengthToEnergy(double w)
{
return frequencyToEnergy(wavelengthToFrequency(w));
}
public static double wavelengthToFrequency(double w)
{
return c/w;
}
public static double frequencyToEnergy(double f)
{
return f*h;
}
}
@au5ton
Copy link
Author

au5ton commented Oct 24, 2014

Screenshot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment