Monday, November 30, 2015

history of the United States

The date of the start of the history of the United States is a subject of constant debate among historians. Older textbooks start with the arrival of Christopher Columbus in 1492 and emphasize the European background, or they start around 1600 and emphasize the American frontier. In recent decades American schools and universities typically have shifted back in time to include more on the colonial period and much more on the prehistory of the Native peoples.
Indigenous people lived in what is now the United States for thousands of years before European colonists began to arrive, mostly from England, after 1600. The Spanish had small settlements in Florida and the Southwest, and the French along the Mississippi River and the Gulf Coast. By the 1770s, thirteen British colonies contained two and a half million people along the Atlantic coast east of the Appalachian Mountains. In the 1760s the British government imposed a series of new taxes while rejecting the American argument that any new taxes had to be approved by the people (see Stamp Act 1765). Tax resistance, especially the Boston Tea Party (1774), led to punitive laws (the Intolerable Acts) by Parliament designed to end self-government in Massachusetts. American Patriots (as they called themselves) adhered to a political ideology called republicanism that emphasized civic duty, virtue, and opposition to corruption, fancy luxuries and aristocracy.
All thirteen colonies united in a Congress that called on them to write new state constitutions. After armed conflict began in Massachusetts, Patriots drove the royal officials out of every colony and assembled in mass meetings and conventions. Those Patriot governments in the colonies unanimously empowered their delegates to Congress to declare independence. In 1776, Congress declared that there was a new, independent nation, the United States of America, not just a collection of disparate colonies. With large-scale military and financial support from France and military leadership by General George Washington, the American Patriots rebelled against British rule and succeeded in the Revolutionary War. The peace treaty of 1783 gave the new nation the land east of the Mississippi River (except Florida and Canada, and Spain disputed the Mississippi Territory until 1795) and confirmed Great Britain's recognition of the United States as a nation. The central government established by the Articles of Confederation proved ineffectual at providing stability, as it had no authority to collect taxes and had no executive officer. Congress called a convention to meet secretly in Philadelphia in 1787 to revise the Articles of Confederation. It wrote a new Constitution, which was adopted in 1789. In 1791, a Bill of Rights was added to guarantee inalienable rights. With Washington as the Union's first president and Alexander Hamilton his chief political and financial adviser, a strong central government was created. When Thomas Jefferson became president he purchased the Louisiana Territory from France, doubling the size of the United States. A second and final war with Britain was fought in 1812.
Encouraged by the notion of Manifest Destiny, federal territory expanded all the way to the Pacific. The U.S. always was large in terms of area, but its population was small, only 4 million in 1790. Population growth was rapid, reaching 7.2 million in 1810, 32 million in 1860, 76 million in 1900, 132 million in 1940, and 321 million in 2015. Economic growth in terms of overall GDP was even faster. However the nation's military strength was quite limited in peacetime before 1940. The expansion was driven by a quest for inexpensive land for yeoman farmers and slave owners. The expansion of slavery was increasingly controversial and fueled political and constitutional battles, which were resolved by compromises. Slavery was abolished in all states north of the Mason–Dixon line by 1804, but the South continued to profit off the institution, producing high-value cotton exports to feed increasing high demand in Europe. The 1860 presidential election of Republican Abraham Lincoln was on a platform of ending the expansion of slavery and putting it on a path to extinction. Seven cotton-based deep South slave states seceded and later founded the Confederacy months before Lincoln's inauguration. No nation ever recognized the Confederacy, but it opened the war by attacking Fort Sumter in 1861. A surge of nationalist outrage in the North fueled a long, intense American Civil War (1861-1865). It was fought largely in the South as the overwhelming material and manpower advantages of the North proved decisive in a long war. The war's result was restoration of the Union, the impoverishment of the South, and the abolition of slavery. In the Reconstruction era (1863–1877), legal and voting rights were extended to the freed slave. The national government emerged much stronger, and because of the Fourteenth Amendment, it gained the explicit duty to protect individual rights. However, when white Democrats regained their power in the South during the 1870s, often by paramilitary suppression of voting, they passed Jim Crow laws to maintain white supremacy, and new disfranchising constitutions that prevented most African Americans and many poor whites from voting, a situation that continued for decades until gains of the civil rights movement in the 1960s and passage of federal legislation to enforce constitutional rights.
The United States became the world's leading industrial power at the turn of the 20th century due to an outburst of entrepreneurship in the Northeast and Midwest and the arrival of millions of immigrant workers and farmers from Europe. The national railroad network was completed with the work of Chinese immigrants and large-scale mining and factories industrialized the Northeast and Midwest. Mass dissatisfaction with corruption, inefficiency and traditional politics stimulated the Progressive movement, from the 1890s to 1920s, which led to many social and political reforms. In 1920, the 19th Amendment to the Constitution guaranteed women's suffrage (right to vote). This followed the 16th and 17th amendments in 1913, which established the first national income tax and direct election of US senators to Congress. Initially neutral during World War I, the US declared war on Germany in 1917 and later funded the Allied victory the following year. After a prosperous decade in the 1920s, the Wall Street Crash of 1929 marked the onset of the decade-long world-wide Great Depression. Democratic President Franklin D. Roosevelt ended the Republican dominance of the White House and implemented his New Deal programs for relief, recovery, and reform. The New Deal, which defined modern American liberalism, included relief for the unemployed, support for farmers, Social Security and a minimum wage. After the Japanese attack on Pearl Harbor on December 7, 1941, the United States later entered World War II along with Britain, the Soviet Union, China, and the smaller Allies. The U.S. financed the Allied war effort and helped defeat Nazi Germany in Europe and defeated Imperial Japan in the Pacific War. The American use of newly inventedatomic bombs on Japanese cities remains controversial into the 21st century.
The United States and the Soviet Union emerged as rival superpowers after World War II. During the Cold War, the US and the USSR confronted each other indirectly in the arms race, the Space Race, proxy wars, and propaganda campaigns. US foreign policy during the Cold War was built around the support of Western Europe and Japan along with the policy of "containment" or stopping the spread of communism. The US joined the wars in Korea and Vietnam to try to stop its spread. In the 1960s, in large part due to the strength of the civil rights movement, another wave of social reforms were enacted by enforcing the constitutional rights of voting and freedom of movement to African-Americans and other racial minorities. Native American activism also rose. The Cold War ended when the Soviet Union officially dissolved in 1991, leaving the United States as the world's only superpower. As the 21st century began, international conflict centered around the Middle East following the September 11 attacks by Al-Qaeda on the United States in 2001. In 2008, the United States had its worst economic crisis since the Great Depression, which has been followed by slower than usual rates of economic growth during the 2010s.

