Tech Support Guy banner
  • Please post in our Community Feedback thread for help with the new forum software! If you are having trouble logging in, please Contact Us for assistance.
Status
Not open for further replies.
1 - 3 of 3 Posts

·
Registered
Joined
·
4 Posts
Discussion Starter · #1 ·
I am in a Java programming class. One of my assignments is to write a program that uses Einstein's formula to calculate the amount of energy an amount of mass would make. Then it has to tell how many light bulbs it could light up. It keeps calculating incorrectly and I was wondering if there is something wrong with my script.

import java.util.Scanner;
public class EMCSquared {

public static void main(String[] args) {

int mass;
int bulbs;
int energy;
int speed = 300000000;

Scanner M = new Scanner(System.in);
System.out.print("Enter the mass of an item in KG--> ");
mass =M.nextInt();
energy=mass*speed*speed;
System.out.println("That mass would produce "+energy+" Joules of energy");
bulbs=energy/360000;
System.out.println("That is enought energy to light up "+bulbs+" light bulbs!");

}
}
 

·
Registered
Joined
·
20,583 Posts
Also:

1 joule = 1 kg-m2/s2, i.e. E (joules) = m (kg) * (299,792,458 m/s)2

-- Tom
 
1 - 3 of 3 Posts
Status
Not open for further replies.
Top