Friday, February 2, 2018

Longest Word in PHP

In this article I would like to share with you a sample program that I wrote using PHP that will ask the user to give a sentence and then our program will check and determine which of the word in the given sentence is the longest. The code is very simple and easy to understand.

I am currently accepting programming and web development work kindly contact me in the following email address for further details. Thank you.

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

My mobile number here in the Philippines is 09173084360.

My telephone number at home here in Bacolod City, Negros Occidental is (034) 4335675.







Sample Program Output


Program Listing

long.php

<!-- long.php                                        -->
<!-- Written By Mr. Jake R. Pomperada, MAED-IT             -->
<!-- February 2, 2018 Friday   4:03 PM               -->
<!-- jakerpomperada@yahoo.com and jakerpomperada@gmail.com -->
<!-- Bacolod City, Negros Occidental Philippines           -->
<!DOCTYPE html>
<html> 
<head>
   <title>Longest Word in PHP</title>
   <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
   </head>
   <style>

   .art {

      font-family: arial;
      font-weight: bold;
      color:red;
      text-align: center;
      width:45%;
      background-color:yellow;
   }

.art2 {

      font-family: arial;
      font-weight: bold;
      font-size: 25px;
      color:blue;
      text-align: center;
      width:45%;
      background-color:lightgreen;
   }

   body {
     font-family: arial;
     font-weight: bold;
     font-size: 20px;
   }

   input[type=submit] {
    background-color: #008CBA;
    font-family: arial;
    font-weight: bold;
    font-size: 20px;
    height: 50px;
    width: 120px
     text-align: center;
    cursor: pointer;
 }

 input[type=text] {
    font-family: arial;
    font-weight: bold;
    font-size: 20px;
   
 }
</style>
   <body>
    <?php
    error_reporting(0);
    
    ?>
    <h1 class="art"> Longest Word in PHP </h1>
    <p  class="art2"> Created By Mr. Jake R. Pomperada, MAED-IT </p>
    <br><br>
   <form method="post">
   Enter a Sentence :
 <input type="text" name="val_str" size="50" autofocus=""><br><br>
 <input type="submit" name="submit" value="Check"> &nbsp;&nbsp;&nbsp;
 <input type="submit" name="clear" value="Clear">
 </form><br><br><br>
<?php

function longest_word($str_test)
{
$words  = explode(' ', $str_test);

$longestWordLength = 0;
$longestWord = '';

foreach ($words as $word) {
   if (strlen($word) > $longestWordLength) {
      $longestWordLength = strlen($word);
      $longestWord = $word;
   }
}
return strtoupper($longestWord);
}

 if(isset($_POST['submit']))  
    { 

      $str_value = $_POST['val_str'];

      $display = "The longest word is " .longest_word($str_value).".";
      echo "The sentence : " .$str_value;
      echo "<br><br>";
      echo $display;
  
 }

 if(isset($_POST['clear']))  
    { 
    $display="";
    }

?>
</body>
</html>





Longest String in JavaScript

A simple program that will ask the user to give a sentence and then our program will check which of the words in the given sentence is the longest in terms of number of characters. I wrote this program using sublime as my text editor and JavaScript as my programming language.

I am currently accepting programming and web development work kindly contact me in the following email address for further details. Thank you.

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

My mobile number here in the Philippines is 09173084360.

My telephone number at home here in Bacolod City, Negros Occidental is (034) 4335675.




Sample Program Output


Program Listing

index.htm

<!--
 Written By Mr. Jake R. Pomperada, MAED-IT
 February 2, 2018   11:54 AM   Friday
 Bacolod City, Negros Occidental Republic of the Philippines
 jakerpomperada@yahoo.com and jakerpomperada@gmail.com -->
<!doctype html>
<html>
<head>
<title> Longest String in JavaScript </title>
<style>

   .art {

      font-family: arial;
      font-weight: bold;
      color:red;
      text-align: center;
      width:45%;
      background-color:yellow;
   }

.art2 {

      font-family: arial;
      font-weight: bold;
      font-size: 25px;
      color:blue;
      text-align: center;
      width:45%;
      background-color:lightgreen;
   }

   body {
     font-family: arial;
     font-weight: bold;
     font-size: 20px;
   }

   #button_me {
    background-color: #008CBA;
    font-family: arial;
    font-weight: bold;
    font-size: 20px;
    height: 50px;
    width: 120px
     text-align: center;
    cursor: pointer;
 }

 input[type=text] {
    font-family: arial;
    font-weight: bold;
    font-size: 20px;
   
 }
</style>
      
<script>
function longestWord(string) {
    var str = string.split(" ");
    var longest = 0;
    var word = null;
    str.forEach(function(str) {
        if (longest < str.length) {
            longest = str.length;
            word = str;
        }
    });
    return word.toUpperCase();
}



function test()
{


str_string=document.getElementById("no_input").value;

 document.getElementById("msg").innerHTML = "The longest string in the sentence is "  + 
 longestWord(str_string)+".";
}

</script>

