find sin-1 of user input for ladder hight [closed] - java

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
I'm trying to find the sin of a number that the user inputs say for eg 1.5. I've done it on the calculator and it works but the code is not working.
Here is the code:
package msd1;
import java.util.Scanner;
public class Part3
{
public static void main(String[] args)
{
Scanner scanner = new Scanner(System.in);
System.out.println("Enter a number");
double Height = scanner.nextDouble();
double Angle = Height/2;
double asine = Math.asin(Angle);
System.out.println("Arcsine of " + Angle + " = " + asine);
}
}

Your variable names make no sense. A "height" is a length, and dividing a length by 2 doesn't give you an "angle". Furthermore, you don't pass an "angle" to asin, you pass it a number from -1 to +1 and it returns an angle.
In your case, you'd want to want to take the height of the ladder and divide it by its length to give you your sin (between -1 and +1), then take the asin of that value.
Odds are you also want to take the angle returned by asin in radians and convert to degrees.
You might have code like this:
double lengthOfLadder = 2.0;
double height = scanner.nextDouble();
double sine = height / lengthOfLadder;
double angleInRadians = Math.asin(sine);
double angleInDegrees = angleInRadians / Math.PI * 180;

Related

How to calculate gravitational force? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I am getting the wrong output for the code below. G = 6.674 x 10^-11. I am supposed to get 3.559466666666664e+22 but I am getting 8.0088E44. Can someone please explain what I have wrong on my code? I will appreciate it. The inputs are 2e30 6e24 1.5e11
import stdlib.StdOut;
public class GraviForce {
public static void main(String[] args) {
double m1 = Double.parseDouble(args [0]);
double m2 = Double.parseDouble(args [1]);
double r = Double.parseDouble(args [2]);
double G = 6.674e-11;
double f = G * (m1 * m2) / r * r;
StdOut.println(f);
A simple operator associativity mistake - missing parens:
double f = G * (m1 * m2) / (r * r);

Put point in string value (android java) [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I have BMI calculator app that takes some input and puts it in "EditText". Here is what I am trying to do:
If the input is 170, it will become 1.70.
If the input is 1.70, it will not change.
This is the code I have:
String weight = editText.getText().toString();
Cant you convert the string to an integer and take modulus 100 to the cms and divide by 100 to get in meters?
You can convert the String weight to int like this
int wgt = Integer.parseInt(weight);
Then separating meters and centimetres.
int mtrs = wgt / 100;
int cms = wgt % 100;
Then combining both
String result = mtrs + "." + cms;
try something like this
float value = Float.parse("170");
editText.setText(String.Format(Locale.ENGLISH,"%,02f", value/100f))
I found this way works: I take the number that the user put, and then "170/100" + "0" gives me 1.70

Calories burned program not returning the answer it is supposed to return [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
I'm trying to write a simple program from this task.
The number of calories burned per hours by cycling , jogging, and swimming are 200, 475, and 275 respectively. A person loses 1 pound of weight for each 3500 calories burned. Write a program that declares 3 variables, one to store the number of hours spent jogging, the second to store the number of hours spent cycling and the third to store the number of hours spent swimming. Assign each of these variables values. Calculate and display the number of pounds worked off.
The code I have written is:
public class task2
{
public static void main(String[] args)
{
double c = 2; //2 hrs of cycling
double j = 1; //1 hr of jogging
double s = 2; //2 hrs of swimming
double cycle = c * 200; //400 calories
double jog = j * 475; //475 calories
double swim = s * 275; //550 calories
double sum = cycle + jog + swim / 3500; //1425 / 3500 is what should be in here
System.out.println("You've burned " + sum + " calories");
}
}
The answer I get back is:
"You've burned 0.40714286 calories"
but I get back:
"You've burned 875.15871428571428 calories".
I don't know where I went wrong. I want the output to be a double so it can show the answer if it's below 3500 calories.
You might meant: double sum = (cycle + jog + swim) / 3500;
You need () to group all the +'s so that the addition is carried out before the division:
double sum = (cycle + jog + swim) / 3500;

error: cannot find symbol input.nextdouble [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 9 years ago.
Improve this question
Cant figure out why I keep getting this error. I'm trying to write a program that will add the sum of a 2 digit number.
SplitNum.java:9: error: cannot find symbol
double digit = input.nextdouble();
^
symbol: method nextdouble()
location: variable input of type Scanner
1 error
Code:
import java.util.Scanner;
public class SplitNum
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
System.out.print("Enter 2 digit number");
double digit = input.nextdouble();
double tens = digit / 10.0;
double ones = digit % 10.0;
double sum = tens+ones;
System.out.println(sum);
}//end main
}//end class
Change the method name
nextdouble() to
nextDouble()
It's supposed to be input.nextDouble() instead of input.nextdouble()
In Java, coding conventions say that for method names, the first letter of every word, excluding the first one, must be capitalized.

Quick java clarification needed for student [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am reviewing a piece of code that looks like this:
float x = 9;
float y = 5;
int z = (int)(x / y);
Question:
I am wondering why there is a second int on line 3 when it is already declared that z is an int. Thanks in advance.
The result of the division x / y is a float. Java doesn't allow you to assign to an int variable like this, with a narrowing primitive conversion (here, to an int), because this would potentially lose precision. But Java will allow you to do this with an explicit cast, in which Java assumes you know what you're doing.
You have to declare the result (x/y) to be int, otherwise you are trying to set the value of an int variable with a float, which generates a compiler error. This purposeful declaration is required when reducing the precision or range of a number.
According to compilers we are kiddo's.. therefore he(the compiler) wants us to explicitly mention that what we are doing is on purpose and not a mistake, hence we need to specify explicitly..
These are the two scenarios:
1) With (int):
**Program:**
class fox
{
public static void main(String args[])
{
float x = 9;
float y = 5;
int z = (int)(x / y);
System.out.print(z);
}
}
**Output:**
# 1: hide clone input 8 seconds ago
result: success time: 0.07s memory: 380224 kB returned value: 0
input: no
output:
1
2) Without (int):
**Program:**
class fox
{
public static void main(String args[])
{
float x = 9;
float y = 5;
int z = (x / y);
System.out.print(z);
}
}
**Output:**
Main.java:7: error: possible loss of precision
int z = (x / y);
^
required: int
found: float
1 error
# 1: hide clone 6 seconds ago
result: compilation error
// see the compiler cannot understand that we wish to do it purposefully,,

Categories

Resources