Sunday, August 20, 2017

Checking if the given number is already sorted in Java

About this program it will check if the given list of numbers stored in one dimensional array is already sorted or not using Java. It will return if the given list of numbers is already sorted and false is the given number is not yet sorted.

I hope you will find my work useful and beneficial. If you have some questions about programming, about my work please send mu an email at jakerpomperada@gmail.com and jakerpomperada@yahoo.com. People here in the Philippines can contact me at  my mobile number 09173084360.

Thank you very much and Happy Programming.




Sample Program Output



Program Listing

sorted.java


package exam;

public class sorted {

public static boolean CheckSorted(int[] val_num){
   boolean checkSorted = true;
   boolean isAscending = val_num[1] > val_num[0];
   if(isAscending) {
       for (int a = 0; a < val_num.length-1; a++) {
           if(val_num[a] > val_num[a+1]) {
               checkSorted= false;
               break;
           }           
       }
   } else {
       for (int b = 0; b < val_num.length-1; b++) {
           if(val_num[b] < val_num[b+1]) {
               checkSorted = false;
               break;
           }           
       }  
   }    
   return checkSorted;
}
public static void main(String[] args) {
         
        
         int list_values1[] = new int[]{2,3,3,4,5};
        
         int list_values2[] = new int[]{10,-5,75,4,8,53};
         
         System.out.println();
         System.out.print("Checking if the given number is already sorted in Java");
         System.out.println("\n\n");
         System.out.print(CheckSorted(list_values1));
         System.out.println();
         System.out.print(CheckSorted(list_values2));
        
     
      
 }

}




Find the Largest Number Using Comparator in Java

A program that I wrote that will arrange the given series of numbers and find the largest in terms of value using comparator library in Java. 

I hope you will find my work useful and beneficial. If you have some questions about programming, about my work please send mu an email at jakerpomperada@gmail.com and jakerpomperada@yahoo.com. People here in the Philippines can contact me at  my mobile number 09173084360.

Thank you very much and Happy Programming.



Program Sample Output


Program Listing

Solution.java

package exam;


import java.util.*;

public class Solution {
    private static Comparator<Integer> sorter = new Comparator<Integer>(){
        @Override
        public int compare(Integer a, Integer b){
            String a1 = a.toString();
            String b1 = b.toString();
            if(a1.length() == b1.length()){
                return b1.compareTo(a1);
            }
            int mlen = Math.max(a1.length(), b1.length());
            while(a1.length() < mlen * 2) a1 += a1;
            while(b1.length() < mlen * 2) b1 += b1;
            return b1.compareTo(b1);
        }
    };
    public static String join_all(List<?> things){
        String output = "";
        for(Object obj:things){
            output += obj;
        }
        return output;
    }
    public static void main(String[] args){
        List<Integer> num_values1 = new ArrayList<Integer>(Arrays.asList(2,1,3));
        List<Integer> num_values2 = new ArrayList<Integer>(Arrays.asList(1,4,7));
        List<Integer> num_values3 = new ArrayList<Integer>(Arrays.asList(4,8,3));
        List<Integer> num_values4 = new ArrayList<Integer>(Arrays.asList(4,6,3));
        
        System.out.println();
        System.out.print("Find the Largest Number Using Comparator in Java");
        System.out.println("\n\n");
        Collections.sort(num_values1, sorter);
        System.out.println(join_all(num_values1));
        
        System.out.println();
        Collections.sort(num_values2, sorter);
        System.out.println(join_all(num_values2));
        
        System.out.println();
        Collections.sort(num_values3, sorter);
        System.out.println(join_all(num_values3));
        
        System.out.println();
        Collections.sort(num_values4, sorter);
        System.out.println(join_all(num_values4));
        
    }
}

Saturday, August 19, 2017

Positive and Negative Number Checker in Visual Foxpro

A very simple program that I wrote using Visual Foxpro 5 to ask the user to give a number and then our program will check if the given number is a Positive or Negative number. The code is very simple and short.  I hope you will find my work useful. Thank you.

I hope you will find my work useful and beneficial. If you have some questions about programming, about my work please send mu an email at jakerpomperada@gmail.com and jakerpomperada@yahoo.com. People here in the Philippines can contact me at  my mobile number 09173084360.


Thank you very much and Happy Programming.




