Skip to content

Instantly share code, notes, and snippets.

@jimmy087
jimmy087 / Exercise9_9.java
Created May 4, 2013 06:14
A method for bubble sort
public class Exercise9_9 {
public static void main(String[] args) {
String [] s1 = {"a", "b", "e", "f", "g", "d", "c", "h"};
sort(s1);
for (int i = 0; i < s1.length; i++) {
if (i < s1.length - 1) {
System.out.print(s1[i] + ", ");
}
else {
System.out.print(s1[i] + ".");
@jimmy087
jimmy087 / Exercise9_15.java
Created May 4, 2013 06:16
A program for finding out the upper case letter in a string.
// A program for finding out the upper case letter in a string.
public class Exercise9_15 {
public static void main(String[] args) {
java.util.Scanner input = new java.util.Scanner(System.in);
System.out.println("Please enter a string: ");
String s1 = input.nextLine();
int [] counts1 = countUpperCaseLetters(s1);
for (int i = 0; i < counts1.length - 1; i++) {
if (counts1[i] != 0) {
@jimmy087
jimmy087 / TotalArea.java
Created May 4, 2013 06:21
Print Circle Array and total area of the circle
public class TotalArea {
public static void main(String[] args) {
//Declare circleArray
Circle3[] circleArray = createCircleArray();
//Print circleArray and total areas of the circles
printCircleArray(circleArray);
}
public static Circle3[] createCircleArray() {
@jimmy087
jimmy087 / Exercise8_4.java
Created May 4, 2013 06:23
print random numbers in java
import java.util.Random;
public class Exercise8_4 {
public static void main(String[] args) {
Random random = new Random(1000);
for (int i = 1; i < 5000; i++) {
if (i % 10 != 0) {
System.out.print(random.nextInt(2000) + "\t");
}
else {
@jimmy087
jimmy087 / ComputeBMI.java
Created May 4, 2013 12:30
Compute Body Mass Index
import java.util.Scanner;
//Compute BMI
public class ComputeBMI {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Please enter your weight in pounds: ");
double weightPound = input.nextDouble();
System.out.print("Please enter your height in inches: ");
double heightInch = input.nextDouble();
@jimmy087
jimmy087 / MonteCarloSimulation.java
Created May 4, 2013 12:38
Monte Carlo Simulation a basic program
import java.util.Scanner;
//Monte Carlo Simulation.
public class MonteCarloSimulation {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
double numberOfSimulation = 1000000;
int numberOfHits = 0;
for (int i = 0; i < numberOfSimulation; i = i + 1) {
double x = Math.random() * 2 - 1;
@jimmy087
jimmy087 / GreatestCommonDivisor.java
Created May 4, 2013 12:39
Greatest Common Divisor in java
import java.util.Scanner;
// Calculating Greatest Common Divisor.
public class GreatestCommomDivisor {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Please enter the first integer: ");
int number1 = input.nextInt();
System.out.print("Please enter the second integer: ");
int number2 = input.nextInt();
@jimmy087
jimmy087 / Exercise4_28.java
Created May 4, 2013 12:40
Displaying the first day of each month in java
import java.util.Scanner;
// Displaying the first day of each month.
public class Exercise4_28 {
public static void main (String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Please enter the year: ");
int year = input.nextInt();
System.out.println("Please enter the day number: ");
@jimmy087
jimmy087 / Exercise4_27.java
Created May 4, 2013 12:42
Display leap years
// Displaying leap years.
public class Exercise4_27 {
public static void main (String[] args) {
System.out.println("The following are the leap years");
System.out.println("--------------------------------");
int count = 0;
for (int i = 2000; i <= 2100; i++ ) {
if (i % 4 == 0) {
count++;
System.out.print((count % 10 != 0) ? i + " " : i +"\n" );
@jimmy087
jimmy087 / Exercise4_26.java
Created May 4, 2013 12:43
Summation of a series
// Summation of a series.
public class Exercise4_26 {
public static void main (String[] args) {
double e = 1;
double item = 1;
for (int i = 1; i <= 100000; i++) {
item = item / i;
e += i;
if (i == 10000 || i == 30000 || i == 60000 || i == 75000 || i == 100000)