I'm trying to calculate sin(x) without using Math.sin(x). The formula for sin(x) is: x - x^3/3! + x^5/5! ... I can't seem to get the coding for the alternating +/- right. Here's my program:
import java.util.Scanner; import java.lang.Math; class Sin { public static void main(String[] args) { Scanner kb = new Scanner(System.in); int n, c, fact = 1, count = 1; double x, sum = 0, sum_sin = 0, result;
Given a string of numbers and operator. Compute as follows:
Consider, "000293000002030403+0400293059694" is the input.
a. Separate the two operands and one operator: "000293000002030403" "+" "0400293059694"
b. On each string operand, take each digit. ADD them all. (2+9+3+2+3+4+3) + (4+2+9+3+5+9+6+9+4) The two string operands should now become two integers.
c. Lastly, perform the operation using the string operator specified on the original string. 26 + 51 = 77
I don't know why I get the sum of 52 when I use a for loop.
Here are my codes:
public class string2math { public static void main(String[] args) { String input = "000293000002030403+0400293059694"; String [] operand = input.split("+"); String firstOpera = operand[0];
I'm having extreme troubles with my outputs not displaying the correct math. I have everything organized how I want it, it's just not giving me the correct answers.
The code is supposed prompt the user to enter an investment amount and an interest rate and display the future investment amount for years 1-30. The formula for this is:
import java.util.Scanner; public class InvestmentValue { public static void main(String[] args) { // prompt user to enter data Scanner scan = new Scanner(System.in); System.out.println("The amount invested: ");
[Code] ....
And I have to use a method to do this as it is what we are learning in class right now. A sample output as of now is:
The amount invested: 1000 Annual interest rate: 9 Years Future Value 11.0E15 21.0E27
[Code] .....
And obviously a future investment amount cannot equal infinity.
I am trying to complete an assignment and I am stuck on a key point. I must print the total inventory value across each of these arrays, as it prints for each "list". To do this, I understand that I need some form of correlation between my variables "total" and "Price" between each array. My quandary lies in the way that I have designed this code to begin with. I am not sure where to add the math section of code that is needed, nor am I fluent enough with Java to know how to call all of the arrays as it prints. Listed below is my code, when you compile it the total inventory value is 0 for each "list".
package inventory; public class Inventory { public static void main (String[] args) { List[]list = new List[5];
building a game. the game is all about the multiple times table with levels. easy medium and difficulty. I dont even know where to begin and what is the codes to use or even the platform. what websites can be access etc and what is the big deal with code tags.
i am trying to calculate the number of months it takes to pay off a set amount of credit card debt given the following information: principle amount, annual interest rate, and monthly payment. How to import the formula necessary to system.out.print the answer (number of months it takes to pay off debt) ???
This program is supposed to ask for the operator (+ or -) then ask you for two numbers and do the math. When I run it it comes up- Enter operator. When I say add or sub nothing happens. Here it is:
import java.util.Scanner; public class Echo1{ public static void main(String args[]){ Scanner userInput = new Scanner(System.in); System.out.println("Enter Operator"); String operator = userInput.next();
I am a 3rd year electrical engineer and I am working on a project on solar cell design in the developing world.For my project I am looking to create a very simple web page which can be used by people in the developing world to determine whether a photo voltaic system is suitable to their needs.
For this I want to have simple boxes where a user can input numbers and I used complex calculations to return values (a lot of trigonometric functions etc.), the values then should have the opportunity to be altered to the users digression. This will create a solar model.
For the load aspect of it I am looking to have drop down boxes for a number of components which the user can select and will have a numerical value in Watts which will sum to give total load on system. Ideally I would like to show this graphically in a pie chart showing how much energy each component is taking to give the option to remove.
I am also creating a statistical model which determines the likelihood of having no sunlight on a given day which looks at the solar output, battery capacity and load on the system and will return reliability of the system - this has not been completed but should be shortly.
Aim is to keep web page as simple as possible as unskilled computer users may want to use it.
So basically I am trying to get it that the number inside the square root isnt negative. So lets say I enter a: 1, b: -1, c: 4.25. When you do the discriminant it would be -16 but I want that to be positive so I multiple it by -1 (thats the dem part). Then I sqaure root the whatever the answer is and then go to the imagine and imagineneg part where you find the imaginary number.
My problem is that instead of it being -16*-1 to get 16, some how I get 15.
I am trying to make a calculator that ranges from simple math to trig. I am trying to start the j-frame for it and I already have most of the formulas programmed with the if-else statements and such. How do I go about starting the jFrame and marrying the 2 codes together to start it. (I have taken a bit of programming but relatively new to writing j-frames and using other classes and putting them together).
So my little math game is working so far. I can only do addition though. I know how to fix it if I can find out how to generate random math operators. After that I want to use a loop (or a better technique) to ask ten different math questions before the game is over.
package pkgnew; import java.util.Scanner; import java.util.Random; public class New { public static void main(String args[]) { //Declare and construct variables Random randomnum = new Random();
I want make a math equation game. usually math game use equation for the question and we answer that equation. ex : what is the result of 2*5 / 2+2/ 2^2 etc. and we answering that. but i want to make it different so i want to make the equation answer as the question and the equation as the answer of the game. Ex : the question is 54 so we can answer it with 9*6 or 24+30. and this is my java code
package coba; import java.util.Scanner; public class Coba {
public static void main(String[] args) { double angka = Math.random()*70;
[Code] ....
but when i run it the error code show like this : Quote
The area of a square is stored in a double variable named area . Write an expression whose value is length of the diagonal of the square. Do I use math.sqrt?
I am running into some trouble with Line-Plane intersection, my method works, provided I am perpendicular to the plane I want to intersect. This is caused be the plane equation (with my given x, y, and z coordinates, the equation is -Z - 1 = 0). So the equation is only relying on the Z value of anything inputted. Is there another way to calculate the equation of a plane that would rely on all axis? Here is my current code:
Java Code:
Vector3f A = new Vector3f(0, 0, -1); Vector3f B = new Vector3f(0, 1, -1); Vector3f C = new Vector3f(1, 1, -1);
How do you use power of math. I'm trying to write a calculator to calculate the volume of a cylinder by asking the user to enter the height and radius but when I use pow(2) it doesn't work. I imported java.lang.math class so i dont have to keep using math. for now my code runs just fine since I'm using radius * radius but I would really luv to use the power instead times each other when i have to use higher powers.
import java.util.Scanner; import static java.lang.Math.*; public class Lab2 { public static void main(String[] args) { Scanner scan = new Scanner(System.in);
i am migrating my web application from Server1 (Tomcat 5 and Java 1.5) to Server2 (Tomcat 7 wand Java 1.6).
In my web application, I have multiple adapters (web clients) that are connecting to external web services, https interfaces, sftp servers etc.
In order to connect with all these external interfaces, i have installed multiple certificates in my JRE keystore on Server1.
Now since the application is going to be migrated to Server2, i need to know if there is any way I can import all the existing certificates from Server1 JRE to Server2 JRE?
Since the application has been running on Server1 for a long time, I am not sure, what exactly is a complete list of certificates that I need to install on my Server2 JRE.
So i am kind of looking how can i generate the keystore file with certificates from the existing server1 JRE and then import it into Server2 JRE.
Does this command provide a list of all the installed certificates on my Server1 JRE?
The other solution i can think of is to manually download/save all the certificates by opening all the URLs in the browser and then import the .pfx files through keytool into my Server2 JRE.
how to make a simple game. I am having trouble when it comes to adding sound though. It tells me to do this:
package net.game.Game;
import java.applet.Applet; import java.applet.AudioClip; public class Sound { public static final AudioClip BALL = Applet.newAudioClip(Sound.class.getResource("ball.wav")); public static final AudioClip GAMEOVER = Applet.newAudioClip(Sound.class.getResource("gameover.wav")); public static final AudioClip BACK = Applet.newAudioClip(Sound.class.getResource("back.wav")); }
What this does is it gets the sound file then gives it a name(BALL=ball.wav GAMEOVER=gameover.wav ect..) and then there is other code in other classes that call the sound so it will run but it keeps giving me an error and I don't know what to do. How can I get it to import the sound? Here is the error.
PHP Code:
Exception in thread "main" java.lang.ExceptionInInitializerError at net.game.Game.stuff.<init>(stuff.java:35) at net.game.Game.stuff.main(stuff.java:62) Caused by: java.lang.NullPointerException at sun.applet.AppletAudioClip.<init>(Unknown Source) at java.applet.Applet.newAudioClip(Unknown Source) at net.game.Game.Sound.<clinit>(Sound.java:7) ... 2 more
I'm making an import/export of xml - I have the import of xml sorted I'm just trying to finish off the export. My export class is called XmlWriter.java. Inside the class I have an updateFile method to update an xml file as such:
public void updateFile(Environment environment,Document doc) { // code }
I then in my main method have
public static void main(String argv[]){ //declare new object of class XmlWriter xmlWriter = new XmlWriter(); //test testUpdate method // xmlWriter.testUpdate(); Environment environment = ;
[code]....
I don't know what to make my variables equal to - eclipse keeps trying to use null but obviously that won't work. The Environment is another class that just contains getters and setters for the 3 different databases (that are in the xml file) and the getter/setter for the environment ID (also in xml file).