Showing posts with label tutorials. Show all posts
Showing posts with label tutorials. Show all posts

A simple Phone Number detector Code

Program Code:


package stringrecognizing;

/**
 *
 * @author Shawon
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        String input = "01614728542,01914728542,01552354992,01863767578,01711081503";
        String[] str = input.split(",");
        for(int i=0; i<str.length; i++){
            if(str[i].startsWith("017")){
                System.out.println(str[i]+" -- This is a GP number");
            }else if(str[i].startsWith("018")){
                System.out.println(str[i]+" -- This is a Robi number");
            }else if(str[i].startsWith("019")){
                System.out.println(str[i]+" -- This is a Bangla Link number");
            }else if(str[i].startsWith("016")){
                System.out.println(str[i]+" -- This is a Airtel number");
            }else if(str[i].startsWith("015")){
                System.out.println(str[i]+" -- This is a Teletalk number");
            }else{
                System.out.println(str[i]+" -- Is not a valid Bangladeshi number");
            }
        }
    }

}

List of Some important problem for java ( Basic Practice in Java )


List of Some important problem for java


1. Write a program in Java to check if a number is even or odd in Java? (input 2 output true, input 3 : output false)


A number is called even if it is completely divisible by two and odd if it’s not completely divisible by two. For example number 4 is even number because when you do 4/2 , remainder is 0 which means 4 is completely divisible by 2. On the other hand 5 is odd number because 5/2 will result in remainder as 1.

2. Write a program in Java to find out if a number is prime in Java? (input 7: output true , input 9 : output false)
A number is called prime if it is divisible by either itself or 1. There are many algorithm to find prime numbers e.g. instead of dividing till number, division upto square root of number may be enough. Start from simplest one and than try to solve this problem with couple of different ways.

3. Write Java program to check if a number is palindrome in Java? ( 121 is palindrome, 321 is not)
A number is called a palindrome if number is equal to reverse of number e.g. 121 is palindrome because reverse of 121 is 121 itself. On the other hand 321 is not palindrome because reverse of 321 is 123 which is not equal to 321. See here for solution of  checking if a number is palindrome or not in Java.

4. How to find if a number is power of 2 in Java? (1,2, 4 power of 2, 3 is not)
This is another interesting Java programming exercise. This program can be solved using different ways e.g. using arithmetic operator or by using bit shift operator.

5. Write program to sort an integer array without using API methods?
Sorting questions are one of the integral part of programming questions. There are many sorting algorithm out there to sort any array in Java e.g. Bubble sort, Insertion sort, Selection sort or quick sort. Implementing sorting algorithm itself a good programming exercise in Java.

6. Write Java program to check if a number is Armstrong number or not? (input 153 output true,  123 output false)
An Armstrong number of 3 digit is a number for which sum of cube of its digits are equal to number e.g. 371 is an Armstrong number because 3*3*3 + 7*7*7 + 1*1*1 = 371).

7. Write a program in Java to reverse any String without using StringBuffer?
This is another classical Java programming question. You can reverse String in various way in Java but two programming technique is used to do e.g. Iteration and Recursion. Try solving this problem using Iteration by using Java’s arithmetic operator.

8. Write a program in Java to print Fibonacci series up to given number? Write  iterative version.
Fibonacci series a popular number series and very popular programming question in Java, in which number is equal to sum of previous two numbers, starting from third. Fibonacci series is also a good recursion exercise and often asked in Interviews as well. Try doing this exercise by using both Iteration e.g. loops .

9. Write a Java program to calculate factorial of an integer number ? Write iterative solution.
Calculating Factorial is also a classic recursion exercise in programming. Since factorial is a recursive function, recursion becomes natural choice to solve this problem. You just need to remember formula for calculating factorial which is for n! its n*(n-1)*…1.


10. Print following structure in Java?
This program is a good exercise for mastering loops e.g. for loop and while loop in Java. By the way you can print any character and use System.out.print() and System.out.println()) in below example input is 5,
    *
   ***
  *****
 *******
*********

Note: Solution will be updated one by one. Please stay with this site.............

Database connection code for Java Dekstop Application using SQLite manager

Database connection code for Java Desktop Application using SQLite manager


import java.sql.*;
import javax.swing.*;
public class JavaConnect {
    
    Connection conn=null;
    
    public static Connection connectorDB(){
       
        try{
            Class.forName("org.sqlite.JDBC");
            
                    Connection conn=DriverManager.getConnection("jdbc:sqlite:C:\\Users\\RunTime Error\\Desktop\\Contact\\contact_bd.sqlite");
     //              JOptionPane.showMessageDialog(null, "Connection Established");
                    
                    return conn;
                    
            } catch(Exception e){
                JOptionPane.showMessageDialog(null, e);
                  return null;
            }
      
        
    }
    
    
}

How to convert String to Number in java program

How to convert String to Number in java program 


Just use A simple Snip code:


String st=”123”;

Int i=Integer.ParseInt(st);

System.out.println(i);

A java simple source code consider all the exception

Write a Calculator class which prosses some methods named, add, multi, sub, div and reminder. Write another class named Tester in which you will prompt two inputs from user and print the results of those methods. Consider all the exception cases.

Ans:


//Write the main class name Tester and copy the code and run.
//Thanks to all




package calculator1;

import java.util.Scanner;

/**
 *
 * @author RunTime Error
 */

