Skip to main content

Posts

Showing posts from July, 2012

Algorithm Sample - Multiplication Table

package algorithmsample33; /**  *  * @author Nurhak  */ public class AlgorithmSample33 {     public static void main(String[] args) {         for (int i = 0; i <= 10; i++) {             System.out.println(i + " Multiplication Table");             for (int j = 0; j <= 10; j++) {                 System.out.println(i+" X "+j+" = "+(i * j));             }         }     } }

Algorithm Sample - Working with even and odd numbers

package algorithmsample32; import java.util.Scanner; /**  *  * @author Nurhak  */ public class AlgorithmSample32 {     public static void main(String[] args) {         int number = 0;         int sumEvenNumbers = 0;         int sumOddNumbers = 0;         String data = "";         try {             Scanner scan = new Scanner(System.in);             System.out.println("Please enter 10 numbers.");             for (int i = 1; i <= 10; i++) {                 System.out.println("Number : " + i);                 data = scan.nextLine();                 number = Integer.parseInt(data);               ...

Algorithm Sample - Factorial - Reverse Engineering

package algorithmsample31; import java.util.Scanner; /**  *  * @author Nurhak  */ public class AlgorithmSample31 {     public static void main(String[] args) {         String data = "";         int number = 0;         int factorial = 0;         try {             Scanner scan = new Scanner(System.in);             System.out.println("Enter the factorial fuction result please:");             data = scan.nextLine();             factorial = Integer.parseInt(data);             number = factorial;             for (int i = 1; i <= (factorial - 1); i++) {                 factorial = factorial / i;             }   ...

Algorithm Sample - Factorial

package algorithmsample30; import java.util.Scanner; /**  *  * @author Nurhak  */ public class AlgorithmSample30 {     public static void main(String[] args) {         int number = 0;         int factorial = 1;         String data = "";         try {             Scanner scan = new Scanner(System.in);             System.out.println("Enter the number.");             data = scan.nextLine();             number = Integer.parseInt(data);             for (int i = number; i >= 1; i += -1) {                 factorial = factorial * i;             }             System.out.println(number + " ! = " + factorial);   ...

Algorithm Sample - Finding the biggest and smallest number

package algorithmsample29; import java.util.Scanner; /**  *  * @author Nurhak  */ public class AlgorithmSample29 {     public static void main(String[] args) {         int number = 0;         int biggestNumber = 0;         int smallestNumber = 0;         String data = "";         try {             Scanner scan = new Scanner(System.in);             for (int i = 1; i <= 10; i++) {                 System.out.println("Enter the number " + i);                 data = scan.nextLine();                 number = Integer.parseInt(data);                 if (number > biggestNumber) {               ...

Algorithm Sample - Listing the first 10 even numbers which are greater than 0

package algorithmsample28; import java.util.ArrayList; import java.util.Iterator; /**  *  * @author Nurhak  */ public class AlgorithmSample28 {     public static void main(String[] args) {         int i = 0;         ArrayList list = new ArrayList();         do {             if (i % 2 == 0) {                 System.out.println(i);                 list.add(i);             }             i++;         } while (list.size() < 10);               System.out.println("List of elements: ");         Iterator it = list.iterator();         while (it.hasNext()) {             Object object = it.next();...

Algorithm Sample - Absolute value of a math function

package algorithmsample24; import java.util.Scanner; /**  *  * @author Nurhak  */ public class AlgorithmSample24 {     public static void main(String[] args) {         int number1 = 0;         int number2 = 0;         int subResult = 0;         String data = "";         try {             Scanner scan = new Scanner(System.in);             System.out.println("Please enter the first number.");             data = scan.nextLine();             number1 = Integer.parseInt(data);             System.out.println("Please enter the second number.");             data = scan.nextLine();             number2 = Integer.parseInt(data);     ...

Algorithm Sample - Multiple of the numbers that are inserted by the user

package algorithmsample22; import java.util.Scanner; /**  *  * @author Nurhak  */ public class AlgorithmSample22 {     public static void main(String[] args) {         int number = 0;         int result = 1;         String data = "";         try {             Scanner scan = new Scanner(System.in);             for (int i = 1; i <= 5; i++) {                 System.out.println("Enter the number: "+i);                 data = scan.nextLine();                 number = Integer.parseInt(data);                 result = result * number;             }             System.out.println("Multiple o...

Algorithm Sample - Reprocessing the inserted value according to an algorithm

package algorithmsample9; import java.util.Scanner; /**  *  * @author Nurhak  */ public class AlgorithmSample9 {     public static void main(String[] args) {         int number = 0;         String data = "";         try {             Scanner scan = new Scanner(System.in);             System.out.println("Please enter an integer value!");             data = scan.nextLine();             number = Integer.parseInt(data);             for (int i = 1; i <= number * 2; i++) {                 System.out.println(i + " --> " + number);             }         } catch (Exception e) {             System.err.println("An erro...

Algorithm Sample - Inch to Cm convertion

package algorithmsample7; import java.util.Scanner; /**  *  * @author Nurhak  */ public class AlgorithmSample7 {     public static void main(String[] args) {         String data = "";         double dataInch = 0;         double dataCm = 0;         try {             Scanner scan = new Scanner(System.in);             System.out.println("Please enter data (inch)");             data = scan.nextLine();             dataInch = Double.parseDouble(data);             dataCm = dataInch * 2.54;             System.out.println(dataInch + " inch equals to " + dataCm + " cm.");         } catch (Exception e) {             System.err.println("You pro...

Algorithm Sample - Area of a Triangle

package algorithmsample6; import java.util.Scanner; /**  *  * @author Nurhak  */ public class AlgorithmSample6 {     public static void main(String[] args) {         int base = 0;         int height = 0;         double area = 0;         String data = "";         try {             Scanner scan = new Scanner(System.in);             System.out.println("Please enter the base value(mm).");             data = scan.nextLine();             base = Integer.parseInt(data);             System.out.println("Please enter the height value(mm).");             data=scan.nextLine();             height = Integer.parseInt(data);       ...

Algorithm Sample - Area and Perimeter of a Rectangle

package algorithmsample5; import java.util.Scanner; /**  *  * @author Nurhak  */ public class AlgorithmSample5 {     public static void main(String[] args) {         double side1 = 0;         double side2 = 0;         double area = 0;         double perimeter = 0;         String value = "";         try {             Scanner scan = new Scanner(System.in);             System.out.println("Enter the length(mm) of first side.");             value = scan.nextLine();             side1 = Double.parseDouble(value);             System.out.println("Enter the length(mm) of second side.");             value = scan.nextLine();         ...

Algorithm Sample - Division of two numbers that are inserted by the user

package algorithmsample4; import java.util.Scanner; /**  *  * @author Nurhak  */ public class AlgorithmSample4 {     public static void main(String[] args) {         double result = 0;         double number1 = 0;         double number2 = 0;         String number = "";         try {             Scanner scan = new Scanner(System.in);             System.out.println("Please enter the first number.");             number = scan.nextLine();             number1 = Double.parseDouble(number);             System.out.println("Please enter the second number.");             number = scan.nextLine();             number2 = Double.parseDouble(number)...

Algorithm Sample - Sum of two numbers that are inserted by the user

package algorithmsample3; import java.util.Scanner; /**  *  * @author Nurhak  */ public class AlgorithmSample3 {     public static void main(String[] args) {         Scanner scan=new Scanner(System.in);         int total=0;         int number1=0;         int number2=0;               System.out.println("Please enter the first number:");         number1=scan.nextInt();               System.out.println("Please enter the second number:");         number2=scan.nextInt();               total=number1+number2;               System.out.println("Result: "+total);     } }

Algorithm Sample - Sum of the numbers from 1 to 100(1 and 100 included)

package algorithmsample2; /**  *  * @author Nurhak  */ public class AlgorithmSample2 {     public static void main(String[] args) {         int total = 0;         int x = 0;         for (x = 1; x <= 100; x++) {             System.out.println("Immediate Total: " + total);             total = total + x;         }         System.out.println("************************");         System.out.println("Total: " + total);     } }

Algorithm Sample - Are you legally an adult?

package algorithmsample1; import java.util.Scanner; /**  *  * @author Nurhak  */ public class AlgorithmSample1 {     public static void main(String[] args) {         Scanner scan = new Scanner(System.in);         int age = 0;         System.out.println("Please enter your age!");         try {             age = scan.nextInt();             if (age >= 18) {                 System.out.println("You are legally an adult!");             } else {                 System.out.println("You are not legally an adult!");             }         } catch (Exception e) {             System.out.println("Please...