Calculating Sin(x) Without Using Math

Sep 14, 2014

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;

[Code] ....

View Replies


ADVERTISEMENT

Split A Math Expression?

Feb 27, 2015

I have a math expression in a String, that I want to split into 4 pieces as in the following example:

String math = "23+4=27"
int num1 = (23 STORES HERE)
int num2 = (4 STORES HERE)
String operator = (+ STORES HERE)
int answer = (27 STORES HERE)

Note that the operator can be either + - * /

View Replies View Related

Using MATH Class For Assignment?

Sep 18, 2014

Here is the assignment:

Prompt the user to input two sides (a and b) of a right triangle. Calculate, using the

formulas below, the hypotenuse and the other two angles of the triangle. Calculate the

perimeter and the area.

Here are the formulas:

a^2 + b^2 = h^2

sinθ = a/h

A + B + C = 180 degrees

how to start this program out, i know which math classes i need to use.

View Replies View Related

String To Math Operation

Sep 14, 2014

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];

[Code] ...

View Replies View Related

Use Math Methods Without Import In IDE

Feb 22, 2014

package statics;
public class Test_main {
public static void main(String[] args) {
Math.log(50.00);
}
}

I am able to use a Math method without importing the java.lang.Math. Which makes me think

1) What is the use of the import statement in java?
2) Is my IDE taking care of the import automatically?

I am using Eclipse IDE and JDK 1.7.

View Replies View Related

Outputs Not Displaying Correct Math

Oct 14, 2014

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:

futureInvestmentAmount = investmentAmount * (1 + monthlyInterestRate)^(numberOfYears*12)

Here is my code:

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.

View Replies View Related

Math Integration Across Multiple Arrays

Feb 14, 2014

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];

[code]...

View Replies View Related

Building Multiple Math Games?

Nov 23, 2014

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.

View Replies View Related

Converting Math Formula To Java?

Jan 20, 2015

I'm trying to convert a Formula to run in a java program.

This is the formula:

(you can ignore the modifier part)

This is my attempt. However it prints out 0.0

import java.util.Scanner;
public class DamageCalc{
public static void main(String[] args){
Scanner s = new Scanner(System.in);

[Code].....

View Replies View Related

Importing Math Formula To Java

Sep 1, 2014

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) ???

View Replies View Related

Program Ask For Operator And Two Numbers And Do Math

Feb 17, 2015

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();

[Code] ....

View Replies View Related

Complex Math Functions With A Simple Web Page?

Feb 4, 2015

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.

View Replies View Related

Java Math - Find Imaginary Number

Nov 2, 2014

I am doing this math for my assignment where you have to find the imaginary number.

double dem = (b*b-4*a*c)*-1;
double dem2 = Math.sqrt(dem);
realPart = (-b/(2*a));
imagine = (dem2)/(2*a);
imagineneg = (dem2)/(2*a);

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.

View Replies View Related

Calculator That Ranges From Simple Math To Trig

Nov 15, 2014

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).

View Replies View Related

Random Math Operators And Asking Ten Questions With A Loop?

May 18, 2014

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();

[code].....

View Replies View Related

Math On Three Numbers - Get Average / Sum And Number Entered By User

Feb 25, 2015

Java program : For this assignment you are going to write code for the following class:

MathOnThreeNumbers

Here are the specifications of class MathOnThreeNumbers:

Methods of class MathOnThreeNumbers:

1. inputThreeNumbers
2. getAverage
3. getSum
4. getNumberOne
5. getNumberTwo
6. getNumberThree

Constructor of class MathOnThreeNumbers

write a constructor that initializes the first, second, and three numbers to 1, 2, and 3 respectively.

Specs for the methods methods:

1.
name: inputThreeNumbers
accessibilty: public
arguments: none
what it does: asks the user for three numbers of type double

2.
name: getAverage
accessibilty: public
arguments: none
what it does: returns average of the three numbers

3.
name: getSum
accessibilty: public
arguments: none
what it does: returns sum of the three numbers

4.
name: getNumberOne
accessibilty: public
arguments: none
what it does: returns the first number entered by the user

5.
name: getNumberTwo
accessibilty: public
arguments: none
what it does: returns the second number entered by the user

6.
name: getNumberThree
accessibilty: public
arguments: none
what it does: returns the third number entered by the user

Here is an example of how the class MathOnThreeNumbers works. The following code produces the output displayed after the code.