class Calculator{

static int add(int x, int y)     // adds x and y, then returns
{
int res;
res = x+y;
return res;

}
static int sub(int x, int y) // subtract  y from x, then returns
{
int res;
res = x-y;
return res;

}
static int multi(int x, int y) // multiplies x and y, then returns
{
int res;
res = x*y;
return res;
}
static String div(int x, int y) // divide x by y, then returns the quotient
{
float res=0;
                String st=null;
try{
                   res = x/y; 
                   st=res+"";
                } catch(Exception e){
                    System.out.println("Input Error: "+e);
                }
                
return st;
}
static String remainder(int x, int y) // divide x by y, then returns the remainder
{
           float res=0;
                String st=null;
try{
                   res = x%y; 
                   st=res+"";
                } catch(Exception e){
                    System.out.println("Input Error: "+e);
                }
                
return st;
}


}
public class Tester extends  Calculator{

    /**
     * @param args the command line arguments
     */
    
public static void main(String args[]){

    Scanner input = new Scanner(System.in);
    System.out.println("Enter 1st Number:");
int a=input.nextInt(); 
 System.out.println("Enter 2nd Number:");
int b=input.nextInt();

//result = add(a,b);
System.out.println("The result of the Addition is : "+ add(a,b));
//result = sub(a,b);
System.out.println("The result of the Subtraction is : "+ sub(a,b));
//result = multi(a,b);
System.out.println("The result of the Multiplication is : "+ multi(a,b));
//result = div(a,b);
                String div=div(a,b);
                if(div!=null)
System.out.println("The result of the Division is : "+ div);
//result = mod(a,b);
                 String rem=remainder(a,b);
                if(rem!=null)
System.out.println("The result of the remainder is : "+ div);
                

}

}

Pattern and Matcher easy source code in java

Write a class named “find”, use Pattern, Matcher class to find “love” in the following String: “I love java”.

import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Tester
{
public static void main (String[] args)
{
String t ="I love Java";
Pattern pattern = Pattern. compile("love");
Matcher matcher = pattern. matcher(t);
if (matcher . find())
{
System. out.println("Found match!");
}
}
}

if , ifelse and elseif Operator In C++

If Operator


"If", which is used as a conditional operator. "If" keyword execute the statement only if the condition will be true.

Syntax: 
if (condition) 
statement:
Source code of "If" operator:


If-else


When if condition will be false then the statement of else condition will execute.

Syntax: 
if (condition) 
statement1
 else statement2.

Source code of "Ifelse" operator:



In above code “a=10”,”b=9” there are not equal , so “if(a==b)” condition is not true .
the output will be….

