Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I'm trying to write a Java program that can take values and put them into a formula involving electron. How can I calculate e^x in Java?
you can use java.lang.Math.exp() method to calculate e^x.
here is an example
`
public static void main(String[] args)
{
double a = 2.0;
System.out.println(Math.exp(a));
}
//output = 7.38905609893065
`
you can read more about this using this link.
https://www.javatpoint.com/java-math-exp-method
You could use Math.exp().
Example:
import java.lang.Math;
// inside main
Math.exp(1.0); // e^1
Math.exp(1.6); // e^1.6
import java.lang.Math;
class Answer {
// driver code
public static void main(String args[])
{
double a = 30;
double b = 2;
System.out.println(Math.pow(a, b));
a = 3;
b = 4;
System.out.println(Math.pow(a, b));
a = 2;
b = 6;
System.out.println(Math.pow(a, b));
}
//you can use Math.pow(e,x);
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 days ago.
Improve this question
How to write a loop that will delete those elements of the collection whose numbers form an arithmetic progression, by type if the number 246 deletes, but the second 245 does not, since it does not oblige the progression
import java.util.ArrayList;
public class n {
public static void main(String[] args) {
ArrayList nums = new ArrayList<>();
nums.add(24);
nums.add(223);
nums.add(2424);
nums.add(135);
nums.add(258);
nums.add(246);
for (int i = 0; i < nums.size();i++){
if
}
}
}
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 10 months ago.
Improve this question
I want to make a list of 5 , 5.5 , 6.5 , ++
Can someone show me how to fix it
Here is my code:
package com.bowl.Bowling;
public static void main(String[] args) {
for (double i = 5; i <= 12; i+=0.5) {
System.out.println(i);
i++;
}
}
Output:
5.0
6.5
8.0
9.5
11.0
just delete i++ like here:
public static void main(String[] args) {
for (double i = 5; i <= 12; i+=0.5)
System.out.println(i);
}
in your code, you have two part for update your loop counter which one is i+=0.5 and another one is i++ and you should delete one of them
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 10 months ago.
Improve this question
I have a simple for loop
and I want to change it into a statement using filter
for (int lotto_num: lottos) {
if (lotto_num == 0) {
unknown_count++;
}
for (int win_num : win_nums) {
if (lotto_num == win_num) {
count ++;
}
}
}
is it possible? I dont't really know how to use filter and stream.
In order to use Java's Stram API you should firstly convert your int[] arrays win_nums and lottos to List<Integer>.
It can be done this way:
List<Integer> win_nums_list = IntStream.of(win_nums).boxed().collect(Collectors.toList());
List<Integer> lottos_list= IntStream.of(lottos).boxed().collect(Collectors.toList());
Now we can use Stream API to get the desired result.
int count = win_nums_list.stream().filter(win_num -> lottos_list.contains(win_num)).count();
int unknown_count = lottos_list.stream().filter(lotto -> lotto== 0).count();
with adding imports to the beginning of your code:
import java.util.*;
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I hope this thread isnt against the rules
my problem is
im using macos and i couldnt find a calculator that Divides number and show the reminder and quotient
so i thought there might be a java code that do that
i could program such app but im really on a hurry
couze im studing multiplicate cipher that uses gcd (greatest common diviser )
and i need to culaculate alot of number using the reminder of that calculation
so i thought i bring this here cause there is alot of experienced programs in this form
thanks in advance
I have found the code
//Author : Mayank Rajoria
import java.util.*;
class remainderAndQuotient {
public static void main(String[] args) {
int n, q, a, k = 1, r;
Scanner sc = new Scanner(System.in);
System.out.println("Enter 2 numbers");
n = sc.nextInt();
a = sc.nextInt();
r = n % a;
q = n / a;
System.out.println("Quotient : " + q);
System.out.println("Remainder : " + r);
}
}
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 8 years ago.
Improve this question
I done a coding to get the output 20,40,60,80 and 100.
Multiple.java:
public class Multiple {
static int n=20;
static int m;
public static void main(String[] args) {
for(int i=1;i<=5;i++){
m=n*i;
System.out.println(m);
}
}
}
Output:
20
40
60
80
100
I didn't have any issue in this coding.I got an output successfully.But loop running 5 times.Let me know is there any other way to get these output(20,40,60,80 and 100) in simplest way.
very interesting. if you know the output result (it's fixed), why don't you write them out directly:
System.out.println(20);
System.out.println(40);
System.out.println(60);
System.out.println(80);
System.out.println(100);`
oh i see, you think that's too long. Then probably you can use the below:
int a = 0;
while(a<100){ a += 20; System.out.println(a);}
Enjoy it!