Introduction to Application Development

Introduction to Application Development

An application is software that is designed to meet specific user requirements. For example, the applications that you use for creating documents, sending email and instant messages, playing computer games, or listening to music are pieces of software developed to accomplish a particular task. To meet various types of requirements, you need to accordingly create various types of applications. Before you actually get into the application development process, you need to consider various factors, such as the type of application to be developed and the technology to develop the required application.

Identifying the Types of Applications

An application can be categorized on the basis of various factors, such as the type of interface it provides, the architecture on which it operates, the platform on which it
runs, and the device on which it has to be accessed or used. An application allows users to accomplish the desired tasks by accepting instructions. These instructions are given to the application through its interface. On the basis of the interface, applications can be broadly classified into the following categories:



Character User Interface (CUI) :

 In an application that provides a CUI, the instructions are given in the form of commands. These commands are a combination of characters. In these applications, the instructions can be given only by typing commands with the help of a keyboard.

Graphical User Interface (GUI) :

 In an application that provides a GUI, the instructions are given to the application by using various graphical components, such as menus, icons, buttons, and links. In such an application, a pointing device, such as a mouse, joystick, or trackball, is used to interact with the application. For example, the Windows operating system provides a GUI for interaction. In addition, these days most of the applications are developed with a GUI.

Applications can also be classified on the basis of their underlying architecture. From an architectural perspective, an application can be classified into the following layers:




Presentation layer : Consists of the interface through which the users interact with the application. Business logic layer : Consists of the components of the application that control the flow of execution and communication between the presentation and the data layers.

 Data layer : Consists of data storage, such as a file or a database.


Most applications are built using all the three layers. The manner in which these layers are distributed and the way in which they communicate with each other, define the architecture of an application. An application can have one of the following types of architecture:



Single-tier architecture :

 In an application based on the single- tier architecture, all the three layers are integrated together and can be installed on a single computer. If the application needs to be accessed on multiple computers, a separate installation is required on each of the computers. For example, Adobe Photoshop that is used to create and edit graphics is a standalone application based on the single- tier architecture.
Two- tier architecture : In an application based on the two-tier architecture, the three layers are distributed over two tiers, a client and a server. The presentation layer resides on each client computer, the business logic layer resides either on the client or on the server, and the data access layer resides on the server. Depending on the business requirements, an organization can have the following types of two-tier application architecture:

Fat client and thin server : The architecture in which the business logic layer resides on the client tier is referred to as the fat client and thin server architecture. 
In this architecture, the client accepts user requests and processes these requests on its own. The client communicates with the server only when the data for communication or archival needs to be sent to the server.
 Fat server and thin client : The architecture in which the business logic layer resides on the server is referred to as the fat server and thin client architecture. In this architecture, the client accepts requests from the users and forwards the same to the server. Further, the server processes these requests and provides responses. 


