How to search and find Index Number of a word in a String in Java?


Code : 
package demo;
import java.util.Scanner;
/**
 *
 * @author www.CodeTheta.com
 */
public class StringSearch {
    public static void main(String[] args) {
        String TextString;
        String FindString;
        System.out.println("Enter a string : ");
        Scanner in = new Scanner(System.in);
        TextString = in.next();
        System.out.println("Enter a word you want to find.");
        Scanner in1 = new Scanner(System.in);
        FindString = in1.next();
        int IndexNumber = TextString.indexOf(FindString);
        if(IndexNumber == - 1) {
            System.out.println("Not Found");
        } else {
            System.out.println("Entered Word Found at Index Number : " + IndexNumber);
        }
   }
}

Output :
Enter a string : 
codetheta
Enter a word you want to find.
d
Entered Word Found at Index Number : 2

IDE Used To Test This Code : NetBeans IDE 8.2

Try this code in your computer for better understanding. Enjoy the code. If you have any Question you can contact us or mail us.We will reply you as soon as possible.

How to check two string equal or not in JAVA?


Code :
package demo;
import java.util.Scanner;
/*
 * @author www.CodeTheta.com
 */
public class Demo {
    public static void main(String[] args) {
    String UserString1,UserString2;
    System.out.println("Enter any string: ");
    Scanner in = new Scanner(System.in);
    UserString1 = in.next();
    UserString2 = in.next();
    if(UserString1.equals(UserString2)){
        System.out.println("Equal String");
    }
    else {
        System.out.println("Not Equal String");
    }   
    }   
}

Output :
Enter any string: 
www.codetheta.com
www.codetheta.com
Equal String

IDE Used To Test This Code : NetBeans IDE 8.2

Try this code in your computer for better understanding. Enjoy the code. If you have any Question you can contact us or mail us.We will reply you as soon as possible.

How to find String Length in Java using length function?


Below program segment value given by user in program execution time.
Code :
package demo;
import java.util.Scanner;
/*
 * @author www.CodeTheta.com
 */
public class Demo {
    public static void main(String[] args) {
    String UserString;
    System.out.println("Enter any string: ");
    Scanner in = new Scanner(System.in);
    UserString = in.next();
    System.out.println("Length of given string is: "+UserString.length());   
    }   
}

Output :
Enter any string: 
www.codetheta.com
Length of given string is: 17

Below program segment value already assigned.
Code :
package demo;
/*
 * @author www.CodeTheta.com
 */
public class Demo {
    public static void main(String[] args) {
    String UserString = "www.codetheta.com";
    System.out.println("Length of given string is: "+UserString.length());   
    }   

}

Output :
Length of given string is: 17

IDE Used To Test This Code : NetBeans IDE 8.2

Try this code in your computer for better understanding. Enjoy the code. If you have any Question you can contact us or mail us.We will reply you as soon as possible.

How to calculate Circle area in Java programming?


Code :
package demo;
import java.util.Scanner;
/*
 * @author www.CodeTheta.com
 */
public class Demo {
    public static void main(String[] args) {
    double CircleArea,Radius;
    double Pi=3.14;
    System.out.println("Enter radius of a circle: ");
    Scanner in = new Scanner(System.in);
    Radius = in.nextInt();
    CircleArea = Pi * Radius * Radius;
    System.out.println("Area of a circle is: "+CircleArea);   
    }   
}

Above program calculating Circle area through user input during program execution time.

Output :
Area of a circle is: 28.259999999999998

Code :
package demo;
/*
 * @author www.CodeTheta.com
 */
public class Demo {
    public static void main(String[] args) {
    double CircleArea,Radius = 3;
    double Pi=3.14;
    CircleArea = Pi * Radius * Radius;
    System.out.println("Area of a circle is: "+CircleArea);   
    }   

}

Above program calculating Circle area through user defined input.

Output :
Area of a circle is: 28.259999999999998


IDE Used To Test This Code : NetBeans IDE 8.2

 Try this code in your computer for better understanding. Enjoy the code. If you have any Question you can contact us or mail us.We will reply you as soon as possible.

How to install CouchCMS and test in your localhost server?


CouchCMS is an open source CMS that you can integrate with any custom based HTML or PHP website. With the help of  CouchCMS you can edit your website front end data through admin / back end section.\

Here is few simple steps that you can run it on your machine / localhost successfully.

Prerequisite :
1. XAMPP / WAMP

1. You must have XAMPP installed on your machine.