Sample Program Output


Program Listing


** Positive and Negative Number Checker in Visual Foxpro
** Written By: Mr. Jake R. Pomperada, MAED-IT
** August 19, 2017  Saturday   6:35 PM

SET TALK OFF
SET ECHO OFF
CLEAR
STORE 0 TO a


@ 1,20 Say "Positive and Negative Number Checker in Visual Foxpro"
@ 3,25 Say "Written By Mr. Jake R. Pomperada, MAED-IT"
@ 6,1 Say "Enter A Number    : " Get A Pict "9999"

READ

if (A >=0) then
   @ 10,1 Say "It given number is POSITIVE."
else 
   @ 10,1 Say "It given number is NEGATIVE."
endif




Odd and Even Number Checker Using Scala

I wrote this simple program to ask the user to give a number and then our program will determine if the given number by our user is an ODD or EVEN number. I am using Scala as my programming language in this sample program. I am still a beginner in Scala programming, learning Scala is much easier it resembles Java programming language in many language syntax and features. I hope you will find my work useful. Thank you.

I hope you will find my work useful and beneficial. If you have some questions about programming, about my work please send mu an email at jakerpomperada@gmail.com and jakerpomperada@yahoo.com. People here in the Philippines can contact me at  my mobile number 09173084360.


Thank you very much and Happy Programming.







Sample Program Output


Program Listing

OddEven.scala

// Written By: Mr. Jake R. Pomperada, MAED-IT
// Tool : Scala
// IDE  : IntelliJ IDEA Community Version 2017.2
// Date : August 19, 2017   Saturday
// Country : Philippines


import java.util.Scanner;

object OddEven {

  def main(args: Array[String]) {

    var input = new Scanner(System.in);

    def isEven(number: Int) = number % 2 == 0
    def isOdd(number: Int) = !isEven(number)

    print("\n\n");
    print("Odd and Even Number Checker Using Scala");
    print("\n\n");
    print("Written By: Mr. Jake R. Pomperada, MAED-IT");
    print("\n\n");
    print("Enter a Number : ");

    var num_value = input.nextInt();

    if (isEven(num_value)) {
      print("\n\n");
      print("The given number " + num_value + " is an EVEN number.");
      print("\n\n");
    }
    else if  (isOdd(num_value))  {
      print("\n\n");
      print("The given number " + num_value + " is an ODD number.");
      print("\n\n");
    }

    print("\t END OF PROGRAM");
    print("\n\n");
  }
}




Area of the Circle Solve Using Scala

In this article I wrote a program using Scala to ask the user to give the radius of the circle and then our program will compute the area of the circle. I wrote the code using Scala as my programming language and IntelliJ IDEA text editor community edition which is FREE to download and use over the Internet. I hope you will find my work useful. Thank you.

I hope you will find my work useful and beneficial. If you have some questions about programming, about my work please send mu an email at jakerpomperada@gmail.comand jakerpomperada@yahoo.com. People here in the Philippines can contact me at  my mobile number 09173084360.

Thank you very much and Happy Programming.



My text editor use in making this program





Sample Program Output



Program Listing

// Written By: Mr. Jake R. Pomperada, MAED-IT
// Tool : Scala
// IDE  : IntelliJ IDEA Community Version 2017.2
// Date : August 19, 2017   Saturday
// Country : Philippines


import java.util.Scanner;

object AreaCircle2 {

  def main(args: Array[String]) {

    var input = new Scanner(System.in);

    print("\n\n");
    print("Area of the Circle Solve Using Scala");
    print("\n\n");
    print("Written By: Mr. Jake R. Pomperada, MAED-IT");
    print("\n\n");
    print("Enter the Radius of the Circle : ");

    var radius = input.nextDouble();


    var area = 3.14 * radius * radius

    print("\n\n");
    print("The Area of Circle is " + f"$area%2.2f" )
    print("\n\n");
    print("\t END OF PROGRAM");
    print("\n\n");
  }
}




Friday, August 18, 2017

Product of Two Number in Scala

A very simple program that will ask the user to give two numbers and then our program will find the product of the two numbers given by our user using Scala as our programming language. The code is some what similar in Java using Java Scanner to get inputs from our user. I hope you will learn something new using Scala. Thank you.