The two- tier architecture can be used when multiple users need to access and manipulate common data storage. For example, an application has to be developed to store an organization’s employee details in a database. In addition, the application should allow the retrieval of the employee details from the database. In this case, the employee details need to be entered and retrieved by using multiple computers. Therefore, installing a database, along with the application on each computer, may lead to storage of duplicate records. In addition, a user cannot retrieve the employee details that are stored on some other computer. To avoid these problems, the application can be installed on each computer. However, the database is installed on a single computer, and the same can be accessed by applications on multiple computers. In the preceding example, the presentation and business logic layers are integrated and installed on each computer. The applications installed on the computers send requests to the server (database) for the storage and retrieval of data. On the other hand, the server accepts the requests and responds accordingly. In this setup, the fat client and thin server architecture is used. 

Three- tier architecture :

 In an application based on the three- tier architecture, the three layers of the application are placed separately as three different entities. This architecture is used for those applications in which merging the business logic layer with the presentation layer or the data layer may degrade the performance of the application. To improve the application performance, the three layers are kept separately and the communication among the layers occurs with the help of a request-response mechanism.

INTRODUCTIONS

INTRODUCTIONS 

Introductions can be challenging and can require effort. However, you must always project energy while making introductions. You owe it to yourself and the individuals involved. Make the individuals feel that you are pleased and honored to connect with them. Allow them to feel as if they are special. Set the tone of introduction by providing a proper, professional power launch.

Self: 


  • Introduction is the first thing that you do when you meet someone for the first time. 
  • It does not require excess effort and certainly does not need a strong personality. 
  • All you need to do is to sport a smile and warmly say ’Hello’.

Others:

  •  Introduce people with their complete names. Avoid using the first names of seniors or supervisors. Ensure that you remember the names of these people and know how to pronounce them correctly.
  •  Drop in a line or two while introducing people to each other, rather than just the names.
  •  Address the more important person first and introduce the lesser important person to him or her. 
  • Keep the introductions short and simple. 

Nuances of a Professional Introduction:


  • Use honorifics. Address men as Mr. and women as Ms., unless instructed otherwise.
  •  Use honorifics if the person you are introducing holds a degree or a position, such as Doctor or Major.
  •  Make an effort to find the honorifics and use them while introducing politicians and dignitaries from other countries.
  • Ask a person, if you got any doubt how he/she prefers to be addressed and introduced as. 
  • Maintain a balance in business introductions. You cannot introduce two people as, “Dr. Kalyani Gupta, please meet Mr. Duggal.” 
  • Say the name of the most important person first. 
  • Put the customer first while introducing him/her to anyone from your company. 
  • Ensure that the supervisor comes first when you introduce family members to your supervisor during an office event.
  •  Introduce the elder person first if both the individuals share the same rank. 

BODY LANGUAGE

BODY LANGUAGE 

Body language is like a computer. Most of the people know what it is and how to use it, but very few are actually aware of how it works. This is because the process of decoding non verbal (or body language) clues is done on a sub conscious level. Humans are innately programmed to identify and interpret facial and behavioral cues. People see and interpret a gesture and often make judgments about the person they are communicating with in a matter of seconds. It is good to remember that non verbal signals that a person sends out play a vital role in the first impression he creates. Our ancestors efficiently used to read and interpret nonverbal clues because their survival often depended on
the ability to correctly decode the visual information. Over the ages, humans have lost the edge and now people make mistakes while interpreting body language. Not all first impressions are correct. The kind of life we live today is far more complex, and there are many layers of social boundaries and restrictions. There are many meanings that add to the social dealings and interactions. The corporate culture also adds complexities in the form of restrictions and guidelines for behavior in the mix. A person can improve his ability to correctly decode the body language by sifting the impressions he gets from other person through five Cs. These five Cs are: 
  1. Context
  2.  Clusters
  3.  Congruence
  4.  Consistency
  5.  Culture

POSITIVE BODY LANGUAGE

Eye contact: Maintain proper eye contact but look away after every ten seconds so that the other person does not get uncomfortable.
Facial expression/Mouth: Remember that a smile gives a positive message and creates a feel good factor.
 Hands/Arms: Open arms with controlled movements are definitely preferred over fidgety arms and hands.
 Legs: Cross your legs at the ankles if you are a woman, and keep them flat on the floor if you are a man.
Body angle/Body posture: Sit attentively, appearing neither too loose nor too stiff. Proximity: Maintain at least one foot distance (neither more, nor less) between you and the other person.



Thursday, November 26, 2015

SQL TRUNCATE Statement

SQL TRUNCATE Statement

SQL TRUNCATE TABLE statement used to completely remove all table records. Not supporting to a WHERE clause.
SQL TRUNCATE statement is faster and use some transaction log resources.
SQL TRUNCATE statement logically equivalent to a DELETE statement that deletes all rows, but they are practically different under some rules.

SQL TRUNCATE Statement Rules

  • TRUNCATE operation use for dropping or re-create table, which is much faster than deleting rows one by one.
  • TRUNCATE operation not rollback, It means truncated can not be returned.
  • TRUNCATE operation is not a safe.
TRUNCATE Table Table_name
TRUNCATE Table student_info