2. Download the latest version of CouchCMS through URL - https://www.couchcms.com/

3. After that go to your htdocs folder or follow this path C:\xampp\htdocs

4. Paste the CouchCMS download folder to htdocs folder and extract it.

5. Before installation CouchCMS requires a database, so we need to create a database, for database creation open your default browser like Chrome or Firefox and in URL section type localhost/phpmyadmin and then create a database with any name.

6. After that open your CouchCMS folder and you will see a PHP file called config.example.php, rename this file to config.php otherwise you will get error like this -
"config.php" not found. Perhaps you forgot to rename the "config.example.php" file to "config.php" after editing it?

7. Now open config.php file to notepad and you will see code like this -

// Name of the database
define( 'K_DB_NAME', 'database_name' );
// Database username
define( 'K_DB_USER', 'database_username' );
// Database password
define( 'K_DB_PASSWORD', 'database_password' );

8. Now change the database_name to your phpmyadmin databse, database_username to your local database username and database_password with database password.

7. Now go to browser tab and type localhost and go to CouchCMS folder and you will see a installation form will come up. You need to put your local database, username and password and then click on install button and after that installation will be successful.

Simple Linked List program example in C++


This is a simple Linked List program which contains three nodes. First, Second, Third .Each node have data part and next part. First, Second, Third nodes data part contain 30,40,50 value respectively.

Code :
#include<iostream>
#include<stdlib.h>
using namespace std;
struct Node 
{
  int data;
  struct Node *next;
};
int main()
{
  struct Node* First = NULL;
  struct Node* Middle = NULL;
  struct Node* Last = NULL;
  First = (struct Node*)malloc(sizeof(struct Node)); 
  Middle = (struct Node*)malloc(sizeof(struct Node));
  Last = (struct Node*)malloc(sizeof(struct Node));
  First->data = 30;
  First->next = Middle;
  Middle->data = 40;
  Middle->next = Last;
  Last->data = 50;
  Last->next = NULL;
  cout<<"\nFirst :"<<First->data;
  cout<<"\nMiddle :"<<Middle->data;
  cout<<"\nLast :"<<Last->data;
  return 0;
}

Output :
First : 30
Middle : 40
Last : 50

IDE Used To Test This Code : DEV C++.

Try this code in your computer for better understanding. Enjoy the code. If you have any Question you can contact us or mail us.We will reply you as soon as possible.

How to find Absolute Number in Java with user input?


In Java you can easily find Absolute Number with user input. Follow the below code :

Code :
import java.util.Scanner;
public class Absolute_Number {
public static void main(String[] args) {
    int Number;
    System.out.println("Enter The Negative or Positive Number: ");
    Scanner in = new Scanner(System.in);
    Number = in.nextInt();
    if (Number < 0)
    {
      Number = (-1)* Number;
    }
    System.out.println("Result is: "+ Number);
    }
}

Output :
Enter The Negative or Positive Number: -230
Result is: 230

IDE Used To Test This Code : Dr. Java

Try this code in your computer for better understanding. Enjoy the code. If you have any Question you can contact us or mail us.We will reply you as soon as possible.

How to make correct circle by CSS?


You can easily make circle by using CSS. Code written in below.

HTML Code :
<html>
<head>
<title>
CSS Circle | https://native-code.blogspot.in
</title>
<link rel="stylesheet" type="text/css" href="main.css">
</head>
<body>
<div class="div-box">
</div>
</body>
</html>

CSS Code :
.div-box {
width: 200px;
height: 200px;
background-color: gray;
border-radius: 50%;
}

Output :

IDE Used To Test This Code : Sublime Text.

Try this code in your computer for better understanding. Enjoy the code. If you have any Question you can contact us or mail us.We will reply you as soon as possible.

How to make Diagonal Stripes in Div by CSS?


This tutorial will teach you how you can make Diagonal Stripes within any DIV by CSS.

HTML Code : 
<html>
<head>
<title>Diagonal Stripes in DIV CSS | native-code.blogspot.com</title>
<link rel="stylesheet" type="text/css" href="main.css">
</head>
<body>
<div class="diagonal-stripes">
<h1>Diagonal Stripes CSS</h1>
</div>
</body>
</html>

CSS Code :
.diagonal-stripes {
width: 700px;
height: 300px;
border: 1px solid black;
background: repeating-linear-gradient(
 45deg,
 #B0BEC5,
 #B0BEC5 10px,
 #78909C 10px,
 #78909C 20px
);
}

Output :


IDE Used To Test This Code : Sublime Text.

