Friday 31 December 2021

How do you select data from a table in SQL?

Create Table

How do you select data a table in SQL?

The SELECT statement is used to select data from a database. The data returned is stored in a result table, called the result-set.

The most commonly used SQL command is SELECT statement. It is used to query the database and retrieve selected data that follow the conditions we want.

In simple words, we can say that the select statement used to query or retrieve data from a table in the database.

Select table syntax:

SELECT expressions FROM tables WHERE conditions;

select table output:

SQL SELECT COUNT

The SQL COUNT() is a function that returns the number of records of the table in the output. This function is used with the SQL SELECT statement

Let's take a simple example: If you have a record of the voters in the selected area and want to count the number of voters, then it is very difficult to do it manually, but you can do it easily by using SQL SELECT COUNT query.

Syntax of Select Count Function in SQL

SELECT COUNT(column_name) FROM table_name;

In the syntax, we have to specify the column's name after the COUNT keyword and the name of the table on which the Count function is to be executed.

select Count table output:

SQL SELECT TOP

The SELECT TOP statement in SQL shows the limited number of records or rows from the database table. The TOP clause in the statement specifies how many rows are returned.

It shows the top N number of rows from the tables in the output. This clause is used when there are thousands of records stored in the database tables.

Syntax of TOP Clause in SQL

SELECT TOP number | percent column_Name1, column_Name2, ....., column_NameN FROM table_name WHERE [Condition] ;

select Top table output:

SQL SELECT FIRST

The SQL first() function is used to return the first value of the selected column. Let's see the syntax of sql select first() function:

Select First table syntax:

SELECT FIRST(column_name) FROM table_name;

select First table output:

SQL SELECT LAST

The last() function is used to return the last value of the specified column. Syntax for SQL SELECT LAST() FUNCTION:

You should note that the last() function is only supported in MS Access. But there are ways to get the last record in MySql, SQL Server, Oracle etc. databases.

Select LAST table syntax:

SELECT LAST (column_name) FROM table_name;

select table output:

SQL SELECT RANDOM

The SQL SELECT RANDOM() function returns the random row. It can be used in online exam to display the random questions.

There are a lot of ways to select a random record or row from a database table. Each database server needs different SQL syntax.

Select RANDOM table syntax:

SELECT column FROM table ORDER BY RAND ( ) LIMIT 1

select RANDOM table output:

SQL Tutorial

Thursday 30 December 2021

ALTER TABLE add multiple columns in sql

ALTER Table

How do you ALTER TABLE in SQL ?

The SQL ALTER TABLE command is used to add, delete or modify columns in an existing table. You should also use the ALTER TABLE command to add and drop various constraints on an existing table

The ALTER TABLE statement is used to add, delete, or modify columns in an existing table. The ALTER TABLE statement is also used to add and drop various constraints on an existing table.


In many situations, you may require to add the columns in the existing table. Instead of creating a whole table or database again you can easily add single and multiple columns using the ADD keyword.



1 . ADD Column

Syntax of ALTER TABLE ADD Column statement in SQL


ALTER TABLE table_name ADD column_name column-definition;

The above syntax only allows you to add a single column to the existing table. If you want to add more than one column to the table in a single SQL statement, then use the following syntax:

ADD Column in table output:

2 MODIFY Column

The MODIFY keyword is used for changing the column definition of the existing table.

Syntax of ALTER TABLE MODIFY Column


ALTER TABLE table_name MODIFY column_name column-definition;

This syntax only allows you to modify a single column of the existing table. If you want to modify more than one column of the table in a single SQL statement, then use the following syntax:

MODIFY Column in table output:

3 DROP Column

In many situations, you may require to delete the columns from the existing table. Instead of deleting the whole table or database you can use DROP keyword for deleting the columns.

Syntax of ALTER TABLE DROP Column statement in SQL


ALTER TABLE table_name DROP Column column_name ;

DROP Column in table output:

4 RENAME Column

The RENAME keyword is used for changing the name of columns or fields of the existing table.