I hope you will find my work useful and beneficial. If you have some questions about programming, about my work please send mu an email at jakerpomperada@gmail.com and jakerpomperada@yahoo.com. People here in the Philippines can contact me at  my mobile number 09173084360.

Thank you very much and Happy Programming.






Sample Program Output


Program Listing


Product.scala



import java.util.Scanner;

object Product {
def main(args: Array[String]) {
var scanner = new Scanner(System.in);
println("\n\n");
print("Product of Two Numbers in Scala");
println("\n\n");
print("Enter the first number : ");
var a = scanner.nextInt();
print("Enter the second number : ");
var b = scanner.nextInt();
println("\n\n");
println("The product of " + a + " and " + b + " is " +(a*b) +".");
println("\n\n");
println("END OF PROGRAM");
}





Addition of Two Numbers in Scala

A very simple program that will ask the user to give two numbers and then our program will find the sum of the two numbers given by our user using Scala as our programming language. The code is some what similar in Java using Java Scanner to get inputs from our user. I hope you will learn something new using Scala. Thank you.

I hope you will find my work useful and beneficial. If you have some questions about programming, about my work please send mu an email at jakerpomperada@gmail.comand jakerpomperada@yahoo.com. People here in the Philippines can contact me at  my mobile number 09173084360.

Thank you very much and Happy Programming.




Sample Program Output


Program Listing

import java.util.Scanner;

object Add {

def main(args: Array[String]) {

var scanner = new Scanner(System.in);

println("\n\n");
print("Addition of Two Numbers in Scala");
println("\n\n");

print("Enter the first number : ");


var a = scanner.nextInt();

print("Enter the second number : ");

var b = scanner.nextInt();
println("\n\n");
println("The sum of " + a + " and " + b + " is " +(a+b) +".");
println("\n\n");
println("END OF PROGRAM");

}
}


Hello World in Scala

This will be my first time to write a code using Scala my very first program is a simple hello world. Scala is much similar with Java it is also object oriented programming language and functional programming language. I am still exploring and experimenting on this language which I found very interested to learn and use. I hope you will my simple work useful. Thank you.

I hope you will find my work useful and beneficial. If you have some questions about programming, about my work please send mu an email at jakerpomperada@gmail.comand jakerpomperada@yahoo.com. People here in the Philippines can contact me at  my mobile number 09173084360.

Thank you very much and Happy Programming.




Sample Program Output


Program Lisitng

Hello.Scala

object Hello extends App {
    println("Hello, world !!! By Jake R. Pomperada")
}


Quick Sort in Java

A very simple program that I wrote using Java to demonstrate quick sort algorithm. I hope you will find my work useful.  Thank you for all the support in my website.

I hope you will find my work useful and beneficial. If you have some questions about programming, about my work please send mu an email at jakerpomperada@gmail.comand jakerpomperada@yahoo.com. People here in the Philippines can contact me at  my mobile number 09173084360.

Thank you very much and Happy Programming.






Sample Program Output



Program Listing

QuickSort.java

package testing;

import java.util.Arrays;
import java.util.Scanner;

public class QuickSort {
public static void main(String[] args) {
 
Scanner input=new Scanner(System.in);

int x[]  =new int[5];
System.out.println();
System.out.println(" QUICK SORT IN JAVA ");
System.out.println();
for(int i=0;i<5;i++){
System.out.print("Give value in item no. " + (i+1) + " : ");
            x[i]=input.nextInt();
   }

System.out.println();
System.out.println("Original Values");
System.out.println();
System.out.println(Arrays.toString(x));

int low = 0;
int high = x.length - 1;

quickSort(x, low, high);
System.out.println();
System.out.println("Sorted Values");
System.out.println();
System.out.println(Arrays.toString(x));
input.close();
}

public static void quickSort(int[] arr, int low, int high) {
if (arr == null || arr.length == 0)
return;

if (low >= high)
return;
 
int middle = low + (high - low) / 2;
int pivot = arr[middle];

int i = low, j = high;
while (i <= j) {
while (arr[i] < pivot) {
i++;
}

while (arr[j] > pivot) {
j--;
}

if (i <= j) {
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
i++;
j--;
}
}
 
if (low < j)
quickSort(arr, low, j);

if (high > i)
quickSort(arr, i, high);
}

}