Different between Delete and Truncate Commands


DELETE
TRUNCATE
1
If we want to delete all the records from the table, then our SQL query is:

SQL> DELETE FROM table_name;
Whereas Truncate command is used to delete all records from the table. Our SQL query is:

SQL> TRUNCATE TABLE table_name;
2
DELETE statement with WHERE clause you can remove specific record in a table.
SQL> DELETE FROM table_name
                 WHERE condition;
Whereas TRUNCATE statement use for remove all record in a table.
3
DELETE statement is a DML (Data Manipulation Language) command.
Whereas TRUNCATE statement is a DDL (Data Definition Language) command.
4
Executed DELETE statement you can UNDO the changes and return back to deleted data.
Whereas executed TRUNCATE statement you can't return back.

SQL CHECK

SQL CHECK constraint check specified specific condition, which must evaluate to true for constraint to be satisfied.
SQL CHECK constraint must be specified as a logical expression that evaluated specific condition either TRUE or FALSE.
SQL CHECK constraint define at column level that allow only specified values for a column and Whereas define at table level that allow specified values as well as use other column value for checking specific condition.
 CREATE TABLE student_info(
  no NUMBER(3) PRIMARY KEY,
  stu_code VARCHAR(10) CHECK (stu_code like 'pr%'),
  name VARCHAR(30) CHECK ( name = upper(name) ),
 city VARCHAR(30) CHECK (city IN ('LUcknow','DELHI','KANPUR'))
 scholarship NUMBER(5) CHECK (scholarship BETWEEN 500 AND 20000)
);
We are create new student_info table name with following check constraints:
  • Values inserted into stu_code column must be start with the lower letter 'pr'.
  • Values inserted into name column must be capitalize.
  • Values inserted into city column only allow lucknow,kanpur,delhi as valid legitimate values.
  • Values inserted into scholarship column between 500 and 20000.

ADD CHECK constraint (ALTER TABLE)

ALTER TABLE statement to add CHECK constraint in existing table column.
Syntax :
ALTER TABLE table_name
 ADD CONSTRAINT check_constraint_name CHECK (column_name condition);
ALTER TABLE student_info ADD CONSTRAINT check_name CHECK (name = upper(name));

DROP CHECK constraint (ALTER TABLE)

ALTER TABLE statement to drop CHECK constraint in existing table column.
Syntax :
ALTER TABLE table_name
 DROP CONSTRAINT check_constraint_name;

Identifying Techniques for Designing Algorithms

Designing Algorithms and Measuring their Efficiency

Designing an algorithm for a given problem is a difficult intellectual exercise. This is because there is no systematic method for designing an algorithm. Moreover, there may be more than one algorithm to solve a given problem. Writing an effective algorithm for a new problem or writing a better algorithm for an already existing algorithm is art as well as science because it requires both, creativity and insight.

Identifying Techniques for Designing Algorithms

Although there is no systematic method for designing an algorithm, there are some well-known techniques that have proved to be quite useful in designing algorithms. The following two techniques are commonly used for designing algorithms:

  •  Divide and conquer approach 
  • Greedy approach 


 Divide and conquer approach 

The divide and conquer approach is an algorithm design technique that involves breaking down a problem recursively into sub problems until the sub problems become so small and trivial that they can be easily solved. The solutions to the sub problems are then combined to give a solution to the original problem. Divide and conquer is a powerful approach for solving conceptually difficult problems. It simply requires you to find a way of breaking the problem into sub problems, solving the trivial cases, and combining the solutions to the sub problems to solve the original problem. Divide and conquer often provides a natural way to design efficient algorithms. 


Greedy Approach

 The greedy approach is an algorithm design technique that selects the best possible option at a given time. Algorithms based on the greedy approach are used for solving optimization problems where you need to maximize profits or minimize costs under a given set of conditions.

Types of Data Structures


Types of Data Structures

Data structures can be classified under the following two categories:
Static: These are data structures whose size is fixed at compile time and does not grow or shrink at run time. An example of a static data structure is an array. Suppose you declare an array of size 50, but store only 5 elements in it. Therefore, the memory space allocated for the remaining 45 elements will be wasted. Similarly, if you have declared an array of size 50, but later, if you want to store 20 more elements, you will not be able to store these extra required elements because of the fixed size of an array.
 Dynamic: These are data structures whose size is not fixed at compile time and that can grow and shrink at run time to make the efficient use of memory. An example of a dynamic data structure will be a list of items for which memory is not allocated in advance. As and when items are added to the list, memory is allocated for those elements. Similarly, when items are removed from the list, memory allocated to those elements is deallocated. Such a list is called a linked list.


Arrays and linked lists are basic data structures that are used to implement other data structures, such as stacks, queues, and trees. 
An array is always a static data structure, and a linked list is always a dynamic data structure. However, the other data structures can be static or dynamic depending on whether they are implemented by using an array or a linked list.



Role of Data Structures