Syntax of ALTER TABLE RENAME Column


ALTER TABLE table_name RENAME COLUMN old_name to new_name;

RENAME Column in table output:

SQL Tutorial

Tuesday 28 December 2021

How do you Rename a table in SQL?

Create Table

How do you Rename a table in SQL?

In some situations, database administrators and users want to change the name of the table in the SQL database because they want to give a more relevant name to the table.

Any database user can easily change the name by using the RENAME TABLE and ALTER TABLE statement in Structured Query Language.

Here, we have taken the following two different SQL examples, which will help you how to change the name of the SQL table in the database using RENAME statement:

Rename table syntax:

ALTER TABLE old_table_name RENAME TO new_table_name;

Rename table output:

  • First, specify the name of the table to be renaming.

  • Second, specify the name of the database in which the table was created and the name of the schema to which the table belongs. The database name is optional.

  • Third, use IF EXISTS clause to remove the table only if it exists. The IF EXISTS clause has been supported since SQL Server 2016 13.x. If you remove a table that does not exist, you will get an error. The IF EXISTS clause conditionally removes the table if it already exists.

SQL Tutorial

Monday 27 December 2021

How do you drop a table in SQL?

Create Table

How do you drop a table in SQL?

The SQL DROP TABLE statement is used to remove a table definition and all the data, indexes, triggers, constraints and permission specifications for that table

The SQL Server (Transact-SQL) DROP TABLE statement allows you to remove or delete a table from the SQL Server database.

This is very important to know that once a table is deleted all the information available in the table is lost forever, so we have to be very careful when using this command.

DROP table syntax:

DROP table tablename ;

DROP table output:

DROP

  • First, specify the name of the table to be removed.

  • Second, specify the name of the database in which the table was created and the name of the schema to which the table belongs. The database name is optional. If you skip it, the DROP TABLE statement will drop the table in the currently connected database.

  • Third, use IF EXISTS clause to remove the table only if it exists. The IF EXISTS clause has been supported since SQL Server 2016 13.x. If you remove a table that does not exist, you will get an error. The IF EXISTS clause conditionally removes the table if it already exists.

Note:

Be careful before dropping a table. Deleting a table will result in loss of complete information stored in the table!


DROP TABLE and CREATE TABLE should not be executed on the same table in the same batch. Otherwise an unexpected error may occur.



It is sometimes easier to drop a table and recreate it, instead of using the ALTER TABLE statement to change the table's definition

Sunday 26 December 2021

Create table in SQL WITH PRIMARY key

Create Table

What is Table in ,MySql

SQL CREATE TABLE statement is used to create table in a database. If you want to create a table, you should name the table and define its column and each column's data type.

Tables are used to store data in the database. Tables are uniquely named within a database and schema. Each table contains one or more columns. And each column has an associated data type that defines the kind of data it can store e.g., numbers, strings, or temporal data.

create table syntax:

Create table tablename ( column1 datatype, column2 datatype, column3 datatype, column4 datatype,)

The data type of the columns may vary from one database to another. For example, NUMBER is supported in Oracle database for integer value whereas INT is supported in MySQL.

Let us take an example to create a STUDENTS table with ID as primary key and NOT NULL are the constraint showing that these fields cannot be NULL while creating records in the table.

create table output:

create

Now you have the STUDENTS table available in your database and you can use to store required information related to students

The column parameters specify the names of the columns of the table. The datatype parameter specifies the type of data the column can hold (e.g. varchar, integer, date, etc.).

Note:

In addition to the standard reserved keywords, the following keywords cannot be used as column identifiers because they are reserved for ANSI-standard context functions CURRENT_DATE CURRENT_ROLE, CURRENT_TIME, CURRENT_TIMESTAMP, CURRENT_USER


DEFAULT and AUTOINCREMENT are mutually exclusive; only one can be specified for a column.

Sunday 19 December 2021

udemy_sun

Udemy

Couser 1


[FREE]

