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
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 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);
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 5 years ago.
Improve this question
I am making a Java game and am trying to get blocks to spawn alternating back and forth on the x-axis using a for loop.
Just do something like this:
spawn(0);
for(int i = 1; i <= 3; ++i)
{
spawn(-i);
spawn( i);
}
Method createBlock(): //creates the blocks at desired x axis
createBlock(0); //initial block placed at 0
int howMany= input
for (i=0; howMany;i++){
createBlock(-i)
createBlock(i)
}
IntStream.iterate(0, i -> i >= 0 ? -i - 1 : -i). limit(100).forEach(i -> System.out.println(i));
System.out.print(0);
for (int i = 1; i<=3; i++) {
System.out.print(String.format(",%s,%s", -i, i));
}
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!
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
In my project, I want to show a paginator. I have 100 employee Objects in my ArrayList, now I want to show on every page only 10 objects (means 10 employee's information). On a click on next, I want to show the next 10 records.
How can I do this?
Here is the basic principle of a pagination system:
public static void main(String[] args) {
final int pageNumber = *X*;
// list containing numbers from 1 to 100
final List<Integer> list = populatedList();
final int RESULTS_PER_PAGE = 10;
// algorithm
int to = pageNumber * RESULTS_PER_PAGE;
int from = to - RESULTS_PER_PAGE;
for (int i = from; i < to; i++) {
System.out.println(list.get(i));
}
}
public static List<Integer> populatedList() {
List<Integer> list = new LinkedList<Integer>();
for (int i = 1; i <= 100; i++) {
list.add(i);
}
return list;
}
For example, with pageNumber = 2, you'll get the following output:
11
12
13
14
15
16
17
18
19
20
Which technology?
Do you are developing web or desktop application?
If you are using web application with JSF you can use primefaces table pager:
http://www.primefaces.org/showcase/ui/datatablePagination.jsf
It is very easy.