Role of Data Structures

Multiple algorithms can be designed to solve a particular problem. However, the algorithms may differ in the extent of efficiency to which they can solve the problem. In such a situation, an algorithm that provides maximum efficiency should be used for solving the problem. Here, efficiency means that the algorithm should work in minimal time and use minimal memory. One of the basic techniques for improving the efficiency of algorithms is to structure the data that they operate on
in such a way that the resulting operations can be efficiently performed. The way in which the various data elements are organized in memory, with respect to each other, is called a data structure. Data can be organized in many different ways. Therefore, you can create as many data structures as you want. However, there are some standard data structures that have proved useful over the years. These include arrays, linked lists, stacks, queues, and trees. You will learn more about these data structures in the subsequent chapters. All these data structures are designed to hold a collection of data items. However, the difference lies in the way in which the data items are arranged with respect to each other and the operations that they allow. As the data items are arranged in different ways, some data structures prove to be more efficient than others to solve a given problem. Suppose you have to write an algorithm that enables a printer to serve the requests of multiple users on a first- come-first-served basis. In this case, using a data structure that stores and retrieves the requests in the order of their arrival would be more efficient than a data structure that stores and retrieves the requests in a random order. In addition, to improve the efficiency of an algorithm, the use of appropriate data structures is required. It also allows you to overcome the following programming challenges:

  1. Simplifying complex problems 
  2. Creating standard and reusable code components
  3.  Creating programs that are easy to understand and maintain 
To understand the use of an appropriate data structure, which helps in simplifying the solution to a problem, let us consider an example where you have to find the maximum value in a set of 50 numbers. In such a case, you can either use 50 variables or use a data structure, such as an array of size 50, to store the numbers. When 50 different variables are used to store the numbers, the following algorithm can be used to determine the maximum value among the numbers: 


  • Accept 50 numbers and store them in num1, num2, num3, ..., num50.
  •  Set max = num1.
  •  If num2 > max then: max = num2 
  • If num3 > max then: max = num3 
  • If num4 > max then: max = num4 
  • . .
  •  If num50 > max then: max = num50
  •  Display max.
On the other hand, when an array of size 50 is used, the following algorithm can be used to determine the maximum value among the elements in an array:

  • Set max = num[0].
  •  Repeat step 3 varying i from 1 to 49. 
  • If num[i] > max then: max = num[i] 
  • Display max.

From the preceding two algorithms, it can be seen that the algorithm that is using an array manipulates memory more efficiently than the algorithm that is using 50 variables. In addition, the algorithm using an array involves few steps, and is therefore, easier to understand and implement as compared to the algorithm that uses 50 variables. Data structures also enable the creation of reusable code components. Suppose you have created a class to implement a data structure that stores and retrieves requests in the order of their arrival. Once the class is created, the same class can be used in several different applications that need to serve the requests of multiple users on a first-come-first-served basis. This means that a data structure, once implemented, can be used as a standard component to provide standard solutions to a specific set of problems. The use of standard components helps to simplify the maintenance process. This is because the standard components are time-tested, and therefore, do not need much maintenance.

Introducing Algorithms and Data Structures

Introducing Algorithms and Data Structure

Computer science is a field of study that solves a variety of problems by using computers. The problem to be solved could be as simple as performing the addition of two numbers, or it can be as complex as designing a robot capable of making decisions in a real-time environment. To solve a given problem by using computers, you need to design an algorithm. The nature of an algorithm often depends closely on the nature of the data on which the algorithm works. Therefore, the study of algorithms also involves the study of the data structures that the algorithms work on.


Explore the Role of Algorithms and Data Structures in Problem Solving

Problem solving is an essential part of every scientific discipline. In today’s world, computers are widely used to solve problems pertaining to various domains, such as banking, commerce, medicine, manufacturing, and transport. To solve a given problem by using a computer, you need to write a program. A program consists of two components, algorithm and data structure. Different algorithms can be used to solve the same problem. Similarly, different types of data structures can be used to represent a problem in a computer. To solve the problem in an efficient manner, you need to select a combination of algorithms and data structures that provide maximum efficiency

Role of Algorithms

The word, algorithm, is derived from the name of the Persian mathematician, Al Khwarizmi. An algorithm can be defined as a step-by-step procedure for solving a problem. It helps the user to get the correct result with a finite number of steps. Consider the
following step-by-step procedure to display the first 10 natural numbers:

  1. Set the value of counter to 1. 
  2. Display counter. 
  3. Increment counter by 1.
  4.  If counter <= 10, go to step 2. 

Please contact me for  website and desktop application

Gmail Id:Prakashmishra.niit@gmail.com
Contect number:9580538062

Tuesday, November 10, 2015

JAVA Program Exercises