What you’ll learn :
Requirements :
This course includes  :
  • 5.5 hours on-demand video
  • 28 downloadable resources
  • Full lifetime access
  • Access on mobile and TV
  • Certificate of completion
How to Subscribe :
  • 1.  Sign Up on Udemy.com
  • 2.  Subscribe Here  Click Here

Saturday 11 December 2021

udemy1

Udemy

Couser 1


Practical MongoDB + PHP: Absolute Beginners Guide [FREE]

What you’ll learn :
  • Feel flexible to work with MongoDB, Perform Basic and Advanced queries in MongoDB.
  • Build real-life application using MongoDB and PHP.
  • Understand how MongoDB stores data.
Requirements :
This course includes  :
  • 1.5 hours on-demand video
  • 1 downloadable resources
  • Full lifetime access
  • Access on mobile and TV
  • Certificate of completion
How to Subscribe :
  • 1.  Sign Up on Udemy.com
  • 2.  Subscribe Here  Click Here

Couser 1


Web Development Masterclass – Complete Certificate Course[FREE]

What you’ll learn :
  • Create and Configure a Testing server on a Local Windows or MAC System
  • Install LAMP Stack (Linux, Apache, MySQL, PHP, PhpMyAdmin) on a local and remote server
  • Create mobile responsive web applications using Bootstrap
  • Use Google Apps for Work to setup a customized business email address