If-else-if


When  if condition will be false then it execute else. If we want to add more if condition with else,Then we have to use elseif such as:

Syntax:
if (condition)
 statement 1 
else if 
(condition) statement 2.

Source code of "If-else-if" operator:





In above code “a=10”,”b=9” there are not equal , so “if(a>b)” condition is not true .So
the output will be….


Thats everything for if, ifelse and elseif condition.


How to create android first project on eclipse???

How to create android first project on eclipse???



Step 01: Click New  in the toolbar.
                                  



Step 02: Open the Android folder, select Android Application Project, and click Next.




Step 03: Fill in the form that appears:
ü  Application Name.
ü  Project Name.
ü  Package Name.
Step 04: Minimum Required SDK is the lowest version of Android that your app supports, indicated using the API level.
Step 05: Target SDK indicates the highest version of Android (also using the API level) with which you have run with your application.
Step 06: Click Next.


Step 07: Again click Next.



Step 08: The next screen can help you create a launcher icon for your app.



Step 09: Click Next.
Step 10: For initial project, select BlankActivity and click Next.



Step 11: Then  click Finish.



Finally your android first project is opened....WoW!!! You have done it!!

Are you new in programming???????

Are you new in programming???????

If you are new, better will be if you start programming in C.



Who are new in programming for them its a little try to help them..

C programming tutorials collection..
        
       
            Please Click Here To Download

Java Language learning



Java is a high level programming language that is object-oriented programming language.


The fundamentals of Java programming in the step of learning you have to know.

1.Object-Oriented Programming Concepts: Object-oriented programming means objects, messages, classes, and inheritance.

2.Language Basics: variables, arrays, data types, operators, and control flow.

3.Classes and Objects. 

3.Interfaces and Inheritance.

4.Numbers and Strings.

5.Packages.

HTML Tutorials Part: 02 (Basic HTML Tag Information)

Your Second Web Page
Now that you have created your first webpage, let us examine the different segments of your "index.html" file.
You have probably noticed a pattern of various words that are surrounded with < and >. These items are called
HTML tags.
An example of an html tag is <body>. The Body tag tells the browser where the page's content begins. Body is also an example of one of the required HTML tags that every web page must have.

Basic HTML Tag Information
Let's learn more about these tags. A basic web page is composed of 2 main tags. If you create a web page without these tags you will be in trouble!

HTML Code:

<html>
<body>
Your site's content goes here
</body>
</html>

The first HTML tag, which conveniently is labeled <html> tells the browser that your HTML code is starting. The second HTML tag, <body> tells the browser that the visible part of the webpage ( your content ) is going to start.

Closing Tags - </tag>
You might be wondering what is the deal with the two tags at the end, </body> and </html>. These tags are telling the browser that certain tags are ending. The </body> lets the browser know that your content is ending,while the </html> tells the browser that your HTML file is finished. The "/" that is placed before the tag's name informs the browser that you would like to stop using the specified tag.<tag> is used to begin a tag and </tag> is used to end a tag.

HTML Tag Order - Important!
The order that opening tags appear and ending tags appear follows an important rule. If an HTML tag is opened within another, for example the body tag is opened inside the html tag, then that tag(body) must close before the outter(html) tag is closed.
We ended the body tag first because it was opened most recently. This rule of "closing the most recent tag before closing older tags" applies to all HTML tags.



Continue Along
These ideas might take a while to sink in, so how about you create your second web page? Copy this code into notepad/DW, like you did before, following the same directions.
<html>

<head>
<title>My Own Webpage!</title>
</head>
<body>

<h2>Welcome to my webpage</h2>

<p>Coming soon will be my completed webpage that will wow and impress you!</p>

</body>
</html>
After you are sure that your HTML code inside notepad/DW is exactly the same as our provided HTML code,go ahead and save your file. You should be saving this file as "index.html". You may be prompted that you will be saving over a file, that is OK, you do not need your 1st web page anymore. When you are done, please continue.