Exercises                                                                                    
1.    10,                      20, 30, 40, 50.....................100
2.    0, 5, 10, 15, 20…………………250
3.    100, 90, 80, 70…………………0
4.    1, 2, 4, 8, 16…………………….n
5.    4, 8, 12, 16…………………..….n
6.    12, 24, 36………………………40 terms
7.    2, 4, 8, 16, ……………………..20 terms
8.    100, 97, 94, 91, ………………upto 10
9.    1, 8, 27, 64, ……………………upto 20 terms
10.   3, 6, 9, 12, ……………………..30
11.  1, 5, 25, 625, …………….…….n
12.  1, 11, 121, 1331, 14641….……n
13.  1, 10, 100, 1000……………..…n
14.  1, 4, 5, 9, 14, 23, 37, 60…….…n
15.  1! + 2! + 3! + 4! + ……………..n!
16.  1 + 3 + 5 + 7 + …………………n
17.  2 + 4 + 6 + 8…………………....n
18.  1 + 7 + 13 + 19………………….n
19.   1 * 3 * 5 * 7 * …………………...n
20.  0 + 3 + 8 + 15 + ……………….upto 15 terms
21.  2 + 5 + 10 + 17 + …………….. upto 25 terms
22.  1+ (1+2) + (1+2+3) + (1+2+3+4) + ………(1+2+3…10)
23.  15, 25, 35, 45, 55,……………….…n5
24.   1 + 22 + 33 + 44 + 55 +..…………nn    
25.   1 + x  + x2 + x3 + x4 + x5 +………xn  



Monday, November 9, 2015

JAVA program (IF-ELSE)

IF-ELSE PROGRAM IN JAVA

  1. WAP to enter age and check if it greater than equal to 18 then print “Eligible to vote” else print  “Not eligible to vote”.

import java.util.*;
class Age
{
  public static void main()
  {
     Scanner sc=new Scanner(System.in);
      int age;
      System.out.println(“Enter the age :”);
      age=sc.nextInt( );
     
      if(age>=18)
            System.out.println(“Eligible to vote”);
      else
            System.out.println(“Not eligible to vote”);
   }

}


b.WAP to check whether a number is odd or even.

import java.util.*;
class EvenOdd
{
  public static void main()
  {
     Scanner sc=new Scanner(System.in);
      int num;

      System.out.println(“Enter the number :”);
      num=sc.nextInt( );
     
      if(num%2= =0)
            System.out.println(“Number is Even”);
      else
            System.out.println(“Number is Odd”);
   }
}

  1. WAP to check whether a number is Positive or Negative.

import java.util.*;
class PosNeg
{
  public static void main()
  {
     Scanner sc=new Scanner(System.in);
     int num;

      System.out.println(“Enter the number :”);
      num=sc.nextInt( );
      if(num>0)
            System.out.println(“Number is Positive”);
      else
            System.out.println(“Number is Negative”);
   }
}


  1. WAP to enter year and check whether it is leap year or not.

import java.util.*;
class LeapYear
{
  public static void main()
  {
     Scanner sc=new Scanner(System.in);
      int year;

      System.out.println(“Enter the year :”);
      year=sc.nextInt( );
      if(year%4= =0 && year%100!=0 || year%400==0)
            System.out.println(“It is Leap Year”);
      else
            System.out.println(“It is not a Leap Year”);
   }
}


  1. WAP to enter character and check whether it is a vowel or not.

import java.util.*;
class Vowel
{
  public static void main()
  {
     Scanner sc=new Scanner(System.in);

      char ch;
      System.out.println(“Enter the character”);
      ch=sc.next().charAt(0);
      if(ch==’a’|| ch==’e’|| ch==’i’|| ch==’o’|| ch==’u’)
            System.out.println(“It is a vowel”);
      else
            System.out.println(“It is not a vowel”);
   }
}


  1. WAP to calculate the commissutiln of a salesman which is 10% if the sale made by the employee is above 10,000.

import java.util.*;
class Comm
{
  public static void main()
  {
     Scanner sc=new Scanner(System.in);
      double sales,comm;

      System.out.println (“Enter the sales :”);
      sales=sc.nextDouble ();

      if(sales >=10000)
               comm=(10/100)*sales;                   
     
      System.out.println(“Commissutiln is :”+comm);
      }    
   }


  1. WAP to calculate the commissutiln of a salesman which is 10% if the sale made by the employee is above 10,000 and 5% if sales is below it.

import java.util.*;
class Comm
{
  public static void main( )
  {
     Scanner sc=new Scanner(System.in);
      double sales,comm;

      System.out.println(“Enter the sales :”);
      sales=Sc.nextDouble( );

      if(sales >=10000)
         comm= 0.10 * sales;                 
      else
        comm= 0.05*sales;                    

      System.out.println(“Commissutiln is  : ”+comm);
     }
   }





  1. WAP to find the grade of the students depending upon the marks given as below :
Marks >= 90                                         Grade    ‘A’
Marks >= 80   and  Marks < 90              Grade    ‘B’
Marks >= 70   and  Marks < 80              Grade    ‘C’
Marks >= 60   and  Marks < 70              Grade    ‘D’
Marks < 60                                           Grade    ‘F’

import java.util.*;
class Grade
{
  public static void main( )
  {
      Scanner sc=new Scanner(System.in);
      int marks;
      char grade;

      System.out.println(“Enter the marks :”);
      marks=sc.nextInt( );
      if(marks >=90)
         grade=’A’;                      
      else if(marks >=80 && marks <90)
        grade=’B’;                       
      else if(marks >=70 && marks <80)
        grade=’C’;
      else if(marks >=60 && marks <70)
        grade=’D’;          
      else
        grade=’F’;           
           
   System.out.println(“Grade is :”+ grade);
  }
}


  1. WAP to enter any two numbers and find the greater of the two.

import java.util.*;
class Greater
{
  public static void main()
  {
     Scanner sc=new Scanner(System.in);
     int a,b;
     System.out.println(“Enter number”);
     a=sc.nextInt( );
     System.out.println(“Enter number”);
     b=sc.nextInt( );
     if(a>b)
       System.out.println(“a is greater”+a);
     else
       System.out.println(“b is greater”+b);
   }
 }


  1.  WAP to enter any three numbers and find the greatest of the three.

import java.util.*;
class Greatest
{
  public static void main( )
  {
         Scanner sc=new Scanner(System.in);
                int a,b,c;
    System.out.println(“Enter number”);
    a=sc.nextInt( );
    System.out.println(“Enter number”);
    b=sc.nextInt( );
    System.out.println(“Enter number”);
    c=sc.nextInt( );
   
    if(a>b && a>c)
               System.out.println(“a is greater”+ a);
          if(b>a && b>c)
               System.out.println(“b is greater”+ b);
          if(c>a && c>b)
               System.out.println(“c is greater”+ c);
         }
      }





  1.   A library charges a fine for books returned late. Following are the fines.
  First 5 days                :   40 paise per day
  6 to 10 days                :   65 paise per day
  Above 10 days            :   80 paise per day
              WAP to calculate the fine assuming that a book is returned ‘n’ days late.

  import java.util.*;
  class fine
  {
     public static void main()
     {
       Scanner br=new Scanner(System.in);
       int day;
       double fine;
    
       System.out.println("Enter number of days: ");   
       day=sc.nextInt();
       if(day>=1 && day<=5)
           fine=day * 0.40;
       else if(day>=6 && day<=10)
           fine=(5 * 0.40)+((day-5) * 0.65 );
       else
           fine=(5 * 0.40) + (5 * 0.65) + ((day-10) * 0.80);
     
      System.out.println("Fine for "+day+" days is Rs."+fine);   
     }
   }


  1.   WAP to compute charges for sending parcels where the charges are as follows:
For the first 1 kg Rs.15.00.For additutilnal weight for every 500gm or fractutiln there of Rs. 8.00.

import java.util.*;
class Parcels
{
  public static void main( )
  {
    Scanner sc=new Scanner(System.in);
                   int w,cost,b;
                    double d;
                    System.out.println("Enter weight : ");   
                     w=sc.nextInt(br.readLine());
                     if(w<=1000)
                           cost=15;
                     else
                    {
                           b=w-1000;
                           d=b/500;
                           if(d==(int)d)
                              cost=15+((int)d*8);
                           else  
                              cost=15+(8*((int)d+1));
                      }
                      System.out.println("Cost is Rs."+cost);   
                   }
                 }


  1. WAP to calculate the telephone bill amount as per instructutilns.
 For 1st 100 calls – Rs. 100
 For additutilnal 50 calls – Rs. 2 per call
 For calls > 150 – Rs. 2.50 per call

import java.util.*;
class Bill
{
  public static void main( )
  {
Scanner sc=new Scanner(System.in);
int call;
double bill;

System.out.println(“Enter number of calls :”);
call=sc.nextInt( );

if(call<=100)
   bill=100;
else if(call>100  && call<=150)
   bill=100 + (call-100)*2;
else
   bill=100 + (50*2) + ((call-150) * 2.5);
    }
 }



  1. WAP to enter any character and check if it is a character, digit or a special character.

import java.util.*;
class Check
{
  public static void main( )
  {
   Scanner sc=new Scanner(System.in);
char ch;
System.out.println(“Enter any character :”);
ch=sc.next( ).charAt(0);
int c=(int)ch;

if(c>=65 && ch<=91 || c>=97 && c<=122)
   System.out.println(“It is a character”);

else if(c>=48 && c<=56)
   System.out.println(“It is a digit”);
else
   System.out.println(“It is a special character”);
             }
            }

  1. WAP to find the age in years, months and days by inputting the date of birth and the current date.

import java.util.*;
class Check
{
  public static void main( )
  {
   Scanner sc=new Scanner(System.in);
Int a,b;
System.out.print(“Enter date of birth”);
a=sc.nextInt( );
System.out.print(“Enter current date”);
b=sc.nextInt( );

if(cd>dd)
d=cd-dd;
else
{
cd=cd+30;
cm=cm-1;
d=cd-dd;
}
If(cm>dm)
m=cm-dm;
else
{
cm=cm+12;
cy=cy-1;
m=cm-dm;
}
System.out.print(y+”yrs”+m+”months”+d+”days”);
}
}


  1. WAP to find the grade of the students depending upon the marks given as below :
Marks >= 90                                                   Grade    ‘A’
Marks >= 80   and  Marks < 90                    Grade    ‘B’
Marks >= 70   and  Marks < 80                    Grade    ‘C’
Marks >= 60   and  Marks < 70                    Grade    ‘D’
Marks < 60                                                     Grade    ‘F’





2.    A no. of answer script with scores 0 to 99 awarded after marking are to be searched for finding no. of answer scripts marked:                                                            [ Year 1998]
1)  Percentage of candidates getting 85 and above
2)  Percentage of candidates getting 39 or less

import java.util.*;
class Grade
{
  public static void main( )
  {
      Scanner sc=new Scanner(System.in);
int  n ;
String y;
double p1,p2;

System.out.print(“Enter no. of scripts”);
n=sc.nextInt( );

for(i=1;i<=n;i++)
{
  System.out.print(“Script” + i + ”is marked”);
   y=sc.next( );
   if(y.equals(“y”);
   {
     c=c+1;
     System.out.print(“Enter score”);
     s=Sc.nextInt( );

     if(s>85)
        a++;
     if(s<=39)
        b++;
   }
 }
p1= (a/c) *100;
p2= (b/c) *100;

System.out.print(“No. of scripts marked”+c);
System.out.print(“Percentage of candidate getting 85 and above”+p1);
System.out.print(“Percentage of candidate getting 39 or less”+p2);
   }
 }
  1. WAP to input age and distance in km and print the corresponding fare.
Age                 Distance                     Fare
Below 10        below 10                     5
10-50                                    10
Above 50                    20
                        10-50               below 10                     15
                                                10-50                           25
                                                Above 50                    35
                        Above 50        below 10                     25
10-50                                    35
Above 50                    45



import java.util.*;
class Grade
{
  public static void main( )
  {
Scanner sc=new Scanner(System.in);
int age,dis,fare;

System.out.println(“Enter age”);
age=Sc.nextInt( );
System.out.println(“Enter distance”);
dis=Sc.nextInt( );

if(age<10)
{
  if(dis<10)
   fare=5;
     else  if(dis>=10 && dis<=50)
   fare=10;
  else
   fare=20;
}
else if(age>=10 && age<=50)
 {
   if(dis<10)
    fare=15;
   else  if(dis>=10 && dis<=50)
    fare=25;
  else
   fare=35;
}
else
{
    if(dis<10)
   fare=35;
 else  if(dis>=10 && dis<50)
   fare=35;
 else  if(dis>50)
   fare=45;
 }
}




  1.  A cloth showroom has announced the following festival discounts on the purchase of items based on the total cost of the items purchased.                                      [Year 2006]
     Total Cost                  Discount
Less than Rs. 2000               5%
Rs. 2000 to Rs. 5000             25%
Rs. 5000 to Rs. 10,000          35%
Above 10,000                         50%

import java.util.*;
class Discount
{
  public static void main( )
  {
Scanner sc=new Scanner(System.in);
double cost,d;

if(cost<=2000)
   d=(5/100)*cost;
else  if(cost>2000 && cost<=5000)
  d=(25/100)*cost;
else  if(cost>5000 && cost<=10000)
  d=(35/100)*cost;
else
  d=(50/100)*cost;
System.out.print(“Total amt is”+(cost+d));
   }
 }


  1.  Given three numbers A,B,C, WAP to write their values in descending order.
  If A=7,B=4, C=10, print 10, 7, 4

import java.util.*;
class Desc
{
  public static void main( )
  {
Scanner sc=new Scanner(System.in);
int a,b,c;

System.out.print(“Enter number”);
a=sc.nextInt( );
System.out.print(“Enter number”);
                 b=sc.nextInt( );
System.out.print(“enter number”);
c=sc.nextInt( );

if(a>b && a>c)
{
  System.out.println(a);
  if(b>c)
  {
   System.out.println(b);
   System.out.println(c);
  }
  else
  {
   System.out.println(c);
   System.out.println(b);
  }
}

else if(b>a && b>c)
{
    System.out.println(b);
    if(a>c)
    {
     System.out.println(a);
     System.out.println(c);
    }
    else
    {
     System.out.println(c);
     System.out.println(a);
    }
}

else if(c>a && c>b)
{
  System.out.println(c);
  if(a>b)
  {
    System.out.println(a);
    System.out.println(b);
  }
  else
  {
   System.out.println(b);
   System.out.println(a);
  }
 }
 }
}