Below is a Java program to print the Fibonacci series:
public class FibonacciSeries {
public static void main(String[] args) {
int n = 10; // Number of terms in the Fibonacci series to print
fibonacciSeries(n);
}
public static void fibonacciSeries(int n) {
int first = 0;
int second = 1;
int next;
System.out.println("Fibonacci Series up to " + n + " terms:");
for (int i = 0; i < n; i++) {
if (i <= 1)
next = i;
else {
next = first + second;
first = second;
second = next;
}
System.out.print(next + " ");
}
}
}
Explanation:
This program defines a method `fibonacciSeries` that takes an integer `n` as input and prints the Fibonacci series up to the `n`th term. In the `main` method, we call this method with `n = 10`, but you can change the value of `n` to print the Fibonacci series up to a different number of terms.