Program-1
Use Eclipse or NetBeans platform and acquaint yourself with the
various menus. Create a test project, add a test class, and run it. See
how you can use auto suggestions, auto fill. Try code formatter and
code refactoring like renaming variables, methods, and classes. Try
debug step by step with a small program of about 10 to 15 lines
which contains at least one if else condition and a for loop.
// Prime Number between 1 to 100
Code :
public class PrimeNumbers {
public static void main(String[] args) {
[Link]("Prime numbers between 1 and 100 are:");
for (int num = 2; num <= 100; num++) {
int count = 0; // counter for divisors
// check how many numbers divide 'num'
for (int i = 1; i <= num; i++) {
if (num % i == 0) {
count++;
}
}
// prime numbers have exactly 2 divisors: 1 and itself
if (count == 2) {
[Link](num);
}
}
}
}
// Fibonacci Sereis
public class FibonacciSeries {
public static void main(String[] args) {
int n = 10; // number of terms
int a = 0, b = 1; // initial numbers
[Link]("Fibonacci Series up to " + n + " terms:");
for (int i = 1; i <= n; i++) {
[Link](a + " "); // print current number
int sum = a + b; // add previous two
a = b; // move forward
b = sum;
}
}
}