Words to Know
Tag - Used to specify ("mark-up") regions of HTML documents for the web browser tom interpret. Tags look like this: <tag>
Element - A complete tag, having an opening <tag> and a closing </tag>.
Attribute - Used to modify the value of the HTML element. Elements will often have multiple
attributes. 
For now just know that a tag is a command the web browser interprets, an element is a complete tag, and an attribute customizes or modifies HTML elements.

HTML Elements
An element consists of three basic parts: an opening tag, the element's content, and finally, a closing tag.
1.<p> - opening paragraph tag
2.Element Content - paragraph words
3.</p> - closing tag
Every (web) page requires four critical elements: the html, head, title, and body elements.


The <html> Element...</html>
<html> begins and ends each and every web page. Its sole purpose is to encapsulate all the HTML code and describe the HTML document to the web browser. Remember to close your HTML documents with the corresponding </html> tag at the bottom of the document.
If you haven't already, open up Notepad or DW and have a new, blank document ready to go. Copy the following HTML code into your text editor.

<html>
</html>

Now save your file by Selecting Menu and then Save. Click on the "Save as Type" drop down box and select the option "All Files". When asked to name your file, name it "index.html", without the quotes. Double check that you did everything correctly and then press save. Now open your file in a new web browser so that you have the ability to refresh your page and see your changes.
If you opened up your index.html document, you should be starring at your very first blank (white) web page!

The <head> Element
The <head> element is "next" as they say. As long as it falls somewhere between your <html> tag and your webpage content (<body>), you're golden. The head functions "behind the scenes." Tags placed within the head element are not directly displayed by web browsers. We will be placing the <title> element here and we'll talk about the other possible elements in later lessons.
Other elements used for scripting (Javascript) and formatting (CSS) will eventually be introduced and you will have to place them within your head element. For now, your head element will continue to lay empty except for the title element that will be introduced next.
Here's a sample of the initial set up.
<html>
<head>
</head>
</html>

As of yet, we still have nothing happening on the web page. All we have so far is a couple of necessaryelements that describe our document to the web browser. Content (stuff you can see) will come later.


The <title> Element
Place the <title> tag within the <head> element to title your page. The words you write between the openingand closing <title></title> tags will be displayed at the top of a viewer's browser.
Here's the html code:

<html>
<head>
<title>My WebPage!</title>
</head>
</html>

Save the file and open it in your browser. You should see "My WebPage!" in the upper-left, as the window's title.
Name your webpage as you please, just keep in mind, the best titles are brief and descriptive.

The <body> Element
The <body> element is where all content is placed. (Paragraphs, pictures, tables, etc). As the menu on the left suggests, we will be looking at each of these elements in greater detail as the tutorial progresses. For now, it is only important to understand that the body element will encapsulate all of your webpage's viewable content.

<html>
<head>
<title>My WebPage!</title>
</head>
<body>
Hello World! All my content goes here!
</body>

</html>

HTML Tutorials Part : 01(Introduction to HTML and web design)

Introduction to HTML and web design




Welcome to Our introduction to HTML (Hyper Text Markup Language) and web design. This short tutorial is aimed to give newbie’s a little experience in writing HTML code, saving their files correctly, and viewing the completed works in a web browser. Regrettably this tutorial cannot teach you the basics of using a computer, so please be sure that you meet the following requirements:

Know what notepad/DW is and how to use it
Are able to open up a file using Internet Explorer (or the browser of your choice)
Know how to copy and paste text from a webpage (important!).
If you are lacking the ability of the aforementioned items please contact me and ask nicely for a quick lesson.

Tutorial Overview
In this tutorial you will be transcribing code into Dream Weaver and then viewing it with a web browser. The code is called HTML (Hyper Text Markup Language). HTML may seem confusing at first, but we will help you understand how it works in this step-by-step tutorial of how to make your first web page.

Your First Web Page
To start off with copy the following HTML code into DW/notepad. Be sure to copy the code exactly, otherwise your web page may not function correctly.