Thursday, August 31, 2017

Reverse A String in Java

In this article I would like to share with you a simple program that will ask the user to give any string and then our program will reverse the given string by our user using Java as our programming language. I am using Eclipse as my IDE in writing this program. Thank you.

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.






Sample Program Output


Program Listing


Reverse_String_Demo.java

/**
 * 
 */
package Reverse_String;

import java.util.*;

/**
 * @author Jacob
 *
 */
public class Reverse_String_Demo {

 public static String  Reverse_Me(String str) {
    
 String Rev_Str;
 
   Rev_Str = "";
   
       for(int a= str.length()-1; a>=0; a--) {
           Rev_Str = Rev_Str + str.charAt(a);
       }
       
       System.out.print("\n\n");
       System.out.println("The Reversed String is " + Rev_Str + ".");
       System.out.println();
       System.out.println("End of Program");
       System.out.println();
       return str; 
 }
/**
* @param args
*/
public static void main(String[] args) {
Scanner user_input =new Scanner(System.in);
String str_me;

        System.out.println();
        System.out.println("Reverse A String in Java");
        System.out.println();
        System.out.println("Written By Mr. Jake R. Pomperada, MAED-IT");
        System.out.println();
System.out.print("Enter any string: ");
        str_me = user_input.nextLine();
        
        Reverse_Me(str_me);
        
        user_input.close();

}

}




Saturday, August 26, 2017

Product of Two in Java Using Getters and Setters

A very simple program that I wrote in Java to demonstrate how to use getters and setters concepts in object oriented programming. The code will ask the user to give two numbers and then our program will compute that product of the two numbers given by our users. 

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.



Sample Program Output


Program Listing


Product_Two.java


// Written By: Mr. Jake R. Pomperada, MAED-IT
// Date : August 26, 2017  Sunday 7:36 AM
// Language: Java
// Place of Origin:  Mandaluyong City, Metro Manila Philippines.


package product_number;

import java.util.Scanner;

public class Product_Two {

int val_a;
int val_b;
public int getVal_a() {
return val_a;
}


public void setVal_a(int val_a) {
this.val_a = val_a;
}


public int getVal_b() {
return val_b;
}


public void setVal_b(int val_b) {
this.val_b = val_b;
}


public int solveProduct()
{
return(val_a * val_b);
}
public static void main(String[] args) {
  
Scanner input = new Scanner(System.in);
  
  Product_Two num = new Product_Two(); 
    
       System.out.println();
       System.out.println("Product of Two in Java Using Getters and Setters");
       System.out.println();
       System.out.print("Enter first value : ");
       num.val_a = input.nextInt();
       System.out.print("Enter second value : ");
       num.val_b = input.nextInt();

        num.setVal_a(num.val_a);
        num.setVal_b(num.val_b);
        num.getVal_a();
        num.getVal_b();
        
        num.solveProduct();
     
        System.out.println();
        System.out.print("The product of " +num.val_a + " and " + num.val_b + " is " + num.solveProduct() + ".");
        System.out.println("\n");
        System.out.print("\t END OF PROGRAM");
        input.close();
}

}



Friday, August 25, 2017

Finding the Smallest Value Using Scala

Hi Guys in this article I would like to share with you how to use one dimensional array in Scala and how we can able to determine which of the values in our array is the smallest in terms of numerical value. The code is very short and easy to understand. I am using IntelliJ IDEA community edition 2017.2 edition as my text editor in writing this code. I hope you will find my work useful. Thank you very much 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.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
Smallest.scala
object Smallest { def main(args: Array[String]) { var listValues = Array(100,45,1240,12,50,531,62,376); print("\n\n"); print("Finding the Smallest Value Using Scala"); print("\n\n"); print("Written By: Mr. Jake R. Pomperada, MAED-IT"); print("\n\n"); for ( a <- listValues ) { print(" " + a + " "); } var smallest = listValues(0); for ( b <- 1 to (listValues.length - 1) ) { if (listValues(b) < smallest) smallest = listValues(b); } print("\n\n"); println("The Smallest Number in the list is " + smallest + "."); print("\n\n"); print("\t END OF PROGRAM"); print("\n\n"); }

Finding the Biggest Value Using Scala

Hi Guys in this article I would like to share with you how to use one dimensional array in Scala and how we can able to determine which of the values in our array is the highest in terms of numerical value. The code is very short and easy to understand. I am using IntelliJ IDEA community edition 2017.2 edition as my text editor in writing this code. I hope you will find my work useful. Thank you very much 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.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


Biggest.scala


object Biggest {

  def main(args: Array[String]) {

    var listValues = Array(100,45,1240,12,50,531,62,376);

    print("\n\n");
    print("Finding the Biggest Value Using Scala");
    print("\n\n");
    print("Written By: Mr. Jake R. Pomperada, MAED-IT");
    print("\n\n");

    for ( a <- listValues ) {
      print(" " + a + " ");
    }

    var biggest = listValues(0);

    for ( b <- 1 to (listValues.length - 1) ) {
      if (listValues(b) > biggest)
        biggest = listValues(b);
    }
    print("\n\n");
    println("The Biggest Number is " + biggest + ".");
    print("\n\n");
    print("\t END OF PROGRAM");
    print("\n\n");
  }
}

Sunday, August 20, 2017

For Loop in Scala

A very simple program to demonstrate how to use for loop statement in Scala programming language. The code is very basic and easy to understand.

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

ForLoop.scala

object ForLoop {

  def main(args: Array[String]) {
    var x = 0;


    print("\n\n");
    print("For Loop in Scala");
    print("\n\n");

    for (x <- 1 to 15) {
      println("Value of x is " + x);
    }
  }
}


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");
  }
}