Requirements :
  • Text Editor such as Text Wrangler (MAC) or Notepad++ (Windows
  • Students will require an internet connection and PC or MAC Computer System. Please note that all required downloads are free.
This course includes  :
  • 20.5 hours on-demand video
  • 2 downloadable resources
  • Full lifetime access
  • Access on mobile and TV
  • Certificate of completion
How to Subscribe :
  • 1.  Sign Up on Udemy.com
  • 2.  Subscribe Here  Click Here

Couser 2


The Python Programming A-Z Definitive Diploma in 2021[FREE]

What you’ll learn :
  • Basic and Advanced Python concepts to become a Rockstar Python Developer
  • Python tools, keywords, best Practicing, high level descriptions
  • All bout Variables, Data Types, Literals, Techniques, Importing and Formatting.
  • Using Databases with Python
Requirements :
This course includes  :
  • 5.5 hours on-demand video
  • 21 downloadable resources
  • Full lifetime access
  • Access on mobile and TV
  • Certificate of completion
How to Subscribe :
  • 1.  Sign Up on Udemy.com
  • 2.  Subscribe Here  Click Here

Couser 3


Introduction To Python Programming [FREE]

What you’ll learn :
  • Program Python
  • Know the basics of Python
  • Write their own scripts, and functinos
Requirements :
  • No programming experience is required!
  • Access to a Computer or Laptop
This course includes  :
  • 1.34 hours on-demand video
  • 18 downloadable resources
  • Full lifetime access
  • Access on mobile and TV
  • Certificate of completion
How to Subscribe :
  • 1.  Sign Up on Udemy.com
  • 2.  Subscribe Here  Click Here

Friday 10 December 2021

Write a program to implement stack using stack class in data structure

Stack

Write a program to implement stack using stack class in data structure

Introduction Stack

Stack is a linear data structure which follows a particular order in which the operations are performed. The order may be LIFO(Last In First Out) or FILO(First In Last Out).

There are many real-life examples of a stack. Consider an example of plates stacked over one another in the canteen. The plate which is at the top is the first one to be removed, i.e. the plate which has been placed at the bottommost position remains in the stack for the longest period of time. So, it can be simply seen to follow LIFO(Last In First Out)/FILO(First In Last Out) order.

stack

stack operations Algorithm by using Array

1. PUSH:-When we insert an element in a stack then the operation is known as a push. If the stack is full then the overflow condition occurs.

2. POP:- When we delete an element from the stack, the operation is known as a pop. If the stack is empty means that no element exists in the stack, this state is known as an underflow state.

3.isEmpty:- It determines whether the stack is empty or not.

4. peek:- It returns the element at the given position.

stack implementation by using Array

  import java.util.Stack;;

  class stackclass {

  public static void main(String[] args)   {

     Stack< String > animals = new Stack < >();

     animals.push("shubhi");

     animals.push("narayan");

      animals.push("mane");

     System.out.println(animals);

     animals.pop();

     System.out.println(animals);

       }

    }

output

[shubhi, narayan, mane]
[shubhi, narayan]

stack implementations ways

Next Topic

udemy

Udemy

Couser 1


Python Scrapy : For Beginners [FREE]

What you’ll learn :
  • Introduction to Scrapy
  • Scrapy at a glance
  • Working of quotestoscrapecom site
  • Usage Area of Scrapy
Requirements :
  • Some Basic Knowledge of HTML
This course includes  :
  • 1 hours 58 minute on-demand video
  • 11 downloadable resources
  • Full lifetime access
  • Access on mobile and TV
  • Certificate of completion
How to Subscribe :
  • 1.  Sign Up on Udemy.com
  • 2.  Subscribe Here  Click Here

Couser 1


API Crash Course: What is an API, how to create it & test it [FREE] [FREE]

What you’ll learn :
  • What is an API .
  • Difference between API & Webservice.
  • HTTP Basics.
  • How to create a mock API
Requirements :
  • PC or Laptop.
  • Internet Connection.
This course includes  :
  • 3.5 hours on-demand video
  • 28 downloadable resources
  • Full lifetime access
  • Access on mobile and TV
  • Certificate of completion
How to Subscribe :
  • 1.  Sign Up on Udemy.com
  • 2.  Subscribe Here  Click Here

Couser 1


The Complete Intro to Machine Learning [Free Course]

What you’ll learn :
  • Learn the basics of data visualization and pre-processing (Python basics, Numpy, Pandas, Seaborn)
  • Gain theoretical and practical experience with fundamental machine learning algorithms (Linear and Logistic Regression, K-NN, Decision Trees, Neural Networks)
  • Understand advanced ML topics (encoding, ensemble learning techniques, etc.)
  • Submit to your first Kaggle Machine Learning Competition
Requirements :
  • No programming or theoretical math prerequisites. We’ll teach you everything you need to know.
This course includes  :
  • 5 hours on-demand video
  • 8 downloadable resources
  • Full lifetime access
  • Access on mobile and TV
  • Certificate of completion
How to Subscribe :
  • 1.  Sign Up on Udemy.com
  • 2.  Subscribe Here  Click Here

Write a program to implement stack using array in data structure

Stack

Write a program to implement stack using array in data structure

Introduction Stack

Stack is a linear data structure which follows a particular order in which the operations are performed. The order may be LIFO(Last In First Out) or FILO(First In Last Out).

There are many real-life examples of a stack. Consider an example of plates stacked over one another in the canteen. The plate which is at the top is the first one to be removed, i.e. the plate which has been placed at the bottommost position remains in the stack for the longest period of time. So, it can be simply seen to follow LIFO(Last In First Out)/FILO(First In Last Out) order.

stack

stack operations Algorithm by using Array

1. PUSH:-When we insert an element in a stack then the operation is known as a push. If the stack is full then the overflow condition occurs.

   top=top+1;

   arr[top]=i

2. POP:- When we delete an element from the stack, the operation is known as a pop. If the stack is empty means that no element exists in the stack, this state is known as an underflow state.

   top=top-1;

3.isEmpty:- It determines whether the stack is empty or not.

top=-1
 

4. peek:- It returns the element at the given position.

stack implementation by using Array

  import java.util.Scanner;

  class stack  {

      int n=10;

      int top=-1;

      int a[] =new int[10];

      Scanner sc = new Scanner(System.in);

    void push()

      {

        if(top== (n-1))

          {

            System.out.println("stcak is overflow");

            }

      else

        {

          System.out.println("enter the number");

          int i =sc.nextInt();

          top=top+1;

          a[top]=i;

          System.out.println("item inseret"

      }

    }

    void pop()

    {

      if(top== -1)

      {

          System.out.println("stcak is underflow");

      }

    else

      {

          top=top-1;

          System.out.println("item delete"

      }

    }

    void display()

       {

        for(int j=top; j>=0 ;j--)

        {

          System.out.println(a[j]

          }

        }

    }

  class stack_array {

  public static void main(String[] args)   {

    {

      Scanner sc = new Scanner(System.in);

      stack s = new stack();

      while(true)

      {

          System.out.println("\n \n \n \n")

          System.out.println("\t \t 1 push")

          System.out.println("\t \t 2 pop")

          System.out.println("\t \t 3 display ")

          System.out.println("\t \t 4 exit")

        System.out.println("enter the choic"

          int ch =sc.nextInt();

    switch(ch)

      {

        case 1: s.push(); break;

       case 2: s.pop(); break;

        case 3: s.display(); break;

        case 4: System.exit(1); break;

        default: System.out.println("try again"

       }

    }

    }

   }

stack implementations ways

Next Topic

Wednesday 8 December 2021

Java Program to separate the Individual Characters from a String

separate

Java Program to separate the Individual Characters from a String

In this program, we need to separate each character from the string.
CHARACTERS

In computer science, collection of characters including spaces is called as string. To separate an individual character from the string, individual characters are accessed through its index.

string 1

CHARACTERS

string 2

C H A R A C T E R S

Program

class IndividualCharacters {

  public static void main(String[] args)   {

    //declare string

   String str1="characters ";

  System.out.println( "Individual characters from given string: " );

  for (int i = 0; i < string.length(); i++){

    System.out.print(string.charAt(i) + " ");

      }

   }

  }

output

Individual characters from given string:
c h a r a c t e r s

Theory

Monday 6 December 2021

Java Program to find the largest and smallest word in a string.

largest_word

Java Program to find the largest and smallest word in a string.

In this program, we need to find the smallest and the largest word present in the string:
"Hardships often prepare ordinary people for an extraordinary destiny"

Consider above example in which 'an' is the smallest word and 'extraordinary' is the largest word. One of the approach to find smallest and largest word is to split string into words then, compare length of each word with variables small and large. If length of a word is less than length of small then, store that word in small. If length of a word is greater than length of large then, store that word in large.

string 1

Hardships often prepare ordinary people for an extraordinary destiny

Program

class SmallestLargestWord {

  public static void main(String[] args)   {

    //declare string

   String str1="Hardships often prepare ordinary people for an extraordinary destiny";;

      String word = "", small = "", large="";

    String[] words = new String[100];

    int length = 0;

      //Add extra space after string to get the last word in the given string

      string = string + " ";

    for (int i = 0; i < string.length(); i++){

        if(string.charAt(i) != ' '){

          word = word + string.charAt(i);

      }

  else

    {

      words[length] = word;

      length++;

      word = "";

      }

  }

      //Initialize small and large with first word in the string

    small = large = words[0];

    for (int k = 0; k < length; k++){

      if (small.length() > words[k].length())

        small = words[k];

      if (large.length() < words[k].length())

          large = words[k];

    }

    System.out.println("Smallest word: " + small);

    System.out.println("Largest word: " + large);

      }

    }

   }

output

Smallest word:    an
Largest word:    extraordinary

Theory

Saturday 4 December 2021

Q13_program to find the duplicate characters in a string

remove_white_space

program to find the duplicate characters in a string

In this program, we need to find the duplicate characters in the string. Great responsibility To find the duplicate character from the string, we count the occurrence of each character in the string. If count is greater than 1, it implies that a character has a duplicate entry in the string. In above example, the characters highlighted in green are duplicate characters.

string 1

"Great responsibility"

Program

class duplicate_char {

  public static void main(String[] args)   {

    //declare string

   String str1="Great responsibility";

int count;

char str1[]=str.toCharArray();

System.out.println( "Duplicate charcters in given string" );

for (int i=0;i< str1.length;i++)

{

count=1;

forint j=i+1; j< str1.length;j++)

{

if (str1[i]==str1[j] && str1[i]!=' ')

System.out.println(str1[j]);

break;

}

}

    }

   }

output

Duplicate characters in a given string: r e t s i

Theory

Q14_Java Program to find the frequency of characters

remove_white_space

Java Program to find the frequency of characters

In this program, we need to find the frequency of each character present in the word. Picture perfect

To accomplish this task, we will maintain an array called freq with same size of the length of the string. Freq will be used to maintain the count of each character present in the string. Now, iterate through the string to compare each character with rest of the string. Increment the count of corresponding element in freq. Finally, iterate through freq to display the frequencies of characters.

string 1

"picture perfect"

Program

class FrequencyCharacter {

  public static void main(String[] args)   {

    //declare string

   String str1="Remove white spaces";

  int [] freq = new int [str.length()];

  int i, j;

  char string[] = str.toCharArray();

for (i = 0; i < str.length(); i++) {

   freq[i] = 1;

  for (j = i+1; j < str.length(); j++) {

     if (string[i] == string[j]) {

     freq[i]++;

     string[j] = '0';

   }

  }

 }

  System.out.println("Characters and their corresponding frequencies");

  for (i = 0; i < freq.length; i++)) {

   if (string[i] != ' ' && string[i] != '0')

    System.out.println(string[i] + "-" + freq[i]);

      }

    }

   }

output

Characters and their corresponding frequencies   p-2   i-1  c-2  t-2  u-1   r-2  e-3  f-1  

Theory

Friday 3 December 2021

Q12_Program to find maximum and minimum occurring character in a string

max_min

Program to find maximum and minimum occurring character in a string

In this program, we need to count each character present in the string and find out the maximum and minimum occurring character. Grass is greener on the other side In above example, character 'a' is occurred only once in the string. So, it is minimum occurring character and is highlighted by red. Character e has occurred maximum number of times in the entire string i.e. 6 times. Hence, it is the maximum occurring character and is highlighted by green.

string 1

Remove white spaces

string 2

Removewhitespaces

Program

class max_min {

  public static void main(String[] args)   {

    //declare string

   String str1="grass is greener on the other side";

   int [] freq = new int [str.length()];

   char minChar = str.charAt(0), maxChar = str.charAt(0);

   int i, j, min, max;

   char string[] = str.toCharArray();

   for (i = 0; i < string.length; i++) {

         freq[i] = 1;

      for (j = i+1; j < string.length; j++) {

            if (string[i] == string[j] && string[i] != ' ' && string[i] != '0') {

               freq[i]++;

               string[j] = '0';

            }

      }

   }

   min = max = freq[0];

   for ( i = 0; i < freq.length; i++) {

      if (min > freq[i] && freq[i] != '0') {

         min = freq[i];

         minChar = string[i];

      }

       if (max < freq[i]) {

         max = freq[i];

         maxChar = string[i];

      }

   }

   System.out.println( "Minimum occurring character: " + minChar);

   System.out.println( "Maximum occurring character: " + maxChar);

    }

   }

output

Minimum occurring character: a Maximum occurring character: e

Theory

Q11_Program to determine whether one string is a rotation of another

Rotate

Program to determine whether one string is a rotation of another

In this program, we need to check whether a string is a rotation of another string or not.

Consider the above example, suppose we need to check whether string 2 is a rotation of string 1. To find this, we concatenate string 1 with string 1. Then, try to find the string 2 in concatenated string. If string 2 is present in concatenated string then, string 2 is rotation of string 1. String 2 deabc is found on the index 3 in concatenated string. So, deabc is rotation of abcde.

string 1

abcde

string 2

deabc

string 1 String2

abcdeabcde

Program

class one_string_rotation {

  public static void main(String[] args)   {

    //declare string

   String str1 = "abcde", str2 = "deabc"; ;

  if (str1.length() != str2.length())

   {

     System.out.println( "second string not rotate" );

   }

 else

  {

  str1=str1.concat(str1);

  if (str1.indexOf(str2)!=-1)

  {

    System.out.println( "second string rotate frist string" );

  }

else

{

  System.out.println( "second string rotate frist string" );

  }

    }

   }

output

Second string is a rotation of first string

Theory

in this program we have roate one string is roate to each other or not. we have to conact one string is itself then found the second string in concated frist string its that means a string is a rotation of another string. if firsr of all check lenght of both strings are equal then to chack wether a string is a rotation of another string . lenghts are not equals the stringits second string is not rotate first.

Q7 Program to remove all the white spaces from a string

remove_white_space

Program to remove all the white spaces from a string

In this program, our task is to remove all the white-spaces from the string. For this purpose, we need to traverse the string and check if any character of the string is matched with a white-space character or not. If so, use any built-in method like replace() with a blank.

In C, we do not have any built-in method to replace. Therefore, we need to run for loop to traverse the string and see if there is any white-space character or not. If so, then start the inner loop (j) from ith character to len and keep replacing each element with its next adjacent element. Decrease the length of the string by 1 on the termination of this loop. Repeat this process until all the white-spaces of the string are removed.

string 1

Remove white spaces

string 2

Removewhitespaces

Program

class remove_white_space {

  public static void main(String[] args)   {

    //declare string

   String str1="Remove white spaces";

  str=str.replaceAll("\\s+", "");

  System.out.println(str);

    }

   }

output

Removewhitespaces

Theory

Thursday 2 December 2021

Program to find the longest repeating sequence in a string

Longest_repeating

Program to find the longest repeating sequence in a string

In this program, we need to find the substring which has been repeated in the original string more than once.

In the above string, the substring bdf is the longest sequence which has been repeated twice.

string 1

"acbdfghybdf"

Program

class Longest_repeating {

  public static String lcp(String s, String t){

   int n = Math.min(s.length(),t.length());

    for (int i = 0; i < n; i++){

    if (s.charAt(i) != t.charAt(i)){

     return s.substring(0,i);

     }

  }

   return s.substring(0,n);

 }

  public static void main(String[] args)   {

    //declare string

   String str1="acbdfghybdf";

  String lrs="";

  int n = str.length();

  for (int i = 0; i < n; i++){

   for (int j = i+1; j < n; j++){

  //Checks for the largest common factors in every substring

    String x = lcp(str.substring(i,n),str.substring(j,n));

     if (x.length() > lrs.length()) lrs=x;

   }

 }

   System.out.println( "Longest repeating sequence: " +lrs);

    }

   }

output

Longest repeating sequence: bdf

Theory

Java Program to determine whether a given string is palindrome

pallindrome

Java Program to determine whether a given string is palindrome

In this program, we need to check whether a given string is palindrome or not. A string is said to be palindrome if it is the same from both the ends. For e.g. above string is a palindrome because if we try to read it from backward, it is same as forward. One of the approach to check this is iterate through the string till middle of string and compare a character from back and forth.

string 1

"mama"

string 2

"kaka"

Program

class String_pallidrome {

  public static void main(String[] args)   {

    //declare string

   String str1="kaka";

  boolean flag= true;

  str= str.toLowerCase();

  for(int i=0;i< (str.length())/2;i++) {

  if (str.charAt(i) != str.charAt(str.length()-i-1))

  {

    flag=false

   break;

   }

  if(flag= true ){

     System.out.println( "pallidrome" );

  }

 else {

       System.out.println( "not pallidrome" );

     }

   }

   }

output

pallidrome

Theory

in this program , we need to check whether a string is palindrome or not. A string is said to palindrome then string backword write is some to write forword otherwise it is not a palindrome string

we are to travel loop to midle of the string to compare the first char to last char then increase the value of i an use flag is boolean varible declare is true but after travelling loop flag is rename true it is palindrome string as basis of our programming method other wise you are use various method as ssson possible to you.

How do you select data from a table in SQL?

Create Table How do you select data a table in SQL? The SELECT statement is used to se...