Skip to content

Latest commit

 

History

History
84 lines (67 loc) · 2.37 KB

File metadata and controls

84 lines (67 loc) · 2.37 KB

LHD Challenge: Learn a New Programming Language

This is a part of challenges by Local Hack Day organized by MLH

What we have learnt:

JAVA

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.

Below there are some basics programs which we have written in java language:

Sheetal's code goes here
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) + " ");
  	}
  }
}
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");
		 }
  }
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();
  }
}