Try this code in your computer for better understanding. Enjoy the code. If you have any Question you can contact us or mail us.We will reply you as soon as possible.

How to add Bootstrap in to your CodeIgniter project


This tutorial will make you understand how you can add or integrate Bootstrap Framework to your CodeIgniter project. Follow the below steps -

Step 1 : Download Bootstrap Framework from http://getbootstrap.com/ and download CodeIgniter from https://www.codeigniter.com/.

Step 2 : After that make a asset folder (or any other name) to CodeIgniter folder.

Step 3 : Then copy the Bootstrap content (3 folders [css, fonts, js]) to asset folder.

Step 4 : After that go to your view folder (application --> views).

Step 5 : Then link the bootstrap css to view page. Below code will integrate the css and put the code between  the <head></head> tag.

<link href="<?php echo base_url(); ?>assets/css/bootstrap.min.css" rel="stylesheet">

Step 6 : Save and reload the page and you will see that bootstrap successfully added to your Codeigniter project.

IDE Used To Test This Code : Eclipse for PHP.

Try this code in your computer for better understanding. Enjoy the code. If you have any Question you can contact us or mail us.We will reply you as soon as possible.

How to show Date and Time in webpage through CodeIgniter


If you are using CodeIgniter Framework and you want to add or show current Date and Time in to your webpage then follow the below steps and you will able do that.

Step 1 : Go to your CodeIgniter Directory and click on Application and then Config folder and then click on config.php file.

application --> config --> config.php

Step 2 : In config.php file add the following code:

date_default_timezone_set('Asia/Kolkata');

Note : For your local time and date put your country name and location in Asia/Kolkata.

Step 3 : After that in your view folder choose a file where you want to show your local time and date. Choose the file and put the following code:

echo date("l j \, F Y h:i:s A");

Step 4 : That's all. Now you will able to see your local time and date.

IDE Used To Test This Code : Eclipse for PHP.

Try this code in your computer for better understanding. Enjoy the code. If you have any Question you can contact us or mail us.We will reply you as soon as possible.

How To Show Div Box Side By Side Using inline-block CSS


Div box is very useful for web design. Here i have shown how you can display your div box side by side using inline-block CSS.

Code :

Index.html
<html>
<head>
<title>Inline Block Example With Div Box</title>
<link rel="stylesheet" type="text/css" href="main.css">
</head>
<body>
<div class="div-box"></div>
<div class="div-box"></div>
<div class="div-box"></div>
<div class="div-box"></div>
<div class="div-box"></div>
<div class="div-box"></div>
<div class="div-box"></div>
<div class="div-box"></div>
<div class="div-box"></div>
<div class="div-box"></div>
<div class="div-box"></div>
<div class="div-box"></div>
</body>
</html>

Code :

main.css
.div-box {
width: 200px;
height: 200px;
background-color: gray;
display: inline-block;
}

Output :


IDE Used To Test This Code : Google Chrome.

Try this code in your computer for better understanding. Enjoy the code. If you have any Question you can contact us or mail us.We will reply you as soon as possible.

JAVA Program To Calculate Factorial Of A Number


Using predefined value
In this predefined program as you can see that i have already defined the value in InputNumber variable and the value is 3.

Code :
class Factorial
{
 public static void main(String args[])
 {
  int InputNumber=3,LoopVariable,Result=1;
  for (LoopVariable=1;LoopVariable<=InputNumber;LoopVariable++)
  {
   Result=Result*LoopVariable;
  }
  System.out.println("Factorial Result is: "+Result);
 }
}

Output :
Factorial is: 6


Using user input
Here you can see that i have used Scanner class to take the value from the user and calculate the factorial.

Code :
import java.util.Scanner;
class Factorial
{
 public static void main(String args[])
 {
  int InputNumber,LoopVariable,Result=1;
  Scanner ScannerObject = new Scanner(System.in);
  System.out.println("Enter a Positive Number To Calculate Its Factorial: ");
  InputNumber = ScannerObject.nextInt();
  for (LoopVariable=1;LoopVariable<=InputNumber;LoopVariable++)
  {
   Result=Result*LoopVariable;
  }
  System.out.println("Factorial Result is: "+Result);
 }
}

Output :
Enter a Positive Number To Calculate Its Factorial:
5
Factorial Result is: 120

IDE Used To Test This Code : Dr Java

Try this code in your computer for better understanding. Enjoy the code. If you have any Question you can contact us or mail us.We will reply you as soon as possible.