This is a part of challenges by Local Hack Day organized by MLH
We learnt about a new programming language which is JAVA. We have planned and choose a programming language which was new to all of us. We have tried and gone through the basics of that programming language.
- Calculate the Factorial of a Number By Sheetal Sharma
Sheetal's code goes here
- Print Fibonacci sequence upto n terms By Aditya Arpan
public class lhd {
static int fib(int x) {
if (x == 0) {
return 0;
} else if (x == 1) {
return 1;
} else {
return fib(x - 1) + fib(x - 2);
}
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter The number of terms: ");
int n = sc.nextInt();
for (int i = 0; i <= n; i++) {
System.out.print(fib(i) + " ");
}
}
}
- Program to calculate BMI of a person By Rishita Nayak
public class lhd {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
System.out.print("Input weight in kilogram: ");
double weight = sc.nextDouble();
System.out.print("\nInput height in meters: ");
double height = sc.nextDouble();
double BMI = weight / (height * height);
System.out.print("\nThe Body Mass Index (BMI) is " + BMI + " kg/m2");
}
}
- Print Fibonacci sequence upto n terms By Mrunank Pawar
public class lhd {
public static void main(String[] args) {
Scanner prime = new Scanner(System.in);
System.out.println("Enter a number: ");
int n = prime.nextInt();
boolean isPrime = true;
for (int i = 2; i < n; i++) {
if (n%i == 0) {
isPrime = false;
break;
}
}
if (n < 2) isPrime = false;
System.out.println(isPrime);
prime.close();
}
}