Here’s a Java program to find the Fibonacci series up to a given number:
import java.util.Scanner;
public class FibonacciSeries {
public static void main(String[] args) {
int n, t1 = 0, t2 = 1;
Scanner scanner = new Scanner(System.in);
System.out.print("Enter the number of terms: ");
n = scanner.nextInt();
System.out.print("Fibonacci Series: ");
for (int i = 1; i <= n; ++i) {
System.out.print(t1 + " + ");
int sum = t1 + t2;
t1 = t2;
t2 = sum;
}
}
}
In this program, we first take user input for the number of terms in the series. We then initialize two variables `t1` and `t2` to 0 and 1 respectively, which are the first two terms of the series. We then use a for loop to generate the Fibonacci series up to the given number of terms.
Inside the loop, we first print out the current term `t1`, and then calculate the next term `sum` by adding the previous two terms `t1` and `t2`. We then update the values of `t1` and `t2` to prepare for the next iteration of the loop.
At the end of the loop, we have printed out the entire Fibonacci series up to the given number of terms.