This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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] + "."); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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: "); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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" ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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) |