<script>
function clear_me()
{
document.getElementById("msg").innerHTML = "";
document.getElementById("no_input").value = "";
document.getElementById("no_input").focus();
}
</script>

</head>
<body>
<h1 class="art"> Longest String in JavaScript </h1>
    <p  class="art2"> Created By Mr. Jake R. Pomperada, MAED-IT </p>
<br><br>
Enter a sentence: <input id="no_input" type="text" size="50" autofocus>
<br><br>
<p id="msg"> </p> 
<button id="button_me" onclick="test()">Check</button>
&nbsp;&nbsp;&nbsp;
<button id="button_me" onclick="clear_me()">Clear</button>
</br></br>
</body>
</html>





Fibonacci Series in Java

In this article I would like to share with you a sample program that will ask the user to give a number and then our program will generate the corresponding Fibonacci numbers based on the given number by our user using Java as our programming language.

I am currently accepting programming and web development work kindly contact me in the following email address for further details. Thank you.

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

My mobile number here in the Philippines is 09173084360.

My telephone number at home here in Bacolod City, Negros Occidental is (034) 4335675.





Sample Program Output



Program Listing

fibonacci.java

import java.util.Scanner;

// fibonacci.java
// Written By Mr. Jake R. Pomperada, MAED-IT
// February 2, 2018   11:09 AM   Friday
// Bacolod City, Negros Occidental Republic of the Philippines
// jakerpomperada@yahoo.com and jakerpomperada@gmail.com

class fibonacci {
public static void main(String[] args)
      {

      int num1=0, a = 0, b = 0, c = 1;;

        Scanner s = new Scanner(System.in);

        System.out.println();
        System.out.println("=== Fibonacci Series in Java === ");
        System.out.println();

         System.out.print("Give a value of n : ");
         num1 = s.nextInt();
          System.out.println();
         System.out.print("Fibonacci Series : ");
        for(int i = 1; i <= num1; i++)
        {
            a = b;
            b = c;
            c = a + b;
            System.out.print(a+" ");
        }

System.out.println("\n");
System.out.println("\t End of Program");
         System.out.println();
}
}










Prime Number Checker in Java

A simple program that I wrote using Java as my programming language that will ask the user to give a number and then our program will check and determine if the give number is a Prime Number or Not a Prime Number.

I am currently accepting programming and web development work kindly contact me in the following email address for further details. Thank you.

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

My mobile number here in the Philippines is 09173084360.

My telephone number at home here in Bacolod City, Negros Occidental is (034) 4335675.








Sample Program Output


Program Listing

prime_number.java

import java.util.Scanner;

// prime_number.java
// Written By Mr. Jake R. Pomperada, MAED-IT
// February 2, 2018   10:44 AM   Friday
// Bacolod City, Negros Occidental Republic of the Philippines
// jakerpomperada@yahoo.com and jakerpomperada@gmail.com

class prime_number {
public static void main(String[] args)
      {

      int num1=0;
      boolean flag = false;

        Scanner s = new Scanner(System.in);

        System.out.println();
        System.out.println("=== Prime Number Checker in Java === ");
        System.out.println();

         System.out.print("Give a Number : ");
         num1 = s.nextInt();

         for(int i = 2; i <= num1/2; ++i)
         {

             if(num1 %  i == 0)
             {
                 flag = true;
                 break;
             }
         }

         if (!flag) {
System.out.println();
             System.out.println("The given number " + num1 + " is a prime number.");
}
         else {
System.out.println();
                 System.out.println("The given number " + num1 + " is not a prime number.");
}
System.out.println("\n");
System.out.println("\t End of Program");
               System.out.println();
}
}





Longest String in a Sentence in Java


In this article I would like to share with you a sample program that will ask the user to give a string or sentence and then our program will find which of the words in the given string is the longest using Java as our programming language. I am using TextPad as my text editor in writing this program.

I am currently accepting programming and web development work kindly contact me in the following email address for further details. Thank you.

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

My mobile number here in the Philippines is 09173084360.

My telephone number at home here in Bacolod City, Negros Occidental is (034) 4335675.





Sample Program Output


Program Listing

string_long.java

import java.util.*;
import java.util.Scanner;

// string_long.java
// Written By Mr. Jake R. Pomperada, MAED-IT
// February 2, 2018   9:59 AM   Friday
// Bacolod City, Negros Occidental Republic of the Philippines
// jakerpomperada@yahoo.com and jakerpomperada@gmail.com

class string_long {

  public static void main(String[] args) {

     String display;

     Scanner input=new Scanner(System.in);

       System.out.println("\n");
   System.out.print("\t Longest String in a Sentence in Java");
   System.out.println("\n");
   System.out.print("Enter a sentence : ");

      String str_sentence =input.nextLine();

     display = Arrays.stream(str_sentence.split(" ")).max(Comparator.comparingInt(String::length)).orElse(null);
    System.out.println("\n\n");
    System.out.println("The longest string is " + display.toUpperCase() + ".");
    System.out.println("\n");
    System.out.println("\t End of Program");
   System.out.println();
  }
}