MathOnThreeNumbers mm = new MathOnThreeNumbers();
System.out.println("first: " + mm.getNumberOne());
System.out.println("second: " + mm.getNumberTwo());
System.out.println("third: " + mm.getNumberThree());
mm.inputThreeNumbers();

[Code] .....

View Replies View Related

Math Equation Game - Making Answer As Question

Apr 26, 2014

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

View Replies View Related

Java Math - Write Expression Whose Value Is Length Of Diagonal Of Square

Jul 24, 2014

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?

View Replies View Related

Vector Math - Calculate Equation Of A Plane That Would Rely On All Axis

Jan 27, 2014

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);

Vector3f v1 = new Vector3f(B.x - A.x, B.y - A.y, B.z - A.z);
Vector3f v2 = new Vector3f(C.x - A.x, C.y - A.y, C.z - A.z);

float[] i = new float[]{v1.x, v2.x};
float[] j = new float[]{v1.y, v2.y};
float[] k = new float[]{v1.z, v2.z};

[Code] ....

View Replies View Related

Power Of Math - Calculate Volume Of A Cylinder By Asking User To Enter Height And Radius

Jan 29, 2015

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);
 
[Code] .....

View Replies View Related

Calculating Pi In While Or Do While Loop

Oct 23, 2014

USING A WHILE OR A DO-WHILE LOOP write a program to compute PI using the following equation:

PI = 3 + 4/(2*3*4) - 4/(4*5*6) + 4/(6*7*8) - 4/(8*9*10) + ...

Allow the user to specify the number of terms (5 terms are shown) to use in the computation. Each time around the loop only one extra term should be added to the estimate for PI.

Alter your solution from part one so that the user is allowed to specify the precision required between 1 and 8 digits (i.e. the number of digits which are correct; e.g. to 5 digits PI is 3.14159), rather than the number of terms. The condition on the loop should be altered so that it continues until the required precision is obtained. Note that you need only submit this second version of the program (assuming you have it working).

View Replies View Related

Calculating Factorial Of Int Number

Mar 2, 2014

I'm working on some exercises and I'm having some problems with a method. I want to create a method to calculate the Factorial of an int number. I already wrote code that asks the user to input an int number and it calculates the Factorial, and it works fine

i.e.: if I input 5 it outputs

5! = 120

as it should. Here's the code:

import java.util.Scanner;
public class Factorial1 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int number;
int total = 1;
 
[Code] ....

Now I want to make a method to re-use this code in other programs and I wrote this program:

public class TestClass {
public static void main(String[] args) {
System.out.print(factorial(5));
}
  public static int factorial(int x) {
int total = 0;

[Code] ....

But when I run this program it outputs 0 instead of 120. What is wrong with this code as it compiles just fine but doesn't work as intended.

View Replies View Related

Calculating Factorials Using BlueJ

Oct 7, 2014

I am trying to calculate factorials using BlueJ. All of my factorials calculate correctly, I am just having an issue with something the instructor asked of us. She asked us to force the loop to stop when the user inputs "Calculate the factorial of 0", and not give any print.

So far I have my for loop with the correct conditions, I am just really confused as to how to make an if statement to stop the code when the input is 0.

View Replies View Related

Calculating Average Of Values

Apr 21, 2014

I'm struggling with this assignment I was given:

Given list of positive integer values, write a program to calculate average of the values. List terminates with -1.

View Replies View Related

Calculating FPS - Delta Variable

May 26, 2014

I am working on the first example in this java game programming book. I am having trouble understanding this basic concept. How does the delta variable work throughout this class? I know the syntax I just don't understand the concept fully.

Explain these components of the program:

1) delta += current-lastTime works
2) lastTime = current;
3) if(delta > 1000)
{
delta-1000
....
}

package javagames.util;
public class FrameRate {
private String frameRate;
private long lastTime;
private long delta;
private int frameCount;

[Code] .....

View Replies View Related

Calculating Total Payout

Jun 5, 2014

what I'm missing to calculate the Total Payout that Payroll has given out to two employees. the professor states that we have to use "getTotalPayout" . It would have been easy to do "(employee1.getFinal() + employee2.getFinal())" but he use getTotalPayout.

public class Payroll
{
private String employeeId;
private int hourlyrate, hoursworked;
private int increaseHours = 10;
private double TotalPayout;

[code]....

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved