C C++ Java Javascrip Android Obooko Tech0019
C C++ Java Javascrip Android Obooko Tech0019
C C++ Java Javascrip Android Obooko Tech0019
2
Understanding C, C++, Java, Javascript & Android for dummies
An Comprehensive Guide For All Programmers
(Start programming in C, C++, Java , Javascript & Android – no experience required…)
Manjunath R
[email protected] , [email protected]
: Linus Torvalds
Abstract: This BOOK provides a precise description of the open source and Linux-based operating system for
mobile devices such as smartphones and tablet computers i.e., the world’s most popular operating system-- the
Android which was developed by the Open Handset Alliance, led by Google, and other companies – and has now
garnered the interest of a million smartphone users -- and also highlights some basic knowledge of artificial
intelligence formal constructed programming languages (like C, C++, Java & XML) designed to interact with the
hardware in a more powerful way and to communicate instructions to a machine, particularly an electronic device
which is capable of receiving information (data) in a particular form and of performing a sequence of operations in
accordance with a predetermined but variable set of procedural instructions (program) to produce a result in the form
of information or signals. If you read this book in a public place (on a commuter train, at the beach, or on the dance
floor at the Restaurants, for example), you can read proudly, with a chip on your shoulder and with your head held
high. C, C++, Java, Javascript and Android is hot stuff, and you’re cool because you’re reading about it. If you are
just learning what kind of animals C, C++, Java, Javascript and Android are, this BOOK will make an excellent
companion to any tutorial and serve as a source of knowledge to your specific questions. And, by reading this
BOOK, you’ll have a broad, basic knowledge of C, C++, Java, Javascript [scripting language used in millions of
Web pages such as Internet Explorer, Firefox, Chrome, Opera, and Safari] and Android. This article is for all
programmers, whether you are a novice or an experienced pro. The beginner will find its carefully paced discussions
and many examples especially helpful. Of course those who have already familiar with programming are likely to
derive more benefits from this book. After completing this book you will find yourself at a moderate level of
expertise in C, C++, Java, Javascript and Android programming from where you can take yourself to next levels.
Keywords: C; C++; Java; XML; Android programming; Language; Javascript; HTML; LINUX.
“What Will Understanding C, C++, Java, Javascript (the world's most popular case-sensitive object oriented
scripting language introduced to create dynamic web pages) & ANDROID (which run on 53 percent of all
smartphones in the United States and on 80 percent of all smartphones worldwide) Do for Me?”
C, C++ & Java programs are commonly referred to as software and this software is essential to a fast and obedient,
smart processing unit called computer because it controls everything the computer does (i.e., performance of a suite
of computer operations and storage of the results in its memory can be manipulated by using notable programming
languages in existence such as C, C++ & Java). Contemplating Android application development is a great choice as
per current market scenario and the importance of Android application development for businesses of today cannot
be emphasized on enough. Android is everywhere. In a study that spans the Americas, Europe, Asia, and the Middle
East, GlobalWebIndex reports that Android tablets outnumber iPads by more than 34 million. More than a million
apps are available for download at the digital distribution platform operated by Google (double the number of apps
that were available in the last few years). And more than 9 million developers write code using Java, XML-- the
3
languages that empowers an array of software intended for mobile devices that features an operating system, core
applications and middleware. Nowadays, website is considered as the window to the world of internet and no
company can think about making its business and marketing requirements big without having its very own website
to get in touch with millions of web surfers all over the world including their potential customer and the global client
base and moreover website serves as the primary step towards having better business sensibility and drives the
company to market the services and products they offer. Javascript is a full-fledged dynamic scripting programming
language, integrated with HTML document, to provide dynamic interactivity on websites (without which there is no
fastest and most efficient way to deliver the content of the website).
ENIAC was the world’s first completely electronic computer, conceived and constructed on Penn’s campus in 1946.
Operating system: A well-defined set of instructions in the form of statements that is installed into the computer
which provide instructions for computer how to operate (i.e., how to receive the raw data through input devices (like
key board, mouse etc.), process the input data through processing device called CPU (Central Processing Unit) and
store the processed data (in information storage devices like hard disks) and display the processed data through
output devices (like monitor, printer etc.)). A well-defined instruction is called a code and a well-defined set of
instructions constitute a program (i.e., compilation of codes gives a program). For example: word is a code and a
paragraph is a program (i.e., compilation of words gives a paragraph).
Examples of Operating system (a well-defined set of instructions that is installed into the computer which provide
instructions for computer how to operate) are: DOS ( Disk operating system developed by Bill Gates and Paul Allen
in 1980 for IBM PCs), Linux (operating system developed by Linus Torvalds at the University of Helsinki with the
assistance of developers around the world), Windows NT, 95 & 2000 (developed by Microsoft corporation for PC),
UNIX (developed by AT&T Bell Laboratories, Murray Hill, New Jersey) etc.
II
Drivers: A well-defined set of instructions (what we call programs or software) that is installed into computer and
stored in the form of files in the computer that allows the computer to communicate with its hardware components
(i.e., hardware components like mouse, key board, printer etc.). Without drivers, the computer cannot communicate
with its hardware components – as a result a mouse, keyboard, or a printer won’t work properly.
III
Server: If we type a request (a request to search information about computer) in the search engine websites (like
Google or Firefox) in the web browser ‒ the request is sent from the browser to the server ‒ a system that acts like a
data center from where the required information is taken and sent to the browser and is displayed in the web
browser. Examples of server are: IIS (Internet Information server LATTER NAMED Internet Information service) ‒
a web server developed by Microsoft corporation, Apache HTTP (HTTP mean Hyper Text Transfer Protocol) ‒ a
web server developed by Robert McCool at the national center for supercomputing applications (university of
Illinois, Urbana-Champaign) – to provide web hosting service.
IV
Hosting: Host is a system that contains information and this information can be accessed by computer users by a
means of internet. This process is called hosting.
V
IP address or Internet Protocol address: Just like every house on a street has a postal address which helps the post
man to find that house on a street, every computer connected to internet has an Internet Protocol address or IP
address which helps the other computers to find that computer on the network.
4
Suppose A B, C, D, E, F and G ‒ are the computers connected to each other by means of internet (i.e., they are on
the network). If computer A has not assigned any IP address, then users at computers B, C, D, E, F and G cannot
send any email or other data to user at computer A or user at computer A cannot receive any email or other data
from the users at computers B, C, D, E, F and G by a means of internet.
Amazon organization is assigned an IP address IP A and Google organization is assigned an IP address IPG. And the
systems (1, 2, 3, 4, 5…..etc.) within the Amazon or the Google organization are assigned an IP addresses IP 1, IP2,
IP3 … etc.
IPA and IPG imply public IP addresses
IP1, IP2, IP3 … etc. implies private IP addresses
Which means: Public IP address is used for external communication (i.e., used for the communication between the
Amazon and the Google organization) and Private IP address is used for internal communication (i.e., used for
communication between the systems within the Amazon or the Google organization).
VI
Domain name: If we type www.google.com (which is called the domain name) in the browser, then the domain
name is sent to DNS (domain name system) where the domain namewww.google.com is converted to IP address
74.125.224.72 (because website / web pages are only identified by their IP address in the server) and this IP Address
is sent to the web server (a system that acts like a data center from where the required information (i.e., web page of
google.com) is taken and sent to the browser and the www.google.com web page is displayed in the web browser).
If you type the IP address in the browser, then DNS is not required. For human convenience (difficult remember
numbers, for example: www.google.com is domain name, IP address is 74.125.224.72. Because it is difficult to
remember 74.125.224.72 so www.google.com is preferred).
VII
ASP.NET:
ASP → Active Server Page
ASP.NET (Active Server Page Network Enabled Technology) is a technology developed by Microsoft corporation
using the languages -- C#, Visual Basic. Net, J script & J# -- to build dynamic web pages / websites and web
applications.
Dynamic web page contains information (say date, month or year or time zone of the day) change automatically
daily without a developer editing its source codes while static web page contains information (say date, month or
year or time zone of the day) cannot change automatically daily without a developer editing its source codes.
Virtual Memory: If the RAM (i.e., Random Access Memory) is full and it is running out of space available for
storage of further information and there is no access to store further information, the idea of extending memory by
using disk is called virtual memory (i.e., the further information is stored in disk and retrieved when required). This
process is called paging or swapping.
VIII
C
5
A high level language (which uses alphabets, digits, punctuations and some special symbols and cannot be executed
directly without being converted into machine level language (the language which uses only 0 and 1)) developed by
a man named Dennis Ritchie (in 1970s at Bell Telephone laboratories (now named AT & T Bell laboratories),
Murray Hill, New Jersey, using the two early programming languages-- Basic combined programming language and
BASIC (Beginner's All-purpose Symbolic Instruction Code) language), used in the development of operating
systems like LINUX, UNIX, because of its reliability, simplicity and easy to understand, easy to use, write, modify
and debug and quick to learn.
Process of C program execution: A C program:
#include<stdio.h>
main()
{
printf("Hello, crazy world!");
}
is written in C editor and is saved as source program and this source program is sent to the C compiler where the
source program is compiled (i.e., the program is entirely read and translated to instructions the computer can
understand i.e., machine understandable/ readable language i.e., to machine code sequence of 0’s and 1’s). If the C
compiler finds any error during compilation, it provides information about the error to the user. The programmer has
to review code and check for the solution. And if there are no errors the translated program is stored in computers
main memory as object file and the program is executed and
Hello, crazy world!
is displayed on the screen. C is case sensitive language: only lower case letters (or small letters) must be used.
Capital letters (or upper case letters) must be avoided to prevent the display of error on the screen (For example: If
the statement PRINTF("Hello, crazy world!"); is written instead of printf("Hello, crazy world!"); or MAIN() is
written instead of main(), compilation Error will be displayed on the screen). And if we forget to end each statement
within the curly braces{} or each statement within the body of the main function
main()
{
} with a semicolon (;), then the compilation Error will be displayed on the screen. There should be no space between
main and the parentheses () and no space inside the parentheses () to prevent the display of compilation error on the
screen.
#include <stdio.h>→if we type a program (a well-defined set of instructions in the form of statements) in C editor,
(as said earlier) the program is saved as source program and this source program is sent to the C compiler where the
source program is compiled i.e., it is translated into machine level language i.e., into a machine code sequence of 0’s
and 1’s (because computer can understand only machine level language). The statement #include<stdio.h> tells the
complier to include the text from the file stdio.h (which is already present in the operating system) before it
translates or complies the program into a sequence of 0’s and 1’s. stdio means standard input output and stdio.h
means standard input output header file (stdio.h comprises standard input output functions like scanf, printf etc. —
note: scanf is an input function and printf is an output function and it is included into the C program by writing the
statement #include <stdio.h>). #include tell the compiler to include the contents of the file stdio.h before
compilation. If a program is written without the statement #include<stdio.h>, then the C compiler can’t compile and
a compilation error is displayed on the screen.
Note: We can also write #include "stdio.h" instead of #include <stdio.h> but sometimes compiler will flag error
message. So the statement #include <stdio.h> is generally preferred.
main() →After the compilation of the source program, the translated (or the complied) program is stored in the
computer’s memory as object file and the program is executed. The program begins its execution with the function
main() (which is called the user defined function (function defined by the user) – the main function -- the entry point
of the program execution i.e., the function from where the execution of C program begins) . The left curly brace “{”
implies the beginning of the main function and the right curly brace “}”implies the end of the main function
6
main() → main function
main()
{
} → body of the main function within which the sequence of instructions in the form of statements i.e., the program
is written and executed.
Note: if a program begins its execution with main function “main()”, it takes the control of the computer from the
operating system. And after the complete execution of the program, the execution is terminated and the function
main() returns back the control to the operating system. Semicolon: program is a well-defined set of instructions and
each well-defined instruction (in the form of a statement) is ended by a semicolon (which is C language punctuation
— like a period in English i.e., in an English paragraph each sentence is ended by a full stop which tells that one
sentence ends and another begins, semicolon implies that one instruction (or statement) ends and another begins).
printf → output function of the C language which make provision to print the output on the screen. The letter f in the
word printf stands for formatted.
The sentence / text Hello, crazy world! should be enclosed by the double quotation marks (" ") and should be
written inside the parentheses of the printf function i.e.,
printf("Hello, crazy world!")
otherwise the compilation error will be displayed on the screen.
The statement
printf("Hello, crazy world!");
make provision to display the output:
Hello, crazy world!
on the screen.
Note: if “ ” is used instead of " ", Error will be displayed on the screen
The statement printf("Hello, crazy world!"); will not display any error on the screen.
The statement printf(“Hello, crazy world!”); will display error on the screen.
Past few years back, the statement return(0); was included in the body of the main function i.e.,
{
printf("Hello, crazy world!");
return(0);
}
But now due to the advancement of technology and emergence of advanced online compilers like CodeChef
(www.codechef.com/)
&
Coding Ground – TutorialsPoint (www.tutorialspoint.com/codingground.htm)
-- without the statement return(0); the program is compiled and executed without flag of any error on the screen.
However, as the execution encounters the statement return (0); the execution stops and the main function ends at “}”
and the main function returns back the control to the operating system.
Note:
7
return(-2);
or
return;
there will be no change in the output on the screen (and no error will be flagged or displayed on the screen) i.e., for
the programs
(a) #include<stdio.h>
main()
{
printf("Hello, crazy world!");
return 0;
}
(b) #include<stdio.h>
main()
{
printf("Hello, crazy world!");
return (1);
}
(c) #include<stdio.h>
main()
{
printf("Hello, crazy world!");
return (-2);
}
(d) #include<stdio.h>
main()
{
printf("Hello, crazy world!");
return;
}
Program 1.1
#include<stdio.h>
main()
{
printf("hello Bill Gates");
}
8
The output on the screen:
hello Bill Gates
Even if
main(void) is written instead of main()
int main is written instead of main()
void main is written instead of main()
main(computer) is written instead of main()
main(comp2016) is written instead of main()
No error will be displayed on the screen.
hello Bill Gates will be outputted on the screen.
But if
main(2016comp) is written instead of main(comp2016)
Error will flagged on the console screen.
Program 1.2
C program to print
*
*****
*****
*****
*****
on screen
#include<stdio.h>
main()
{
printf("\n * ");
printf("\n ***** ");
printf("\n ***** ");
printf("\n ***** ");
printf("\n ***** ");
}
9
(a)
*
****
*******
****
*
(b)
****************
**
* Hello World! *
**
****************
(c)
Answers:
#include<stdio.h>
main()
{
printf("\n * ");
printf("\n **** ");
printf("\n ******* ");
printf("\n **** ");
printf("\n * ");
}
#include<stdio.h>
main()
{
printf("\n **************** ");
printf("\n ** ");
printf("\n * Hello World! * ");
printf("\n ** ");
printf("\n **************** ");
}
10
#include<stdio.h>
main()
{
printf("\n Braces come in pairs!");
printf("\n Comments come in pairs!");
printf("\n All statements end with a semicolon!");
printf("\n Spaces are optional!");
printf("\n Must have a main function!");
printf("\n C is done mostly in lowercase. It’s a case-sensitive language");
}
Program 1.3
#include<stdio.h>
main()
{
int r, area;
r = 2;
area = 4 * 3.14 * r * r;
printf("The area of the circle = %d", area);
}
11
In the statement
printf("The area of the circle = %d", area);
format string %d indicates that the integer value to be displayed at that point in the string i.e., after the statement The
area of the circle = enclosed by double quotes needs to be taken from a variable area and %d tells the printf function
to print an integer. Since the statement "The area of the circle = %d" is followed by , area -- %d tells the printf
function to print an integer which is area.
The area of the circle is 50. 24 (for r = 2) but The area of the circle = 50 is displayed on the screen because data type
int is used instead of float and format specifier %d is used instead of %f.
(floating point variable means fractional variable or decimal number (for example: 1.5, 2.5, 3.5, 4.7…etc.) whereas
integer means non-fractional variable or whole number (for example: 1, 2, 3, 4…etc.))
data type float is used instead of int (and format string %f is used instead of %d) because if the data type int is used
instead of float then the result will not be clearly outputted i.e., instead of 50.24 the computer displays only 50.
If the statement
printf("The area of the circle = %2f", area);
is written instead of the statement printf("The area of the circle = %f", area);
Then the output on the screen is:
The area of the circle = 50.24
i.e., the statement
printf("The area of the circle = %f", area); yields the output:
The area of the circle = 50.24
whereas the statement
12
printf("The area of the circle = %2f", area); yields the output:
The area of the circle = 50.24
If you want to supply the value for r through the key board, then the statement
r =2;
should be replaced by the statements
printf("Enter any number:");
scanf("%d", &r);
i.e., the program is rewritten as:
#include<stdio.h>
main()
{
float r, area;
printf("Enter any number:");
scanf("%d", &r);
area = 4 * 3.14 * r * r;
printf("The area of the circle = %f", area);
}
The output on the screen:
Enter any number:
If you enter the number 2
The area of the circle = 50.24 will be outputted on the screen.
The statement printf("Enter any number:"); make provision to print the sentence / text
Enter any number:
on the screen.
& imply the address and &r imply the address of r in the computer memory. The statement float r, area; imply that
we are creating the float variables r and area and these variables are stored in the computer memory and they are
assigned an address to locate their position in the computer memory (like houses in a street are assigned an address
to locate their position in the street). The statement scanf("%d", &r); make provision to enter a number for r through
the keyboard and store the number entered for r through the keyboard in the address of r in the computer memory.
Format string %d in the statement scanf("%d", &r); tells the input function scanf to read the number entered through
the keyboard (which is a integer) and since " %d" is followed by , &r -- %d tells the scanf function to read the
integer entered through the keyboard for r and store it in the address of r in the computer memory (i.e., store the
number in &r).
Note: Like the letter f in printf(), the letter f in scanf() means formatted.
printf and scanf function are not part of C language but they are part of standard input output file i.e., (stdio.h file) so
the statement #include<stdio.h> should be included in the C program otherwise printf and scanf function will not
work and the compilation error will be displayed on the screen.
If you write area = 4 * 3.14 * r ^ 2; instead of area = 4 * 3.14 * r * r; (where r ^ 2 implies r to the power of 2 or r
square), then the compilation error is displayed on the screen because unlike other high level languages – there is no
operator for performing exponentiation operation i.e., there is no operator for performing r ^ 2 operation so the
statement area = 4 * 3.14 * r ^ 2; is invalid.
13
Note: As told earlier: when you enter an integer for x through the keyboard, this integer will be stored in the
computer memory. If you yearn to know the storage size of the integer in computer memory (i.e., space occupied by
the entered integer in the computer memory), you need to appeal to the following program:
#include <stdio.h>
main()
{
int x;
x=10;
printf("size of x = %d", sizeof(x));
}
The output on the screen:
size of x = 4
i.e., integer entered for x i.e., 10 has occupied a space of 4 bytes in the computer memory.
Answer:
#include<stdio.h>
main()
{
float r, area;
r = 2.5;
circumference = 3.14 * r * r;
printf("The circumference of the circle = %f", circumference);
}
Write a program to print the area of the rectangle (given l = 2.5 and b = 3)
Answer:
#include<stdio.h>
main()
{
float l, b, area;
l = 2.5;
b = 3;
area = 1*b;
printf("The area of the rectangle = %f", area);
}
(a)
#include<stdio.h>
14
main()
{
float r, area;
printf("Enter any number:");
scanf("%d, &r");
area = 4 * 3.14 * r * r;
printf("The area of the circle = %f"; area);
}
(b)
#include<stdio.h>
main()
{
int l, area;
printf("Enter any number:");
scanf("%d"; &r);
area = l × l;
print("The area of the square = %f", area);
}
Program 1.3
C program to find the sum of two numbers
#include<stdio.h>
main()
{
int a, b, sum;
a=1;
b=2;
sum = a + b;
printf("the sum of a and b = %d", sum);
}
The output on the screen:
the sum of a and b = 3
If you want to assign the floating point values i.e., fractional numbers for a & b (i.e., 1.5 for a & 2.6 for b) through
the keyboard, then the statement int a, b, sum; should be replaced by the statement float a, b, sum;
15
and the statement
printf("the sum of a and b = %d", sum); should be replaced by the statement
printf("the sum of a and b = %f", sum);
i.e.,
#include<stdio.h>
main()
{
float a, b, sum;
a=1.5;
b=2.6;
sum = a + b;
printf("the sum of a and b = %f", sum);
}
The output on the screen:
the sum of a and b = 4.1
The statement
printf("the sum of a and b = %f", sum);
make provision to print the output:
the sum of a and b = 4.1
In the statement
printf("the sum of a and b = %f", sum);
format string %f tells the printf function to print an floating point value which is sum.
Since a = 1.5 and b = 2.6 therefore:
the sum of a and b = 1.5 + 2.6 = 4.1 which is outputted on the screen.
If the statement printf("the sum of a and b = %f", sum); is replaced by the statement
printf("the sum of a and b = %f, sum");
Then output on the screen is:
the sum of a and b = %f, sum
And if the statement printf("the sum of a and b = %f", sum); is omitted from the C program, then the program will
be successfully executed but there will be no display of the output on the screen.
If you want to supply the values for a and b through the key board, then the statements
a=1.5;
b=2.6;
should be replaced by the statements
printf("Enter any two numbers:");
scanf("%f %f", &a, &b);
i.e., the program is rewritten as:
#include<stdio.h>
main()
{
float a, b, sum;
printf("Enter any two numbers:");
16
scanf("%f %f", &a, &b);
sum = a+ b;
printf("the sum of a and b = %f", sum);
}
The output on the screen:
Enter any two numbers:
If you enter two numbers 2.9 & 3.6
the sum of a and b = 6.5 will be outputted on the screen.
As said earlier:
ampersand (“&”) imply the address and &a and &b imply the addresses of the created float variables a and b stored
in the computer memory i.e., when we enter a number for a and b through the keyboard, these numbers are read by
scanf function and they are stored in the computer memory (i.e., the number entered for a is stored in the address of
a (i.e., stored in &a) and the number entered for b is stored in the address of b (i.e., stored in &b)).
Note:
The statement printf("Enter any two numbers:"); make provision to print
Enter any two numbers:
on the screen and the statement scanf("%f %f", &a, &b); read the two numbers 2.9 and 3.6 entered through the
keyboard and store them in the computer memory.
If the statements
printf("Enter any two numbers:");
scanf("%f %f", &a, &b);
are replaced by the statements:
printf("Enter any number:");
scanf("%f", &a);
printf("Enter any number:");
scanf("%f", &b);
i.e.,
#include<stdio.h>
main()
{
float a, b, sum;
printf("Enter any number:");
scanf("%f", &a);
printf("Enter any number:");
17
scanf("%f", &b);
sum = a+ b;
printf("the sum of a and b = %f", sum);
}
Then the output on the screen:
Enter any number:
If you enter a number 2.9
Enter any number:
If you enter a number 3.6
the sum of a and b = 6.5 will be outputted on the screen.
If the statement
printf("the sum of a and b = %f", sum);
is replaced by the statement
printf("the sum of %f and %f = %f", a, b, sum);
Then the output on the screen is:
the sum of 2.9 and 3.6 = 6.5
In the statement
printf("the sum of %f and %f = %f", a, b, sum);
there are three format strings:
The format string %f after the statement (the sum of) indicates that the value to be displayed needs to be taken from
a variable a.
The format string %f after the statement (the sum of %f and) indicates that the value to be displayed needs to be
taken from a variable b.
The format string %f after the statement (the sum of %f and %f = ) indicates that the value to be displayed needs to
be taken from a variable sum.
Program 1.4
#include<stdio.h>
main()
{
float C, F;
C=38.5;
F = 9*C/5 +32;
printf("temperature in Fahrenheit= %f", F);
}
The output on the screen:
temperature in Fahrenheit= 101.3
As said earlier: if × is used instead of * and F = 9C/5 +32 is used of F = 9*C/5 +32, then the compilation error will
be displayed on the screen.
If you want to supply a number 16 digits after decimal point i.e., 36.5555555555555555 for C, then the statement
18
double C, F; should be used instead of the statement float C, F;
and %lf should be used instead of %f
i.e.,
#include<stdio.h>
main()
{
double C, F;
C=38.5555555555555555;
F = 9*C/5 +32;
printf("temperature in Fahrenheit= %lf", F);
}
And if you want to supply the number 16 digits after decimal point for C through the key board, then the statement
C=38.5;
should be replaced by the statements
printf("Enter any number:");
scanf("%lf", &C);
i.e.,
#include<stdio.h>
main()
{
double C, F;
printf("Enter any number:");
scanf("%lf", &C);
F = 9*C/5 +32;
printf("temperature in Fahrenheit= %lf", F);
}
Note:
#include <stdio.h>
main()
{
double C, F;
C = 25.3333333333333333;
F = 9*C/5 +32;
printf("temperature in Fahrenheit= %lf", F);
}
The output on the screen:
temperature in Fahrenheit = 77.600000
19
main()
{
double C;
float F;
C = 25.3333333333333333;
F = 9*C/5 +32;
printf("temperature in Fahrenheit= %f", F); (%f is used because the data type for F is float)
}
Then there is slight change in the output on the screen:
temperature in Fahrenheit = 77.599998
Answer:
#include<stdio.h>
main()
{
int a, b, c, sum;
printf("Enter any three numbers:");
scanf("%d %d%d", &a, &b, &c);
sum = a + b + c;
printf("the sum of a, b and c = %d", sum);
}
#include<stdio.h>
#include<math.h>
main()
{
int a, b, c, s, area;
a = 3;
b= 4;
c=5;
s = (a + b + c) / 2;
area = sqrt ((s * (s-a) * (s-b) * (s-c));
printf("the area of the triangle = %d", area);
}
Note: since sqrt() is not part of C language or of standard input output file i.e., (stdio.h file), it is part of math file
i.e., (math.h file which defines various mathematical functions) so #include< math.h> should be included in the C
program otherwise the compilation error will be flagged on the screen stating that sqrt() is not declared.
If the statement area = (s (s-a) (s-b) (s-c)) ½ is written instead of area = sqrt ((s * (s-a) * (s-b) * (s-c));
Then the compilation error will be displayed on the screen because C does not support area = (s (s-a) (s-b) (s-c)) ½.
20
Punch Cards (or IBM cards, or Hollerith cards) -- a piece of stiff paper that contained commands for controlling
automated machinery or data for data processing applications – was formerly used to program computers.
A paper tape, constructed from punched cards, in use in a Jacquard loom. The large holes on each edge were sprocket
holes, which were used to pull the paper tape through the loom.
Program 1.5
#include<stdio.h>
main()
{
int a, b, product;
a=1;
b=2;
product = a * b;
printf("the product of a and b = %d", product);
}
The output on the screen:
the product of a and b = 2
If you insert a value 2^3 for a and 3^2 for b, then as said earlier wrong result or compilation error will be flagged on
the screen because C language do not support the operation 2^3 and 3^2,
a=2^3;
b=3^2; → ERROR
a=2* 2*2
b=3*3; → No ERROR will be displayed on the screen and the Result will be outputted on the screen i.e.,
the product of a and b = 72 will be outputted on the screen.
#include<stdio.h>
main()
21
{
long int a, b, product;
a=1000000000;
b=2000000000;
product = a * b;
printf("the product of a and b = %ld", product);
}
The output on the screen:
the product of a and b = 3000000000000000000
“A language that doesn’t have everything is actually easier to program in than some that do.”
“UNIX is basically a simple operating system, but you have to be a genius to understand the simplicity.”
: Dennis Ritchie
(1941 – 2011)
If you want to supply the values for a and b through the key board, then the statements
a=1;
b=2; should be replaced by the statements
printf("Enter any two numbers:");
scanf("%d %d", &a, &b);
i.e.,
#include<stdio.h>
main ()
{
int a, b, product;
printf("Enter any two numbers:");
scanf("%d%d", &a, &b);
product = a* b;
printf("the product of a and b = %d", product);
}
The output on the screen:
Enter any two numbers:
If you enter two numbers 1 and 3
the product of a and b = 3 will be outputted on the screen.
If you replace the statements
printf("Enter any two numbers:");
scanf("%d%d", &a, &b);
by the statements
printf("Enter any number:");
scanf("%d", &a);
printf("Enter any number:");
scanf("%d", &b);
22
Then the output on the screen will be:
Enter any number:
If you enter the number 3
Enter any number:
If you enter the number 3
the product of a and b = 9 will be outputted on the screen.
If the statement printf("the product of a and b = %d"; product); is written instead of the statement printf("the product
of a and b = %d", product); i.e., instead of variable separator (i.e., comma) semicolon is used -- Then the
compilation error will be displayed on the screen.
Note:
#include <stdio.h>
main()
{
printf("Hello, World!");
printf("Hello, World!\b");
printf("Hello, World!\b");
printf("Hello, World!\b");
}
i.e., if back space \b is used then
Hello, World!Hello, World!Hello, World!Hello, World! will be outputted on the screen.
23
printf("Hello, World!\t");
printf("Hello, World!\t");
}
The output on the screen is:
Hello, World! Hello, World! Hello, World! Hello, World!
Program 1.5
#include<stdio.h>
main()
{
int a, b;
a=2;
b = a * a;
printf("the square of a = %d", b);
}
The output on the screen:
the square of a = 4
If you want to supply the integer value for a through the key board, then the statement
a=2; is replaced by the statements
printf("Enter any number:");
scanf("%d", &a);
i.e.,
24
#include<stdio.h>
main()
{
int a, b;
printf("Enter any number:");
scanf("%d", &a);
b = a * a;
printf("the square of a = %d", b);
}
The output on the screen:
Enter any number:
If you enter a number 4
the square of a = 16 will be outputted on the screen.
Note:
If scanf(%d, &a); is written instead of scanf("%d", &a);
If printf(the square of a = %d, b); is written instead of printf("the square of a = %d", b);
If the main function is followed by a semicolon i.e.,
main(); is written instead of main()
Then the compilation error will be displayed on the screen.
But if the body of the main function is followed by a semicolon i.e.,
main()
{
}; is written instead of
main()
{
}
There will be no display of the compilation error on the screen.
main(); → ERROR
main()
{
}; → NO ERROR
Answer:
#include<stdio.h>
#include<math.h>
main()
{
int a, b;
a=2;
b = pow((a), 3);
printf("the cube of a = %d", b);
25
}
Write a program to print the energy of the substance using energy = mc2
Answer:
#include<stdio.h>
#include<math.h>
main()
{
int m;
long int c, energy;
m=2;
c = 300000000;
energy = m * pow((c), 2);
printf("the energy of the substance = %ld joules", energy);
}
Program 1.6
(a)
#include<stdio.h>
main()
{
int a, b;
a=2;
b =3;
if(a>b)
{
printf("a is greater than b");
}
26
if(b>a)
{
printf("b is greater than a");
}
}
In simpler words,
(a>b) and (b>a) are the conditions (i.e., logical expressions that results in true or false) and if the condition (a> b) is
true, then the statement
{
printf("a is greater than b");
}
make provision to print the output:
a is greater than b
and if the condition (a> b) is not true and the condition (b>a) is true, then the statement
{
printf("b is greater than a");
}
make provision to print the output:
b is greater than a
If you want to supply the integer values for a and b through the key board, then the statements
a=2;
b=3; should be replaced by the statements
printf("Enter any number:");
scanf("%d", &a);
printf("Enter any number:");
scanf("%d", &b);
i.e., the program should be rewritten as:
#include<stdio.h>
main()
{
int a, b;
printf("Enter any number:");
scanf("%d", &a);
printf("Enter any number:");
scanf("%d", &b);
if(a>b)
{
printf("a is greater than b");
27
}
if(b>a)
{
printf("b is greater than a");
}
}
The output on the screen:
Enter any number:
If you enter the number 6
Enter any number:
If you enter the number 3
a is greater than b will be outputted on the screen.
Note:
If the symbol > is replaced by >>
i.e., if
(a>> b)
(b>>a)
is written instead of
(a>b)
(b>a)
Then the program will be successfully executed but there will be no display of the output on the screen.
(b)
#include<stdio.h>
main()
{
int a, b;
a=2;
b =3;
if(a>b)
{
printf("a is greater than b");
}
else
28
{
printf("b is greater than a");
}
}
Note:
Program 1.7
29
}
if (this condition is true)
{
print this statement using printf function;
}
(a)
#include<stdio.h>
main()
{
int a, b, c;
a=2;
b =3;
c=4;
if(a>b&&a>c)
{
printf("a is greater than b and c");
}
if(b>a&&b>c)
{
printf("b is greater than a and c");
}
if(c>b&&c>a)
{
printf("c is greater than b and a");
}
}
The output on the screen:
c is greater than b and a
30
printf("b is greater than a and c");
}
make provision to print the output using printf function:
b is greater than a and c
and if the condition (b>a&&b>c) is not true and the statement b is greater than a and c is not executed; instead the
execution skips and pass to the condition (c>b&&c>a) and if this condition is true, then the statement
{
printf("c is greater than b and a");
}
make provision to print the output using printf function:
c is greater than b and a
(b)
#include<stdio.h>
main()
{
int a, b, c;
a=2;
b =3;
c=4;
if(a>b&&a>c)
{
printf("a is greater than b and c");
}
else if (b>a&&b>c)
{
printf("b is greater than a and c");
}
else
{
printf("c is greater than b and a");
}
31
}
The output on the screen:
c is greater than b and a
(c)
#include<stdio.h>
main()
{
int a, b, c;
printf("Enter any number:");
scanf("%d", &a);
printf("Enter any number:");
scanf("%d", &b);
printf("Enter any number:");
scanf("%d", &c);
if(a>b&&a>c)
{
printf("%d is greater than %d and %d", a, b, c);
}
else if (b>a&&b>c)
{
printf("%d is greater than %d and %d", b, a, c);
}
else if (c>b&&c>a)
{
printf("%d is greater than %d and %d", c, b, a);
}
}
The output on the screen:
Enter any number:
If you enter the number 2
Enter any number:
32
If you enter the number 3
Enter any number:
If you enter the number 4
4 is greater than 3 and 2 will be outputted on the screen.
As said earlier:
If the statements
if(a>b&&a>c)
{
printf("%d is greater than %d and %d", a, b, c);
}
else if (b>a&&b>c)
{
printf("%d is greater than %d and %d", b, a, c);
}
else if (c>b&&c>a)
{
printf("%d is greater than %d and %d", c, b, a);
}
are replaced by the statements
if(a>b&&a>c)
printf("%d is greater than %d and %d", a, b, c);
else if (b>a&&b>c)
printf("%d is greater than %d and %d", b, a, c);
else if (c>b&&c>a)
printf("%d is greater than %d and %d", c, b, a);
i.e., if the program is rewritten as:
#include<stdio.h>
main()
{
int a, b, c;
printf("Enter any number:");
scanf("%d", &a);
printf("Enter any number:");
scanf("%d", &b);
printf("Enter any number:");
scanf("%d", &c);
if(a>b&&a>c)
printf("%d is greater than %d and %d", a, b, c);
else if (b>a&&b>c)
printf("%d is greater than %d and %d", b, a, c);
else if (c>b&&c>a)
printf("%d is greater than %d and %d", c, b, a);
}
33
There will no display of compilation error on the screen and c is greater than b and a will be successfully outputted
on the screen
“ Everybody in this country should learn how to program a computer... because it teaches you how to think.”
: Steve Jobs
ERMA (Electronic Recording Machine, Accounting) was the first machine to use Magnetic Ink Character Recognition
(MICR)
Hypercard (an application program and programming tool for Apple Macintosh and Apple IIGS computers), that was
among the first successful hypermedia systems before the World Wide Web
Did you know that: American computer scientist Grace Brewster Murray Hopper completed A-0, a program that
allowed a computer user to use English-like words instead of numbers to give the computer instructions. It
possessed several features of a modern-day compiler and was written for the UNIVAC I (Universal Automatic
Computer I), the first commercial business computer system in the United States.
#include <stdio.h>
main()
{
int a, b;
a=2;
b=2;
if(a>b || a= = b)
printf("a is greater than or equal to b");
else
printf("b is greater than a");
}
Answer:
a is greater than or equal to b
Note: symbol || denote OR i.e., a>b || a= = b denote a is greater than or a is equal to b.
Program 1.8
#include<stdio.h>
main()
{
int N1, N2, N3, N4, N5, N6, N7, N8, N9, N10, X;
34
printf("Enter any 10 numbers:");
scanf("%d%d%d%d%d%d%d%d%d%d", &N1, &N2, &N3, &N4, &N5, &N6, &N7, &N8, &N9, &N10);
X = (N1 + N2 + N3 + N4 + N5 + N6 + N7 + N8 + N9 + N10) /10;
printf("the average of 10 numbers = %d", X);
}
The output on the screen:
Enter any 10 numbers:
If you enter ten numbers 1, 2, 3, 4, 5, 6, 7, 8, 9 and 10
the average of 10 numbers = 5 will be outputted on the screen.
Note: The average of 10 numbers is 5.5, the output on the screen is 5 because the data type int is used instead of
float.
Any mathematical expression should be written in C equivalent expression to prevent the display of compilation
error on the screen because C language does not accept the general mathematical expressions.
2a2 + 3b + 2 2a *a + 3b + 2
ex + b exp (x) + b
x½ sqrt(x)
x 1/3 cbrt(x)
α=β+γ alpha = beta + gamma
sinθ + cosθ sin (theta) + cos (theta)
a = e x / √ (1+ sinθ) a = exp ( x / sqrt ( 1 + sin (theta)))
#include <stdio.h>
#include<math.h>
main()
{
int a, b, x;
x=2; b=2;
35
a = exp (x) + b; Suppose if you enter the number 2, the square root of
printf("the value of a = %d", a); a number = 1 is outputted on the screen because int is
} used instead of float.
#include <stdio.h>
#include<math.h> Note:
main()
{ Since b = sqrt (a) is written
int alpha, beta, gamma; #include<math.h> must be included in the above
program otherwise compilation error will flag on the
alpha =2;
screen.
beta=2;
i.e., the program:
gamma= 2 * alpha + beta;
#include<stdio.h>
printf("the value of alpha = %d", alpha);
main()
}
{
int a, b;
#include <stdio.h>
printf("Enter any number:");
#include<math.h>
scanf("%d", & a);
main ()
b = sqrt (a);
{
printf("the square root of a number = %d", b);
double theta, result;
}
theta = 90;
will flag compilation error on the screen.
result = sin(theta);
If float is used instead of int then the above program
printf ("The sine 90 degrees is = %lf ", result); take the form:
} #include<stdio.h>
#include<math.h>
What is C equivalent expression of (x/y) n-1? main()
Answer: pow((x/y), n-1) {
float a, b;
printf("Enter any number:");
Program 1.9 scanf("%d", & a);
C program to find the square root of a number b = sqrt (a);
printf("the square root of a number = %f", b);
#include<stdio.h> }
#include<math.h> The output on the screen:
main() Enter any number:
{ If you enter the number 5
int a, b; the square root of a number = 2.23 is outputted on the
printf("Enter any number:"); screen.
scanf("%d", & a); This program can also be written as:
b = sqrt (a); #include<stdio.h>
printf("the square root of a number = %d", b); #include<math.h>
} main()
The output on the screen: {
Enter any number: printf("the square root of a number = %f", sqrt (4));
If you enter the number 4 }
the square root of a number = 2is outputted on the
screen.
36
“Measuring programming progress by lines of code is main()
like measuring aircraft building progress by weight.” {
int P,T, R, SI;
: Bill Gates P = 1000;
|| imply or T = 2;
>imply greater than R = 3;
<imply less than SI = P*T*R/100;
= = imply equal to printf("the simple interest = %d", SI);
! imply not }
!= imply not equal to The output on the screen:
&& imply and the simple interest = 60
& imply address
Note:
Did you know that If you write SI = PTR/100; instead of SI =
P*T*R/100;
American computer scientist John Warner Backus Then compilation error is displayed on the screen
completed Speed code for IBM´s first large-scale because C language does not accept the general
scientific computer, the IBM 701. Although using expressions.
Speed code demanded a significant amount of scarce
memory, it greatly reduced the time required to write a If you want to supply the values for P, T and R
program. In 1957, Backus became project leader of through the key board, then the statements
the IBM FORTRAN (International Business Machine
P = 1000;
Formula Translation) project, which became the most
popular scientific programming language in history T = 2;
and is still in use today. R = 3; should be replaced by the statements
printf("Enter any number:");
Harvard Mark I computer was built as a partnership scanf("%d", &P);
between Harvard and IBM in 1944 printf("Enter any number:");
scanf("%d", &T);
What is the mistake in the following program? printf("Enter any number:");
scanf("%d", &R);
#include<stdio.h> i.e., the above program should take the form:
#include<math.h>
main() #include<stdio.h>
{ main()
Float x, y, c, b; {
x=2; int P,T, R, SI;
y=3; printf("Enter principal amount:");
c=4; scanf("%d", &P);
b = log 10 (x/y + c); printf("Enter time:");
printf("the value of b= %F", b); scanf("%d", &T);
} printf("Enter rate of interest:");
scanf("%d", &R);
Program 2.0 SI = P*T*R/100;
printf("the simple interest = %d", SI);
C program to find the simple interest }
The output on the screen:
#include<stdio.h>
37
Enter principal amount:
If you enter the principal amount 1000 #include<stdio.h>
Enter time: main()
If you enter the time 2 {
Enter rate of interest: int age;
If you enter the rate of interest 3 printf("Enter age:");
the simple interest = 60 will be outputted on the scanf("%d", &age);
screen. if(age>60)
{
Note: if write the statement scanf("%d," &P); instead printf("senior citizen");
of scanf("%d", &P); }
or if(age<60)
if write the statement scanf(%d, &P); instead of {
scanf("%d", &P); i.e., format string for data type int
printf("not a senior citizen");
i.e., %d is not enclosed by double quotes (" ")
}
Then compilation error will be displayed on the
console screen. }
The output on the screen:
Program 2.1 Enter age:
If you enter the value 60
C program to find whether the person is senior citizen senior citizen will be outputted on the screen.
or not Suppose if you enter the value 27
not a senior citizen will be outputted on the screen.
#include<stdio.h>
main() Note: As said earlier:
{ If the symbol >> is used instead of > and << is used
int age; instead of <
age=20; i.e.,
if(age> = 60) #include<stdio.h>
{ main()
printf("senior citizen"); {
} int age;
if(age<60) printf("Enter age:");
{ scanf("%d", &age);
printf("not a senior citizen"); if(age>>60)
} {
} printf("senior citizen");
The output on the screen: }
not a senior citizen if(age<<60)
(age> = 60) means age greater than or equal to 60 {
If you want to supply the value for age through the printf("not a senior citizen");
key board, then the statement }
age=20; }
should be replaced by the statements Then the program will be executed successfully
printf("Enter age:"); without the display of any compilation error but the
scanf("%d", &age); output will not be displayed on the screen.
i.e., the above program should take the form:
38
Program 2.2 If you want to supply the integer values for marks M 1,
M2 and M3 through the key board, then the statements
C program to get marks for 3 subjects and declare the M1 = 38;
result. M2= 45;
If the marks >= 35 in all the subjects the student M3 = 67; should be replaced by the statements
passes else fails. printf("Enter any three numbers:");
scanf("%d%d%d", &M1, &M2, &M3);
#include<stdio.h> i.e.,
main() #include<stdio.h>
{ main()
int M1, M2,M3; {
M1 = 38; int M1, M2,M3;
M2= 45; printf("Enter any three numbers:");
M3 = 67; scanf("%d%d%d", &M1, &M2, &M3);
if(M1>= 35 && M2>= 35 && M3>= 35) if(M1>= 35 && M2>= 35 && M3>= 35)
{ {
printf("candidate is passed"); printf("candidate is passed");
} }
else else
{ {
printf("candidate is failed"); printf("candidate is failed");
} }
} }
The output on the screen: The output on the screen:
candidate is passed Enter any three numbers:
>= imply greater than or equal to and double If you enter three numbers 26, 28, 39
ampersand imply and candidate is failed will be outputted on the screen.
(M1>= 35 && M2>= 35 && M3>= 35) denote the
condition and this condition imply M1 is greater than
“Programs must be written for people to read, and
or equal to 35 and M2 is greater than or equal to 35
only incidentally for machines to execute.”
and M3 is greater than or equal to 35. And if this
condition is TRUE, then the statement
{ : Harold Abelson
printf("candidate is passed");
Did you know that
}
make provision to print the output using the output
function printf: An IBM team led by John Backus developed
FORTRAN, a powerful scientific computing language
candidate is passed that used English-like statements. Some programmers
else the statement were skeptical that FORTRAN could be as efficient as
{ hand coding, but that sentiment disappeared when
printf("candidate is failed"); FORTRAN proved it could generate efficient code.
} Over the ensuing decades, FORTRAN became the
make provision to print the output using printf most often used language for scientific and technical
computing. FORTRAN is still in use today.
function:
candidate is failed
Header file in C the functions it defines
stdio.h standard input output functions
39
(standard input (like scanf and printf functions) {
output header char a = 'b';
file) if( isalpha(a) )
math.h mathematical functions (like {
log(), sqrt(), sin(), cos(), log10()
printf(" the character a is an alphabet");
etc.)
}
stdlib.h standard library functions
else
(like void abort(void) – a function
{
which causes an abnormal/
unusual program termination) printf("the character a is not an alphabet");
ctype.h character manipulation functions }
(like isalpha() which checks }
whether a character is an alphabet The output on the screen:
or not) the character a is an alphabet
graphics.h graphical functions
If the statement char a = b; is written instead of char a
conio.h console input output functions = 'b'; Then the compilation error will be flagged on the
(console input like clrscr() – a function which display screen.
output header clears the screen.
file) Program 2.3
Note: The term console usually refers to monitor or C program to find profit or loss
display screen.
#include<stdio.h>
Write a program to check whether a character is an main()
alphabet or not using the function isalpha() {
int CP, SP, loss, profit;
#include <stdio.h> printf("Enter cost price:");
#include <ctype.h> scanf("%d", &CP);
main() printf("Enter selling price:");
{ scanf("%d", &SP);
int a =2; if(SP>CP)
if( isalpha(a) ) {
{ printf("profit=%d", SP-CP);
printf(" the character a is an alphabet"); }
} if(CP>SP)
else {
{ printf("loss =%d", CP-SP);
printf("the character a is not an alphabet"); }
} }
} The output on the screen:
The output on the screen: Enter cost price:
the character a is not an alphabet If you enter the cost price 25
Enter selling price:
#include <stdio.h> If you enter the selling price 26
#include <ctype.h> profit = 1 will be outputted on the screen.
main()
40
If the condition (SP>CP) is true, then the statement C = 2.54*I;
{ printf("length in centimeters= %f", C);
printf("profit=%d", SP-CP); }
} The output on the screen:
make provision to print the output: Enter the length in inches:
profit = SP-CP (in this case profit = 26-25 =1) If you enter the floating point value or fractional or
If the condition (CP>SP) is true, then the statement decimal number for I i.e., 25.5
{ length in centimeters = 64.9 will be outputted on the
printf("loss=%d", CP-SP); screen.
} Suppose
make provision to print the output: If you enter the value 25
loss = CP-SP The output on the screen:
Note: if the minus sign (‒) is used instead of the minus length in centimeters = 63.5
sign (-) i.e., CP‒ SP is written instead of CP- SP, the Even if you enter the value 25 instead of 25.5, float
error will be displayed on the screen (because C is should be used instead of int because if float is not
case sensitive language). used then C = 63 will be outputted on the screen.
C program to convert inches into centimeter C program to find the incremented and decremented
values of two numbers.
#include<stdio.h>
main() #include<stdio.h>
{ main()
float I, C; {
I=3.5; int a, b, c, d, e, f;
C = 2.54*I; a = 10;
printf("length in centimeters= %f", C); b=12;
} c=a+1;
The output on the screen: d=b+1;
length in centimeters = 8.89 e=a-1;
Note: float is used instead of int because I = 3.5 if int f=b-1;
is used instead of float then the result will not be printf("the incremented value of a =%d", c);
clearly outputted i.e., instead of 8.89 the computer printf("the incremented value of b =%d", d);
displays only 8. And since float is used instead of int, printf("the decremented value of a =%d", e);
the operator %d is replaced by the operator %f. printf("the decremented value of b =%d", f);
}
If you want to supply the floating value for I through The output on the screen:
the key board, then the above program should take the
the incremented value of a = 11 the incremented value
form:
of b = 13 the decremented value of a = 9 the
decremented value of b = 11
#include<stdio.h>
main() If the statements
{ printf("the incremented value of a =%d", c);
float I, C; printf("the incremented value of b =%d", d);
printf("Enter the length in inches:"); printf("the decremented value of a =%d", e);
scanf("%f", &I); printf("the decremented value of b =%d", f);
41
are replaced by the statements The statements
printf("the incremented value of a =%d\n", c); printf("the incremented value of a =%d\n", c);
printf("the incremented value of b =%d\n", d); printf("the incremented value of b =%d\n", d);
printf("the decremented value of a =%d\n", e); printf("the decremented value of a =%d\n", e);
printf("the decremented value of b =%d\n", f); printf("the decremented value of b =%d\n", f);
i.e., new line \n is included i.e., the program is are the same as:
rewritten: printf("\n the incremented value of a =%d", c);
#include<stdio.h> printf("\n the incremented value of b =%d", d);
main() printf("\n the decremented value of a =%d", e);
{ printf("\n the decremented value of b =%d", f);
int a, b, c, d, e, f;
a = 10; If you want to supply the values for a and b through
b=12; the key board, then the above program should take the
c=a+1; form:
d=b+1;
e=a-1; #include<stdio.h>
f=b-1; main()
printf("the incremented value of a =%d\n", c); {
printf("the incremented value of b =%d\n", d); int a, b, c, d, e, f;
printf("the decremented value of a =%d\n", e); printf("Enter any number:");
printf("the decremented value of b =%d\n", f); scanf("%d", &a);
return(0); printf("Enter any number:");
} scanf("%d", &b);
The output on the screen: c=a+1;
the incremented value of a = 11 d=b+1;
the incremented value of b = 13 e=a-1;
the decremented value of a = 9 f=b-1;
the decremented value of b = 11 printf("the incremented value of a =%d\n", c);
i.e., \n make provision for the another result to print in printf("the incremented value of b =%d\n", d);
the new line and (as said earlier) with and without the printf("the decremented value of a =%d\n", e);
statement return (0); the program will be successfully printf("the decremented value of b =%d\n", f);
executed and the result will be outputted on the screen }
without the display of any ERROR on the screen.
The output on the screen:
Enter any number:
Even if the statements
If you enter the number 2
printf("the incremented value of a =%d\n", c);
Enter any number:
printf("the incremented value of b =%d\n", d);
If you enter the number 3
printf("the decremented value of a =%d\n", e);
printf("the decremented value of b =%d\n", f);
the incremented value of a = 3
are replaced by the statements
the incremented value of b = 4
printf("\n the incremented value of a =%d", c);
the decremented value of a = 1
printf("\n the incremented value of b =%d", d);
the decremented value of b = 2
printf("\n the decremented value of a =%d", e);
will be outputted on the screen.
printf("\n the decremented value of b =%d", f);
There will be no change in the output on the screen
Note: b++ is same as b + 1 and b-- is same as b - 1 but
i.e.,
b++ or b-- should be used only in case of for loop or
42
loop statements. Usage of b++ or b-- instead of b +1 }
or b-1 in the certain online compilers like coding if(P>=40&&P<=50 )
ground (tutorials point) yields error or displays the {
wrong result.
printf("pass class");
}
What is the mistake in the following program:
if(P<40)
{
#include<stdio.h>
printf("fail");
main(),
}
{
}
float T1, T2, A,
The output on the screen:
printf("Enter any number:");
Enter the percentage:
scanf("%f"; &T1);
If you enter the percentage 65
printf("Enter any number:");
first class will be outputted on the screen.
scanf("%f," &T2);
A = (T1 + T2) / 2,
Program 2.7
printf("the average temperature of the day = %c"; a);
}
C program to calculate the discounted price and the
total price after discount
Did you know that: the process of fixing the errors in Given:
the program is called debugging. If purchase value is greater than 1000, 10%
discount
If purchase value is greater than 5000, 20%
Program 2.6 discount
If purchase value is greater than 10000, 30%
The percentage marks are entered and the grades are discount
allotted as follows :
percentage>= 60 First Class (a) discounted price
percentage>=50 and per <= 60 Second Class
percentage>= 40 and per <= 50 Pass Class #include<stdio.h>
percentage< 40 Fail main()
Write a C program for the above: {
int PV, dis;
#include<stdio.h> printf("Enter purchased value:");
main() scanf("%d", &PV);
{ if(PV<1000)
int P; {
printf("Enter the percentage:"); printf("dis=%d", PV* 0.1);
scanf("%d", &P); }
if(P >= 60) if(PV>5000)
{ {
printf("first class"); printf("dis =%d", PV* 0.2);
} }
if(P>=50&&P <60) if(PV<10000)
{ {
printf("second class"); printf("dis=%d", PV* 0.3);
}
43
} {
The output on the screen: printf("total =%d", PV- PV* 0.2);
Enter purchased value: }
If you enter the purchased value 6500 if(PV<10000)
dis = 1300 will be outputted on the screen. {
printf("total=%d", PV- PV* 0.3);
(PV<1000), (PV>5000) and (PV<10000) denote the }
conditions and if the condition (PV<1000) is true i.e., }
purchased value is less than 1000, then the statement The output on the screen:
{ Enter purchased value:
printf("dis=%d", PV* 0.1); If you enter the purchased value 650
} total = 585 will be outputted on the screen.
make provision to print the output using printf
function:
If the condition (PV<1000) is true i.e., purchased
dis= PV* 10% = PV* 10 /100 = PV* 0.1 value is less than 1000, then the statement
and if the condition (PV<1000) is false and if the {
condition (PV< 5000) is true i.e., purchased value is
printf("total = %d", PV - PV* 0.1);
less than 5000, then the statement
}
{
make provision to print the output:
printf("dis=%d", PV* 0.2);
total =PV- dis = PV- PV*10% = PV- PV* 10 /100 =
}
PV - PV * 0.1
make provision to print the output using the function
and if the condition (PV<1000) is false and if the
printf:
condition (PV< 5000) is true i.e., purchased value is
dis= PV* 20% = PV* 20 /100 = PV* 0.2 less than 5000, then the statement
and if the condition (PV< 5000) is not true and if the {
condition (PV< 10000) is true i.e., purchased value is
printf("total = %d", PV - PV* 0.2);
less than 10000, then the statement
}
{
make provision to print the output:
printf("dis=%d", PV* 0.3);
total =PV- dis = PV- PV*20% = PV- PV* 20 /100 =
}
PV - PV * 0.2
make provision to print the output using the printf
and if the condition (PV< 5000) is not true and if the
function:
condition (PV< 10000) is true i.e., purchased value is
dis= PV* 30% = PV* 30 /100 = PV* 0.3 less than 10000, then the statement
{
(b) total price printf("total = %d", PV - PV* 0.3);
}
#include<stdio.h>
make provision to print the output:
main()
total =PV- dis = PV- PV*30% = PV- PV* 30 /100 =
{ PV - PV * 0.3
int PV, total;
printf("Enter purchased value:"); Now, Combing both the programs (above), we can
scanf("%d", &PV); write:
if(PV<1000)
{ #include<stdio.h>
printf("total=%d", PV - PV* 0.1); main()
} {
if(PV>5000) int PV, dis, total;
44
printf("Enter purchased value:"); value of i = 1 value of i = 2 value of i= 3 value of i=
scanf("%d", &PV); 4 value of i= 5 value of i= 6 value of i = 7 value of i=
if(PV<1000) 8 value of i = 9 value of i = 10
{
printf("dis=%d", PV* 0.1); for (i=1; i<=10; i++) denote the for loop statement and
the syntax of the for loop statement is:
printf("total=%d", total - dis);
for (initialization; condition; increment)
}
Here:
if(PV>5000)
i=1 denote initialization (i.e., from where to start)
{
i<=10 denote the condition (i.e., stop when 10 is
printf("dis =%d", PV* 0.2);
reached)
printf("total=%d", total - dis);
i++ imply increment (which tells the value of i to
} increase by 1 each time the loop is executed) and i++
if(PV<10000) is the same as i+1.
{ Since the initialization i.e., i=1
printf("dis=%d", PV* 0.3); The statement printf("value of i =%d", i); make
printf("total=%d", total - dis); provision to print the output:
} value of i = 1
} on the screen.
The output on the screen: After this, the following execution takes place:
Enter purchased value: value of i
If you enter the purchased value 850 i= 1
dis = 85 Is the condition (i<=10) is true?
total = 765 Yes because i=1
will be outputted on the screen. Do this
i= 1+1 = 2
“Object oriented programming offers a sustainable The statement printf("value of i =%d", i); make
way to write spaghetti code. It lets you accrete provision to print the output:
programs as a series of patches” value of i = 2
--Paul Graham Now, the value of i is:
(an English computer scientist, a well-known essayist, i= 2
programmer, language designer, co-founded Viaweb, Is the condition (i<=10) is true?
invented Bayesian spam filters (basis of modern
Yes because i=2
filters))
Do this
i= 2+1 = 3
Program 2.8
The statement printf("value of i =%d", i); make
provision to print the output:
C program to print the first ten natural numbers using
value of i = 3
for loop statement
Now, the value of i is:
i= 3
#include<stdio.h>
Is the condition (i<=10) is true?
main()
Yes because i=3
{
Do this
int i;
i= 3+1 = 4
for (i=1; i<=10; i++)
The statement printf("value of i =%d", i); make
printf("value of i =%d", i);
provision to print the output:
}
value of i = 4
The output on the screen is:
45
Now, the value of i is: i= 9
i= 4 Is the condition (i<=10) is true?
Is the condition (i<=10) is true? Yes because i=9
Yes because i=4 Do this
Do this i= 9+1 = 10
i= 4+1 = 5 The statement printf("value of i =%d", i); make
The statement printf("value of i =%d", i); make provision to print the output:
provision to print the output: value of i = 10
value of i = 5 stop because the condition i<=10 is achieved.
Now, the value of i is:
i= 5 If new line \n is introduced i.e., the statement
Is the condition (i<=10) is true? printf("value of i =%d", i); is replaced by the
Yes because i=5 statement printf("value of i =%d\n", i); or printf("\n
value of i =%d", i); i.e.,
Do this
#include<stdio.h>
i= 5+1 = 6
main()
The statement printf("value of i =%d", i); make
provision to print the output: {
value of i = 6 int i;
Now, the value of i is: for (i=1; i<=10; i++)
i= 6 printf("value of i =%d\n", i);
Is the condition (i<=10) is true? }
Yes because i=6 Then the output on the screen is:
Do this value of i = 1
i= 6+1 = 7 value of i = 2
The statement printf("value of i =%d", i); make value of i = 3
provision to print the output: value of i = 4
value of i = 7 value of i = 5
Now, the value of i is: value of i = 6
i= 7 value of i = 7
Is the condition (i<=10) is true? value of i = 8
Yes because i=7 value of i = 9
Do this value of i = 10
i= 7+1 = 8 If the for loop statement for (i=2; i<=10; i++) is
The statement printf("value of i =%d", i); make written instead of the statement for(i=1; i<=10; i++),
provision to print the output: then the output on the screen is:
value of i = 8 value of i = 2 value of i = 3 value of i= 4 value of i=
5 value of i= 6 value of i = 7 value of i= 8 value of i
Now, the value of i is:
= 9 value of i= 10
i= 8
(because i=2 is initialized in the for loop statement the
Is the condition (i<=10) is true? printing started from value of i = 2 and ended at value
Yes because i=8 of i= 10 because of the condition i<=10)
Do this If the for loop statement for(i=1; i<10; i++) is written
i= 8+1 = 9 instead of the statement for (i=1; i<=10; i++), then the
The statement printf("value of i =%d", i); make output on the screen is:
provision to print the output: value of i = 1 value of i = 2 value of i= 3 value of i=
value of i = 9 4 value of i= 5 value of i= 6 value of i = 7 value of i=
Now, the value of i is: 8 value of i = 9
46
(Note: the condition i<=10 tells to print till value of i {
=10 but the condition i<10 tells to print till value of i int i = 1;
=9) while (i<=10)
If the statement for(i=1; i=10; i++) is written instead {
of the statement for (i=1; i<=10; i++), then the output
printf("%d\n", i++);
on the screen is:
}
value of i = 10 value of i = 10 value of i = 10 value
of i = 10 value of i= 10 value of i= 10 value of i = 10 }
value of i= 10 value of i = 10 value of i = 10 value The output on the screen is:
of i = 10 value of i = 10 value of i = 10 value of i = 1
10 value of i = 10 ………. (continues). 2
3
Note: 4
If the statement printf("value of i =%d", i); is replaced 5
by the statement printf("%d\n", i); 6
i.e., 7
#include<stdio.h> 8
main() 9
{ 10
int i;
for (i=1; i<=10; i++) (i<=10) is the condition and the statements
printf("%d\n", i); while (i<=10)
} {
The output on the screen is: printf("%d\n", i++);
1 }
2 imply that while the condition (i<=10) is to print till
3 10, print till 10 using the statement
4 {
5 printf("%d\n", i++);
6 }
7 i.e.,
8 1
9 2
10 3
4
C program to print the first ten natural numbers using 5
for while loop statement 6
7
The syntax of while loop statement is: 8
9
while (this is the condition) 10
{ Note: The statement int i = 1; imply that we are
execute this statement; creating an integer variable i and we are initializing i
} =1.
47
i.e., C program to print first 10 numbers using do while
#include<stdio.h> loop statement
main()
{ The syntax of do while loop statement is:
int i;
while (i<=10) do
{ {
printf("%d\n", i++); execute this statement;
} }
} while(this is the condition);
Then the compilation error will be displayed on the
screen because initialization is not defined i.e., from #include<stdio.h>
where to start is not declared. main()
{
If the statement int i = 1; is replaced by the int i = 0; int i =1;
i.e., do
#include<stdio.h> {
main() printf(" i= %d\n", i++);
{ } while (i<=10);
int i = 0; }
while (i<=10) The output on the screen is:
{ i= 1
printf("%d\n", i++); i=2
} i= 3
} i= 4
Then the output on the screen is: i= 5
0 i= 6
1 i=7
2 i= 8
3 i= 9
4 i= 10
5
6 Using the statement
7 do
8 {
9 printf(" i= %d\n", i++);
10 }
Similarly if the statement int i = 0; is replaced by the while the condition (i<=10) is to print till i = 10 (
int i = 7; starting from i = 1 because of the statement int i=1;)
Then the output on the screen is:
7 Why LOOP is USED?
8
9 If loop is not used then the C program to print first 10
10 numbers should be written as follows:
#include<stdio.h>
48
main() Note: there is no mistake in the above program
{ because even if write printf("Linux is not portable\n",
printf("\n i = 1"); i); instead of
printf("\n i = 2"); printf("Linux is not portable\n"); there will no flag of
error on the screen, the program will be successfully
printf("\n i = 3");
executed and the output
printf("\n i = 4");
Linux is not portable
printf("\n i = 5");
Linux is not portable
printf("\n i = 6");
Linux is not portable
printf("\n i = 7");
Linux is not portable
printf("\n i = 8");
Linux is not portable
printf("\n i = 9");
will be displayed on the console screen.
printf("\n i = 10");
}
Note:
It takes pretty long time to write the code and the
execution time is pretty long i.e., Because to reduce
the time taken to write the code and to reduce the For the program:
execution time -- loop statement is used. #include<stdio.h>
“Simplicity is the ultimate sophistication.” main()
: LEONARDO DA VINCI {
int i;
Write a program to print for (i =1; i=5; i ++)
Never test for an error condition you don't know how printf("Linux is not portable");
to handle }
5 times using for loop statement. The output on the screen is:
Linux is not portable Linux is not portable Linux is
Answer: not portable Linux is not portable Linux is not
portable Linux is not portable Linux is not portable
Linux is not portable Linux is not portable Linux is
#include<stdio.h>
not portable Linux is not portable Linux is not
main() portable Linux is not portable …. continues
{
int i; But for the program:
for (i =1; i<=5; i ++) #include<stdio.h>
printf("Never test for an error condition you don't main()
know how to handle \n");
{
}
int i;
for (i =1; i = = 5; i ++)
What is the mistake in the following program:
printf("Linux is not portable");
}
#include<stdio.h>
The output on the screen is:
main()
?
{
i.e., the program will be successfully executed but
int i; there will be no output on the screen.
for (i =1; i<=5; i ++)
printf("Linux is not portable\n", i);
}
49
Y
Z
char means the data type is character.
The statement
char a; imply that we are creating the character a.
Since char a is used. Therefore: the format specifier
%c should be used instead of %d or %f otherwise
error will be flagged on the screen.
Program 2.9 If the statement for( a=A; a<=Z; a++) is written
instead of the statement for( a='A'; a<='Z'; a++)
i.e., A is written instead of 'A' and Z is written instead
C program to print the characters from A to Z using
of 'Z', then the compilation error will be displayed on
for loop, do while loop and while loop statement.
the console screen.
(a) C program to print the characters from A to Z
using for loop statement: (b) C program to print the characters from A to Z
using while loop statement:
#include<stdio.h>
#include<stdio.h>
main()
main()
{
{
char a;
char a = 'A';
for( a='A'; a<='Z'; a++)
while (a<='Z')
printf("%c\n", a);
{
}
printf("%c\n", a++);
The output on the screen:
}
A
}
B
C
(c) C program to print the characters from A to Z
D
using do while loop statement:
E
F #include<stdio.h>
G main()
H {
I char a = 'A';
J do
K {
L printf(" %c\n", a++);
M } while (a<='Z');
N }
O
P Program 3.0
Q
R C program to print the given number is even or odd.
S
T #include<stdio.h>
W main()
X {
50
int a; Did you know that
printf("Enter any number:");
scanf ("%d", &a); Apple engineer William Atkinson designed
if(a%2 = = 0) HyperCard, a software tool that simplified
{ development of in-house applications. In HyperCard,
programmers built “stacks” of information with the
printf("the number is even");
concept of hypertext links between stacks of pages. As
} a stack author, a programmer employed various tools
else to create his own stacks, linked together as a sort of
{ slide show. Apple distributed the program free with
printf("the number is odd"); Macintosh computers until 1992. HyperCard
} influenced the creation on the Internet protocol HTTP
(Hyper Text Transfer Protocol) and JavaScript.
}
The output on the screen:
Data types and their storage size
Enter any number:
If you enter the number 4
Data type Storage size
the number is even will be outputted on the screen.
char 1 byte
Mathematical symbol % denote modulus and (a%2 =
= 0) is the condition and this condition imply: a int 2 byte
divided by 2 yields reminder = 0. float 4 byte
For example: if you enter the number 4 double 8 byte
Then a = 4
Then 4 divided by 2 yields the remainder = 0 Program 3.1
Then the statement C program to print the remainder of two numbers
{
printf("the number is even"); #include<stdio.h>
} main()
make provision to print the output: {
the number is even int a, b, c;
(Note: in C language = = implies equal to) printf("Enter any number:");
Suppose if you enter the number 3 scanf("%d", &a);
Then a = 3 printf("Enter any number:");
Then 3 divided by 2 yields the remainder = 1 scanf("%d", &b);
Then the statement c = a%b;
{ printf("the remainder of a and b = %d", c);
printf("the number is odd"); }
} The output on the screen:
make provision to print the output: Enter any number:
the number is odd If you enter the number 3
Enter any number:
“If you lie to the compiler, it will get its revenge.” If you enter the number 2
the remainder of a and b = 1 will be outputted on the
: Henry Spencer (a screen.
Canadian computer programmer and space enthusiast. Since (a =3 and b =2). Therefore:
He wrote “regex”, a widely used software library for 3 divided by 2 (i.e., a divided by b) yields the
regular expressions, and co-wrote C News, a Usenet remainder equal to 1
server program) If the statement printf("the remainder of a and b =
%d", c); is replaced by the statement
51
printf("the remainder of %d and %d = %d", a, b, c); If you enter the number 2
i.e., the two numbers are equivalent will be outputted on
#include<stdio.h> the screen.
main()
{ Since 2-2 is equal to 0 (i.e., x-y = = 0). Therefore: the
int a, b, c; statement
printf("Enter any number:"); {
scanf("%d", &a); printf("the two numbers are equivalent");
printf("Enter any number:"); }
scanf("%d", &b); makes provision to print the output:
c = a%b; two numbers are equivalent
printf("the remainder of %d and %d = %d", a, b, c);
} If you enter the integers 3 and 2
The output on the screen: The output on the screen:
Enter any number: the two numbers are not equivalent
If you enter the number 3
Enter any number: Since 3-2 is not equal to 0 (i.e., x-y != 0). Therefore:
the statement
If you enter the number 2
{
the remainder of 3 and 2 = 1 will be outputted on the
screen. printf("the two numbers are not equivalent");
}
Program 3.2 makes provision to print the output:
two numbers are not equivalent
C program to check the equivalence of two numbers. (as said earlier: in C language the symbol != implies
not equal to)
#include<stdio.h>
main() What is the mistake in the following program:
{
int x, y; #include<stdio.h>
printf("Enter any number:"); main()
scanf ("%d", &x); {
printf("Enter any number:"); int year;
scanf ("%d", &y); year =1996;
if(x-y==0) if(year%4==0)
{ printf("leap year");
printf("the two numbers are equivalent"); else
} printf("not a leap year");
else }
{
printf("the number are not equivalent"); Answer: there is no mistake in the above program
}
} The output on the screen is:
The output on the screen: leap year
Enter any number:
If you enter the number 2 Since year =1996. Therefore:
Enter any number:
52
1996 divided by 4 (i.e., year divided by 4) yields the Since a = -35. Therefore:
remainder equal to 0. a is less than 0 i.e., a < 0 because any negative number
The statement is always less than zero.
The statement
printf("leap year"); {
printf("number is negative");
makes provision to print the output: }
leap year makes provision to print the output:
If the year is = 1995. Then number entered is negative
1995 divided by 4 (i.e., year divided by 4) yields the
remainder not equal to 0. Program 3.4
The statement
C program to print the sum of the first 10 digits using
printf("not a leap year"); for loop statement
53
i=4 (now the sum = 6) i=1 (sum = 1 because the sum is initialized to 1 in the
Is i<=10 true? statement int i, sum = 1;)
Yes, do this Is i<=10 true?
sum = sum + i = 6 + 4= 10 Yes, do this
value of i sum = sum + i = 1 +1 = 2
i=5 (now the sum = 10) value of i
Is i<=10 true? i=2 (now the sum = 2)
Yes, do this Is i<=10 true?
sum = sum + i = 10 + 5= 15 Yes, do this
value of i sum = sum + i = 2 + 2 = 4
i=6 (now the sum = 15) value of i
Is i<=10 true? i=3 (now the sum = 4)
Yes, do this Is i<=10 true?
sum = sum + i = 15 + 6 = 21 Yes, do this
sum = sum + i = 4 +3 = 7
value of i value of i
i=7 (now the sum = 21) i=4 (now the sum = 7)
Is i<=10 true? Is i<=10 true?
Yes, do this Yes, do this
sum = sum + i = 21 + 7 = 28 sum = sum + i = 7 + 4= 11
value of i value of i
i=8 (now the sum = 28) i=5 (now the sum = 11)
Is i<=10 true? Is i<=10 true?
Yes, do this Yes, do this
sum = sum + i = 28 + 8 = 36 sum = sum + i = 11 + 5= 16
value of i value of i
i=9 (now the sum = 36) i=6 (now the sum = 16)
Is i<=10 true? Is i<=10 true?
Yes, do this Yes, do this
sum = sum + i = 36 + 9 = 45 sum = sum + i = 16 + 6 = 22
value of i
i=10 (now the sum = 45) value of i
Is i<=10 true? i=7 (now the sum = 22)
Yes, do this Is i<=10 true?
sum = sum + i = 45 + 10 = 55 Yes, do this
stops because the condition is i<=10 sum = sum + i = 22 + 7 = 29
The printf statement i.e., printf("sum of the first 10 value of i
digits =%d", sum); make provision to display the i=8 (now the sum = 29)
output: Is i<=10 true?
sum of the first10 digits = 55 Yes, do this
on the screen. sum = sum + i = 29 + 8 = 37
value of i
If the statement int i, sum = 0; is replaced by int i, sum i=9 (now the sum = 37)
= 1; Is i<=10 true?
Then Yes, do this
value of i sum = sum + i = 37 + 9 = 46
54
value of i
i=10 (now the sum = 46) Program 3.5
Is i<=10 true?
Yes, do this C program to print the average of the first10 numbers
sum = sum + i = 46 + 10 = 56 using for loop statement
stops because the condition is i<=10
The printf statement i.e., printf("sum of the first10 #include<stdio.h>
digits =%d", sum); make provision to display the main()
output: {
sum of the first10 digits = 56 on the screen. int i, avg, sum = 0;
(wrong result because the sum of the first 10 digits is for( i=1; i<=10; i++)
55) sum = sum + i;
avg = sum/10;
What will be the output if the for loop statement for(i printf("sum of the first10 numbers =%d", sum);
=1; i<=10; i++) is replaced by the statement for(i =2;
printf("average of the first10 numbers =%d", avg);
i<10; i++)?
}
The output on the screen:
Answer: sum of 10 digits = 44
sum of the first 10 numbers = 55
average of the first10 numbers = 5
If the statement int i, sum, sum = 0; is written instead
of int i, sum = 0; The average of the first10 numbers = 55/10 = 5.5 not
5. But the output on the screen is:
Then the compilation error message will be displayed
on the screen (stating that sum is twice declared). average of the first 10 numbers = 5
If the for loop is ended with a semicolon i.e., because int is used instead of float.
for( i=1; i<=10; i++);
then the compilation error will be displayed on the If the data type float is used i.e.,
screen #include<stdio.h>
main()
Note: {
sum = sum + a; is the same as sum + = a; float i, avg, sum = 0;
sub = sub- a; is the same as sub - = a; for( i=1; i<=10; i++)
product = product* a; is the same as product * = a; sum = sum + i;
div = div / a; is the same as div /= a; avg = sum/10;
a = a% b; is the same as a % = b; printf("sum of the first10 numbers =%f", sum);
printf("average of the first10 numbers = %f", avg);
Even though if i ++ is replaced by ++ i in the for loop }
statement i.e., if the for loop statement The output on the screen:
for (i=1; i<=10; i++) sum of the first10 numbers = 55
is replaced by the statement average of the first 10 numbers = 5.5
for (i=1; i<=10; ++ i)
There will be no change in the output on the screen (as Program 3.6
observed while compiling in online compilers like
Coding ground (Tutorials point)) and if the statement C program to print the product of the first10 digits
for ( i=1; i<=10; i++); is written instead of the using for loop statement
statement
for (i=1; i<=10; i++)
#include<stdio.h>
Then the Error will be flagged on the screen because
main()
for loop statement is ended by a semicolon (;).
55
{ value of i
int i, product = 1; i=7 (now the product =720)
for( i=1; i<=10; i++) Is i<=10 true?
product = product * i; Yes, do this
printf("the product of the first 10 digits =%d", product = product * i = 720 * 7 = 5040
product); value of i
} i=8 (now the product =5040)
The output on the screen: Is i<=10 true?
the product of the first 10 digits = 3628800 Yes, do this
i.e., 1 * 2 * 3 * 4 * 5 * 6 * 7 * 8 * 9 * 10 = 3628800 product = product * i = 5040 * 8 = 40320
value of i
How the product of the first 10 digits = 3628800 is i=9 (now the product = 40320)
outputted on the screen through the for Loop Is i<=10 true?
statement
Yes, do this
product = product * i = 40320 * 9 = 362880
value of i
value of i
i=1 (product = 1 because the product is initialized to 1
i=10 (now the product = 362880)
in the statement int i, product = 1;)
Is i<=10 true?
Is i<=10 true?
Yes, do this
Yes, do this
product = product * i = 362880 * 10 = 3628800
product = product * i = 1 * 1 =1
stops because the condition is i<=10
value of i
i=2 (now the product = 1)
The printf statement i.e., printf("the product of the
Is i<=10 true?
first 10 digits =%d", product); make provision to
Yes, do this display the output:
product = product * i = 1 * 2 = 2 the product of the first 10 digits = 3628800
value of i on the screen.
i=3 (now the product = 2)
Is i<=10 true? If the statement int i, product = 1; is replaced by int i,
Yes, do this product = 0;
product = product * i = 2 * 3 = 6 Then
value of i value of i
i=4 (now the product = 6) i=1 (product = 0 because the product is initialized to 0
Is i<=10 true? in the statement int i, product = 0;)
Yes, do this Is i<=10 true?
product = product * i = 6 * 4 = 24 Yes, do this
value of i product = product * i = 0 * 1 = 0
i=5 (now the product =24) value of i
Is i<=10 true? i=2 (now the product = 0)
Yes, do this Is i<=10 true?
product = product * i = 24 * 5 =120 Yes, do this
value of i product = product * i = 0 * 2 = 0
i=6 (now the product =120) value of i
Is i<=10 true? i=3 (now the product = 0)
Yes, do this Is i<=10 true?
product = product * i = 120 * 6 = 720 Yes, do this
56
product = product * i = 0 * 3 = 0 If the statement for(i=1; i<=10; i++) is replaced by
value of i for(i=5; i<=8; i++)
i=4 (now the product = 0) Then
Is i<=10 true? value of i
Yes, do this i=5 (product = 1 because the product is initialized to 1
product = product * i = 0 * 4 = 0 in the statement int i, product = 1;)
value of i Is i<=8 true?
i=5 (now the product = 0) Yes, do this
Is i<=10 true? product = product * i = 5 * 1 = 5
Yes, do this value of i
product = product * i = 0 * 5 = 0 i=6 (now the product = 5)
value of i Is i<=8 true?
i=6 (now the product = 0) Yes, do this
Is i<=10 true? product = product * i = 5 * 6 = 30
Yes, do this value of i
product = product * i = 0 * 6 = 0 i=7 (now the product = 30)
value of i Is i<=8 true?
i=7 (now the product = 0) Yes, do this
Is i<=10 true? product = product * i = 30 * 7 = 210
Yes, do this value of i
product = product * i = 0 * 7 = 0 i=8 (now the product = 210)
value of i Is i<=8 true?
i=8 (now the product = 0) Yes, do this
Is i<=10 true? product = product * i = 210 * 8 = 1680
Yes, do this stops because the condition i<=8 is achieved and the
statement
product = product * i = 0 * 8 = 0
printf("the product of the first 10 digits =%d",
value of i
product);
i=9 (now the product = 0)
make provision to display the output:
Is i<=10 true?
the product of the first 10 digits = 1680
Yes, do this
on the screen.
product = product * i = 0 * 9 = 0
value of i
Note: If the statement
i=10 (now the product = 0)
int i, product, product = 1;
Is i<=10 true?
is written instead of int i, product = 1;
Yes, do this
Then the compilation error message is flagged on the
product = product * i = 0 * 10 = 0 screen (stating that product is twice declared).
stops because the condition is i<=10
The printf statement i.e., printf("the product of the Program 3.7
first 10 digits = %d", product); make provision to
display the output:
C Program to print the table of a number using the for
the product of the first 10 digits = 0
loop statement
on the screen.
#include<stdio.h>
(wrong result because the product of the first10 digits
main()
is 3628800)
{
int n, i;
printf("Enter any number:");
57
scanf("%d", &n); 2*4=8
for( i=1; i<=5; i++) using the statement printf("%d * %d = %d\n", n, i,
printf("%d * %d = %d\n", n, i, n*i); n*i);
}
The output on the screen: value of i
Enter any number: i=5
If you enter the number 2 (i.e., n=2) Is i<=5 true?
2*1=2 Yes, print this
2*2=4 2 * 5 = 10
2*3=6 using the statement printf("%d * %d = %d\n", n, i,
2*4=8 n*i);
2 * 5 = 10
will be outputted on the screen. stop Now because the condition i <=5 is achieved.
How the execution takes its Way through the for If the symbol * is replaced by +
Loop statement i.e.,
#include<stdio.h>
Since you entered the number 2, therefore: n=2. main()
value of i {
i=1 int n, a;
Is i<=5 true? printf("Enter any number:");
Yes, print this scanf("%d", &n);
2*1=2 for( i=1; i<=5; i++)
using the statement printf("%d * %d = %d\n", n, i, printf("%d + %d = %d\n", n, i, n+ i);
n*i); }
The output on the screen:
value of i Enter any number:
i=2 If you enter the number 2 (i.e., n=2)
Is i<=5 true?
Yes, print this 2+1=3
2*2=4 2+2=4
using the statement printf("%d * %d = %d\n", n, i, 2+3=5
n*i); 2+4=6
2+5=7
value of i will be outputted on the screen.
i=3
Is i<=5 true? Program 3.8
Yes, print this
2*3=6 C program:
using the statement printf("%d * %d = %d\n", n, i, If you enter a character M
n*i); Output must be: ch = M
value of i #include<stdio.h>
i=4 main()
Is i<=5 true? {
Yes, print this char M;
58
printf("Enter any character:"); M will be outputted on the screen.
scanf("%c", &M);
printf("ch=%c", M); If you replace the statement scanf("%c", &M); by the
} statement
The output on the screen: M = getchar();
Enter any character: and the statement printf("ch=%c", M);by the statement
If you enter the character M putchar (M); i.e.,
ch = M will be outputted on the screen.
#include<stdio.h>
Note: main()
getchar() function is simplified version of the scanf {
function char M;
printf("Enter any character:");
If we replace the statement scanf("%c", &M); by the M = getchar();
statement putchar (M);
M = getchar(); }
i.e., The output on the screen:
#include<stdio.h> Enter any character:
main() If you enter the character S
{ S will be outputted on the screen.
char M;
printf("Enter any character:"); Program 3.9
M = getchar();
printf("ch=%c", M); C program to print the first 5 numbers starting from
} one together with their squares.
There will be no change in the output on the screen
i.e., The output on the screen is: #include<stdio.h>
Enter any character: main()
If you enter the character K {
ch = K will be outputted on the screen. int i;
for( i=1; i<=5; i++)
putchar() function is simplified version of the printf printf("number=%d its square=%d\n", i , i*i);
function }
If we replace the statement printf("ch=%c", M);by the The output on the screen:
statement putchar (M); i.e., number=1 its square=1
#include<stdio.h> number=2 its square=4
main() number=3 its square=9
{ number=4 its square=16
char M; number=5 its square=25
printf("Enter any character:");
scanf("%c", &M); How the execution takes its way through the for
putchar (M); loop statement
}
There will be no change in the output on the screen value of i
i.e., The output on the screen is: i=1
Enter any character: Is i<=5 true?
If you enter the character M
59
Yes, print this number=1 its square=1
number=1 its square=1 number=2 its square=4
using the statement printf("number=%d its number=3 its square=9
square=%d\n", i , i*i); number=4 its square=16
number=5 its square=25
value of i tab /t is included because to leave space between
i=2 number=1 and its square=1
Is i<=5 true?
Yes, print this Suppose printf("number=%d its square=%d", a , a*a);
number=2 its square=4 is replaced by the statement
using the statement printf("number=%d its printf("number=%d\n its square=%d\n", a , a*a);
square=%d\n", i , i*i); Then the output on the screen is:
number=1
value of i its square=1
i=3 number=2
Is i<=5 true? its square=4
Yes, print this number=3
number=3 its square=9 its square=9
using the statement printf("number=%d its number=4
square=%d\n", i , i*i); its square=16
number=5
value of i its square=25
i=4 And if you replace the printf statement
Is i<=5 true? printf("number=%d its square=%d", a , a*a); by the
Yes, print this statement
number=4 its square=16 printf("number=%d\n, its square=%d\n", a , a*a);
using the statement printf("number=%d its i.e., if you place variable separator ( i.e., comma)
square=%d\n", i , i*i); between number=%d\n and its square=%d\n
Then the compilation error will be displayed on the
value of i screen.
i=5
Is i<=5 true? Write a program to print the first 10 numbers starting
Yes, print this from one together with their squares and cubes?
number=5 its square=25
using the statement printf("number=%d its Answer:
square=%d\n", i , i*i);
value of i #include<stdio.h>
i=6 main()
Is i<=5 true? {
No, stop Now int i;
for( i=1; i<=10; i++)
Note: printf("number=%d its square=%d its cube=%d\n", i ,
If the statement i*i, i*i*i);
printf("number=%d its square=%d\n", i , i*i); is }
replaced by the statement
printf("\n number=%d/t its square=%d", i , i*i); What is the mistake in the following program:
then the output on the screen is:
60
#include<stdioh> x = 1;
main() p = &x;
{ printf("The address of the variable x =%d", p);
int i; printf("The value of the variable x =%d", *p);
for( i=1; i=5; i++) }
printf(“number=%d, its square=%d\n”, i ; i*i*i); The output on the screen:
} The address of the variable x = 0x7fffc60478a4
The value of the variable x = 1
Simula, an object-oriented language, was written by Since p = &x:
Kristen Nygaard and Ole-John Dahl at the Norwegian *p= *&x
Computing Center. Based largely on the Algol 60
programming language, Simula grouped data and The value of the variable x = 1 because you have
instructions into blocks called objects, each represented assigned a value to the variable x by declaring the
one facet of a system intended for simulation. In addition statement x=1; within the body of the main function
to simulation, Simula also had applications in computer
graphics, process control, scientific data processing and
If the statements
other fields.
printf("The address of the variable x =%d", p);
Program 4.0 printf("The value of the variable x =%d", *p);
are replaced by the statement
C program to print the sum of two numbers using printf("The address of the variable x =%d and its
pointers value =%d", p,*p);
i.e.,
If we create a integer variable x by declaring the #include <stdio.h>
statement int x; within the body of the main function main()
main() -- this variable is stored in the computer {
memory i.e., this variable occupies a specific location int x, *p;
in the space of computer memory. And this integer x=1;
variable x is assigned an address (i.e., &x) to locate its
position in the computer memory (like a house in the p = &x;
street is assigned an address to locate its position in printf("The address of the variable x =%d and its
the street). Pointers are the variables that represent the value =%d", p,*p);
address of x in the computer memory i.e., p = &x, }
where &x imply the address of x in the computer Then the output on the screen is:
memory and p is the pointer variable (which is the The address of the variable x = 0x7fffc60478a4and its
variable that represent the address of x in the computer value = 1
memory). And further if you assign a value to the
variable x by declaring the statement x=1; within the
body of the main function—this value is stored in the #include <stdio.h>
address of x in the computer memory. “*” denote main()
pointer operator and *p denote the pointer (which {
represent the value stored in the address of x in the int x, y, *p, *q, sum;
computer memory). printf("Enter any number:");
scanf("%d", &x);
C program to print the address of x and the value printf("Enter any number:");
assigned to x
scanf("%d", &y);
p = &x;
#include <stdio.h>
q = &y;
main()
sum = *p + *q;
{
printf("Sum of entered numbers = %d\n", sum);
int x, *p;
61
} subtract of entered numbers = 2
The output on the screen: division of entered numbers = 2
Enter any number: will be outputted on the screen.
If you enter the number 2
Enter any number: C program to find the greatest of two numbers using
If you enter the number 3 pointers
Sum of entered numbers = 5 will be outputted on the
screen. #include<stdio.h>
main()
Since pointer *p imply the value assigned to the {
variable x (i.e., 2) through the keyboard and the int x, y, *p, *q;
pointer *q imply the value assigned to the variable y printf("Enter any integer:");
(i.e., 3) through the keyboard. Therefore:
scanf("%d", &x);
sum = *p + *q = 2 + 3 = 5 (which will be outputted on
printf("Enter any integer:");
the screen)
scanf("%d", &y);
p = &x;
“A C program is like a fast dance on a newly waxed
dance floor by people carrying razors.” q = &y;
if(*p>*q)
- Waldi Ravens. {
printf("x is greater than y");
C program to print the product, subtraction and }
division of two numbers using pointers if(*q>*p)
{
#include <stdio.h> printf("y is greater than x");
main() }
{ }
int x, y, *p, *q, product, subtract, div; The output on the screen:
printf("Enter any number:"); Enter any integer:
scanf("%d", &x); If you enter the integer 10
printf("Enter any number:"); Enter any integer:
scanf("%d", &y); If you enter the integer 16
p = &x; y is greater than x will be outputted on the screen.
q = &y;
product = *p * *q; What is the mistake in the following program:
subtract = *p - *q;
div= *p / *q; #include <stdio.h>
printf("product of entered numbers = %d\n", product); main()
printf("subtract of entered numbers = %d\n", subtract); {
printf("division of entered numbers = %d\n", div); int x;
} x= 0;
The output on the screen: printf("size of x = %d", size of (x));
Enter any number: }
If you enter the number 4
Enter any number: What is the output of the following programs:
If you enter the number 2
product of entered numbers = 8 #include <stdio.h>
62
main() The statement int add (int x, int y); imply function
{ declaration (i.e., we are declaring a function int add
int x; (int x, int y) to add two integers x and y).
x=12; main() imply main function and
printf("per = %d%", x); {
} } imply the body of main function in which the
program statements:
int x, y;
#include <stdio.h>
printf("Enter any integer:");
main()
scanf("%d", &x);
{
printf("Enter any integer:");
int x, t, c;
scanf("%d", &y);
x=12;
result = add (x, y);
t=2;
printf("sum of two numbers=%d", result);
c = x/t;
are written.
printf("velocity = %d m/s", c);
}
int add (int x, int y) imply function to add two integers
x and y and
Program 4.1
{
return x + y;
C program to print the sum of two numbers using
}imply the body of function int add (int x, int y)
functions
63
If the statement int add (int x, int y); is written instead If you enter the integer 5
of int add (int x, int y) product of two numbers = 15 will be outputted on the
i.e., screen.
#include<stdio.h>
int add (int x, int y); C program to print the greatest of two numbers using
main() functions
{
int x, y; #include<stdio.h>
printf("Enter any integer:"); int max (int x, int y);
scanf("%d", &x); main()
printf("Enter any integer:"); {
scanf("%d", &y); int x, y;
result = add (x, y); printf("Enter any integer:");
printf("sum of two numbers=%d", result); scanf("%d", &x);
} printf("Enter any integer:");
int add (int x, int y); scanf("%d", &y);
{ result =max (x, y)
return x + y; printf("largest of two numbers=%d", result);
} }
Then the error is displayed on the screen. int max (int x, int y)
If the statement int add (intx, inty); is written instead {
of int add (int x, int y); i.e., no space is left between if(x>y)
int and x ( and int and y) return x;
Then the compilation error is displayed on the screen. if(y>x)
return y;
C program to print the product of two numbers using }
functions The output on the screen:
Enter any integer:
#include<stdio.h> If you enter the integer 3
int mult (int x, int y); Enter any integer:
main() If you enter the integer 5
{ largest of two numbers= 5 will be outputted on the
int x, y; screen.
printf("Enter any two integers:");
scanf("%d %d", &x, &y); C program to print the greatest of three numbers using
result = mult (x, y); functions
printf("product of two numbers=%d", result);
} #include<stdio.h>
int mult (int x, int y) int max (int x, int y, int z);
{ main()
return x + y; {
} int x, y, z;
The output on the screen: printf("Enter any integer:");
Enter any integer: scanf("%d", &x);
If you enter the integer 3 printf("Enter any integer:");
Enter any integer: scanf("%d", &y);
64
printf("Enter any integer:"); What is the output of the following program:
scanf("%d", &z);
result = max (x, y, z) #include<stdio.h>
printf("largest of three numbers=%d", result); main()
} {
int max (int x, int y, int z) int x;
{ x=6;
if(x>y&& x>z) printf("The address of x = %d", &x);
return x; }
if(y>x&& y > z)
return y; Program 4.2
if(z>x && z>y)
return z; Switch (case) allows to make decision from the
} number of choices i.e., from the number of cases
The output on the screen: For example:
Enter any integer:
If you enter the integer 3 #include<stdio.h>
Enter any integer: main()
If you enter the integer 5 {
Enter any integer: char ch;
If you enter the integer 10 printf("Enter any character:");
largest of three numbers = 10 will be outputted on the scanf("%c", &ch);
screen. switch(ch)
{
C program to print the square of the number using case 'R':
functions printf("Red");
break;
#include<stdio.h> case 'W':
int square (intx); printf("White");
main() break;
{ case 'Y':
int x; printf("Yellow");
printf("Enter any integer:"); break;
scanf("%d", &x); case 'G':
printf("square of the number=%d", square (x)); printf("Green");
} break;
int square (int x) default:
{ printf("Error");
return x*x; break;
} }
The output on the screen is: }
Enter any integer: The output on the screen:
If you enter an integer 5 Enter any character:
square of the number = 25 will be outputted on the If you enter a character R
screen.
Red will be outputted on the screen.
65
switch(ch) allow to make decision from the number of case 'R':
choices i.e., from the number of cases printf("Red");
case 'R': case 'W':
case 'W': printf("White");
case 'Y': case 'Y':
case 'G': printf("Yellow");
Since we have entered the character R (which break;
corresponds to case 'R':) case 'G':
The statement printf("Green");
printf("Red"); break;
make provision to display the output default:
Red printf("Error");
on the screen. break;
Suppose you enter a character K }
The output on the screen is: i.e., if the statement break; is not written after the
Error statements
(Entered character K does not correspond to any of the case 'R':
cases printf("Red");
case 'R':
case 'W': case 'W':
case 'Y': printf("White");
case 'G': Then the output on the screen is:
Therefore the statements Red
default: White
printf("Error"); make provision to display the output Yellow
Error i.e., the output will be printed till yellow even though
on the screen). you have entered the character R.
If the statements
{ “C makes it easy to shoot yourself in the foot; C++
case 'R': makes it harder, but when you do, it blows away your
printf("Red"); whole leg.”
break;
case 'W': -- Bjarne Stroustrup
printf("White");
break; Program 4.3
case 'Y':
printf("Yellow"); C program to print the output
break; Element [0] = 16
case 'G': Element [1] = 18
printf("Green"); Element [2] = 20
break; Element [3] = 25
default: Element [4] = 36
printf("Error"); using arrays:
break;
} are replaced by the statements #include<stdio.h>
{ main()
66
{ with the square brackets [ ] needs to be taken from a
int i; variable (which is i i.e., i=0) and the format string %d
int num [5] = {16, 18, 20, 25, 36}; after the statement (\n Element [%d] = ) indicates that
the value to be displayed at that point in the string i.e.,
for(i=0; i<5; i++)
after the statement (\n Element [%d] = ) needs to be
printf("\n Element [%d] = %d", i, num[i]); taken from a variable (which is stored in num[i] i.e.,
} num[0] i.e., 16).
The statement int num [5] = {16, 18, 20, 25, 36}; format string %d in the square brackets indicates that
imply that we are creating an integer array (and the the value to be displayed at that point in the string i.e.,
name of array is num) consisting of 5 values (i.e., 16, with the square brackets [ ] needs to be taken from a
18, 20, 25, 36) of the same data type int. And the variable (which is i i.e., i=1) and the format string %d
number of values between the braces { } cannot be after the statement (\n Element [%d] = ) indicates that
larger than the number of values that we declare for the value to be displayed at that point in the string i.e.,
the array between square brackets [ ]. Because there after the statement (\n Element [%d] = ) needs to be
are 5 integers i.e., 16, 18, 20, 25, 36 within the braces taken from a variable (which is stored in num[i] i.e.,
{ }, 5 is written within the square brackets [ ]. If there num[1] i.e., 18).
were 6 integers i.e., 16, 18, 20, 25, 36, 42 within the
braces { }, then 6 must be written within the square
value of i
brackets [ ].
i=2
Is i<5 true?
Note: With the declaration int num [5], computer
creates 5 memory cells with name num[0], num[1], Yes, print this
num[2], num[3], num[4]. And since Element [2] = 20
int num [5] = {16, 18, 20, 25, 36}; using the statement
the values 16, 18, 20, 25, 36 are stored in num[0], printf("\n Element [%d] = %d", i, num[i])
num[1], num[2], num[3], num[4] respectively.
format string %d in the square brackets indicates that
How the execution takes its way through the for the value to be displayed at that point in the string i.e.,
loop statement with the square brackets [ ] needs to be taken from a
variable (which is i i.e., i=2) and the format string %d
after the statement (\n Element [%d] = ) indicates that
value of i
the value to be displayed at that point in the string i.e.,
i=0 after the statement (\n Element [%d] = ) needs to be
Is i<5 true? taken from a variable (which is stored in num[i] i.e.,
Yes, print this num[2] i.e., 20).
Element [0] = 16
using the statement value of i
printf("\n Element [%d] = %d", i, num[i]) i=3
Is i<5 true?
format string %d in the square brackets indicates that Yes, print this
the value to be displayed at that point in the string i.e., Element [3] = 25
67
using the statement Element [2] = 18
printf("\n Element [%d] = %d", i, num[i]) Element [3] = 18
Element [4] = 18
format string %d in the square brackets indicates that
the value to be displayed at that point in the string i.e., Suppose the statement printf("\n Element [%d] = %d",
with the square brackets [ ] needs to be taken from a i, num[i]); is replaced by the statement
variable (which is i i.e., i=3) and the format string %d printf("\n Element [%d] = %d", i, num[2]);
after the statement (\n Element [%d] = ) indicates that
i.e., num[2] corresponds to the output:
the value to be displayed at that point in the string i.e.,
after the statement (\n Element [%d] = ) needs to be Element [0] = 20
taken from a variable (which is stored in num[i] i.e., Element [1] = 20
num[3] i.e., 25). Element [2] = 20
Element [3] = 20
value of i Element [4] = 20
i=4
Is i<5 true? Suppose the statement printf("\n Element [%d] = %d",
Yes, print this i, num[i]); is replaced by the statement
Element [4] = 36 printf("\n Element [%d] = %d", i, num[3]);
using the statement i.e., num[3] corresponds to the output:
printf("\n Element [%d] = %d", i, num[i]) Element [0] = 25
Stop because the condition is i<5. Element [1] = 25
Element [2] = 25
format string %d in the square brackets indicates that Element [3] = 25
the value to be displayed at that point in the string i.e., Element [4] = 25
with the square brackets [ ] needs to be taken from a
variable (which is i i.e., i=4) and the format string %d Suppose the statement printf("\n Element [%d] = %d",
after the statement (\n Element [%d] = ) indicates that i, num[i]); is replaced by the statement
the value to be displayed at that point in the string i.e.,
after the statement (\n Element [%d] = ) needs to be printf("\n Element [%d] = %d", i, num[4]);
taken from a variable (which is stored in num[i] i.e., i.e., num[4] corresponds to the output:
num[4] i.e., 36). Element [0] = 36
Element [1] = 36
Suppose the statement printf("\n Element [%d] = %d", Element [2] = 36
i, num[i]); is replaced by the statement Element [3] = 36
printf("\n Element [%d] = %d", i, num[0]); Element [4] = 36
Then the output on the screen:
Element [0] = 16 If i<=5 i.e., if the for loop statement was
Element [1] = 16 for(i=0; i<=5; i++)
Element [2] = 16 Then the output on the screen is:
Element [3] = 16 Element [0] = 16
Element [4] = 16 Element [1] = 18
Element [2] = 20
Suppose the statement printf("\n Element [%d] = %d", Element [3] = 25
i, num[i]); is replaced by the statement Element [4] = 36
printf("\n Element [%d] = %d", i, num[1]); Element [5] = 3656
The output on the screen: 3656 is the number stored in the memory i.e., any
Element [0] = 18 number stored in the memory will be displayed.
Element [1] = 18
68
If the statement int num [5] = {16, 18, 20, 25, 36}; is i=3 (now the sum = 54)
replaced by the statement int num [i] = {16, 18, 20, Is i<5 true?
25, 36}; Yes, do this
Then the compilation will be displayed on the screen sum = sum + num[i] = sum + num[3] = 54 +25 =79
because there are 5 elements within the braces {} not i
elements.
value of i
Note:
i=5 (now the sum = 79)
Is i<5 true?
(a) C program to print the sum of the elements in
array. Yes, do this
sum = sum + num[i] = sum + num[5] = 79 + 36 =115
#include<stdio.h> stops because the condition is i<5
main() The printf statement i.e., printf("Sum of the Elements
{ in the array = %d", sum); make provision to display
int i, sum = 0; the output:
int num [5] = {16, 18, 20, 25, 36}; Sum of the Elements in the array = 115
for(i=0; i<5; i++) on the screen.
sum = sum + num[i];
printf("Sum of the Elements in the array = %d", sum); If the statement
} int i, sum = 0; is replaced by int i, sum = 1;
The output on the screen: Then The output on the screen:
Sum of the Elements in the array = 115 Sum of the Elements in the array = 116
i.e., 16 + 18 + 20 + 25 + 36 = 115 (wrong result because the sum of 5 elements in the
array is 115).
How the Execution takes its way through the for
loop statement (b) C program to print the average of the elements in
array
value of i #include<stdio.h>
i=0 (sum = 0 because the sum is initialized to 0 in the main()
statement int i, sum = 0;)
{
Is i<5 true?
int i, avg, sum = 0;
Yes, do this
int num [5] = {16, 18, 20, 25, 36};
sum = sum + num[i] = sum + num[0] = 0 +16 =16
for(i=0; i<5; i++)
value of i
sum = sum + num [i];
i=1 (now the sum = 16)
avg = sum/5;
Is i<5 true?
printf("Sum of the Elements in the array = %d", sum);
Yes, do this
printf("average of the elements in the array= %d",
sum = sum + num[i] = sum + num[1] = 16 +18 =34 avg);
}
value of i The output on the screen:
i=2 (now the sum = 34) Sum of the Elements in the array = 115
Is i<5 true? average of the elements in the array = 23
Yes, do this
sum = sum + num[i] = sum + num[2] = 34 +20 =54 Write a program to print
69
Einstein [1] = I #include <stdio.h>
Einstein [2] = N main()
Einstein [3] = S {
Einstein [4] = T char i;
Einstein [5] = E char body [4] = {'b', 'o', 'd', 'y'};
Einstein [6] = I for(i=0; i<4; i++)
Einstein [7] = N printf("\n body[%c] = %c", body[i] , body[i]);
using arrays }
Answer: Answer:
body [b] = b
#include<stdio.h> body [o] = o
main() body [d] = d
{ body [y] = y
int i;
char name [8] = {' E' , ' I', ' N', ' S', ' T ', ' E', ' I', ' N'}; #include <stdio.h>
for(i=0; i<8; i++) main()
printf("\n Element [%d] = %c", i, name[i]); {
} int i;
char body [4] = {'b', 'o', 'd', 'y'};
Note: for(i=0; i<4; i++)
printf("\n body[%c] = %c", body[i] , body[i]);
If the format string %d is used instead of %c i.e., if the }
statement Answer:
printf("\n Element [%d] = %c", name[i], name[i]); is body [b] = b
written instead of the statement body [o] = o
printf("\n Element [%c] = %c", name[i], name[i]); body [d] = d
Then the output on the screen is: body [y] = y
Element [69] = E
Element [73] = I #include <stdio.h>
Element [78] = N #include <malloc.h>
Element [83] = S main()
Element [84] = T {
Element [69] = E int x=2;
Element [73] = I printf("%d", malloc ( 200*sizeof(x)));
Element [78] = N }
What will be the output of the following programs? What is the mistake in the following program:
70
} char name;
float price;
Answer: there is no mistake in the above program. int pages;
The output on the screen is: int edition;
}; imply the structure definition i.e., we are defining a
Element [0] = 16 structure (and the data type name of the structure is
Element [1] = 18 book) and it consists of elements: name (which is of
Element [2] = 20 data type char), price (which is of data type float),
pages (which is of data type int), edition (which is of
Element [3] = 25
data type int) – which are placed within the body of
Element [4] = 36 the structure.
71
make provision to print the output on the screen: printf("\n Price of the book = %f", b1.price);
Price of the book = 135.00 printf("\n Number of pages = %d", b1.pages);
on the screen. printf("\n Edition of the book = %d", b1.edition);
}
format string %d (corresponding to the data type int)
in the statement What will be the output of the following program?
printf("\n Number of pages = %d", b1.pages);
indicates that the value to be displayed at that point in #include<stdio.h>
the string i.e., after the statement (\n Number of pages main()
= ) needs to be taken from b1.pages.
{
int a, b, c;
The printf statement
a=2;
printf("\n Number of pages = %d", b1.pages);
b=2;
make provision to print the output on the screen:
c = a ^ b;
Number of pages = 300
printf( " the value of c = %d", c);
on the screen.
}
72
0 0 1 0 printf("\n address of speed of light c in the computer
0 0 1 0 memory = %d", &c);
0 0 0 0 int b, z, a;
b = sizeof(E);
0 × 8 + 0 × 4 + 0×2 + 0 × 1 = 0 z = sizeof(m);
a = sizeof(z);
a^b=0 printf("\n space occupied by E in the computer
memory = %d bytes", b);
printf("\n space occupied by m in the computer
What is the mistake in the following program:
memory = %d bytes", z);
printf("\n space occupied by c in the computer
#include<stdio.h> memory = %d bytes", a);
main() printf(" \n Suppose c would have been 3×10 to the
{ power of -8 meter per second then For 1 kg of mass E
int a, b; = 9 ×10 to the power of -16 joules");
a=2; printf(" \n hence thousands and thousands of hydrogen
printf( "the value of b = Rs %d", b); atoms in the sun would have to burn up to release 4 ×
} 10 to the power of 26 joules of energy per second in
the form of radiation");
int i;
Examine the following program and write the output:
for(i=0; i<5;i++)
printf(" \n Therefore sun would have ceased ");
#include <stdio.h>
printf("to form black hole even before an ooze of
#include<math.h> organic molecules would react and built earliest cells
#include<stdlib.h> and then advance to a wide variety of one celled
#include<ctype.h> organisms and evolve through a highly sophisticated
main() form of life to primitive mammals");
{ long int v;
printf(" \n E=mc squared Einstein's famous equation v=300000000;
that gave birth to the atom bomb and heralded a new c=300000000;
world of atomic physics"); if (v==c)
printf(" \n"); printf(" \n rest mass of the photon is zero because light
printf(" \n E = energy m = mass c = speed of light in travels at the speed of light");
vacuum"); else
printf(" \n As we know c squared is huge so if you printf(" \n Albert Einstein’s special theory of relativity
convert a small amount of mass you'll get a has to be rewritten");
tremendous amount of energy"); int E1;
printf(" \n For example if you convert 1kg of mass E1=2;
you'll get energy of ");
if (isalpha(E1))
long int E, m, c;
printf("\n Einstein’s equation does not hold good");
m=1;
else
c=300000000;
printf("\n Einstein’s equation holds good because light
E=m*c*c; has zero rest mass");
printf("\n %ld joules", E); printf("\n masses of the individual substances are 16 \t
printf("\n address of Energy E in the computer 18 \t 19 \t 20\t 21\t kilograms");
memory = %d", &E); int j, sum = 0;
printf("\n address of mass m in the computer memory int num [5] = {16, 18, 19, 20, 21};
= %d", &m);
for(j=0; j<5; j++)
73
sum = sum + num [j]; if (E>EP)
printf("\n sum of the masses of the individual printf ("\n hf can be equivalent to mc squared");
substances = %d", sum); if (E<EP)
printf("\n sum of the energies of the individual printf ("\n Einstein and Planck equation cannot be
substances = %ld", sum * 300000000 * 300000000); equalized");
printf("\n average energy = %f", sum / 5); printf ("\n ");
printf("\n printf ("\n ");
"); printf ("\n for more details please refer the book ");
printf("\n struct book {
");
char name;
int p, q, r;
float price;
p= 6;
int pages;
q= 3;
int edition;
printf("\n expected energy = %d multiplied by ten to
};
the power of minus 16 joules calculated using Einstein
equation", p); struct book b1;
printf("\n experimental energy = %d multiplied by ten b1.name = 'E';
to the power of minus 16 joules", q); b1.price = 135.00;
r= q-p; b1.pages = 300;
printf("\n difference between experimental energy and b1.edition = 8;
expected energy = %d multiplied by ten to the power printf("\n Name of the book = %cinsteinian physics",
of minus 16 joules", r); b1.name);
printf("\n absolute value of the difference between printf("\n Price of the book = %f", b1.price);
experimental energy and expected energy = %d printf("\n Number of pages = %d", b1.pages);
multiplied by ten to the power of minus 16 joules", printf("\n Edition of the book = %d th edition",
abs(r)); b1.edition);
char k; printf("**************************************
char einstein [10] ={'e', 'm', 'c', 's', 'q', 'u', 'a', 'r', 'e', 'd'}; *******\n");
for(k=0; k<10; k++) printf("**************************************
printf("\n Einstein[%c] = %c", einstein [k], einstein ******\n");
[k]); printf(" According to the Albert Einstein’s law of
int s; variation of mass with velocity: \n");
printf("\n Hey! Einstein may not be wrong please printf(" M = m0 / sqrt ((1- (u/c) squared) \n ");
repeat the experiment"); printf(" M = mass of the moving body \t m0 = rest
for(s=1; s<3; s++) mass of the body \t u= velocity of the body \t c= speed
printf("\n * "); of light in vacuum\n ");
printf("\n ***** "); {
printf("\n **Albert Einstein** "); double M, m0;
printf("\n **e= mc squared**"); long int u, c, b;
printf("\n *****"); m0 = 0.999;
double EP, h, f; u = 200000000;
f=2; c = 300000000;
h=pow((6.625), -34); b = u/c * u /c;
EP= h*f; M = m0 / sqrt (1 - b);
printf("\n energy calculated using the Planck equation printf(" \n Mass of the moving body = %lf", M);
= %lf", EP); if (M==m0 || M<m0)
if (E== EP) printf(" \n body is at rest or the body is moving with
printf("\n hf cannot be equivalent to mc squared"); nonrelativistic speed");
74
else works and to convince a reader that the results will be
printf(" \n body is moving with relativistic speed"); correct.”
}
} ― Donald Ervin Knuth, Selected Papers on Computer
Science
What will be the output of the following program:
IX
#include<stdio.h>
main() C++
{
char ch [5]; An object-oriented high level language (as C++ has
the power and extensibility to write large-scale
printf( "Enter the name: ");
programs) developed by a Danish computer scientist
scanf("%s", &ch); Bjarne Stroustrup (in 1979 at AT & T Bell
printf( "the name you entered = %s", ch); laboratories, USA) as an extension of the C language
} i.e., initially named C with classes which later named
C ++. As a successor of C language, C++ has been
Answer: certified as a 99.9 percent pure standard and possesses
exceptional performance, efficiency and flexibility of
use compared to C, used in the development of
The output on the screen: operating systems and Adobe Systems (like
Enter the name: Photoshop, Acrobat etc.).
If you enter the name Dennis
the name you entered = Denni will be outputted on the Process of C++ program execution: A C++ program:
screen. #include<iostream>
main()
Instead of Dennis, only Denni will be displayed on the {
screen because of the statement char ch [5];
std::cout<<"Hello, crazy world!";
The statement
} is written in C ++ editor and is saved as source
char ch [5]; program and this source program is sent to the C ++
make provision only for 5 lettered name to be compiler where the source program is compiled (i.e.,
displayed on the screen. the program is entirely read and translated to
If the statement char ch [5]; is replaced by the instructions the computer can understand i.e., machine
statement char ch [6]; understandable/ readable language i.e., to machine
Then the output on the screen is: code sequence of 0’s and 1’s). If the C ++ compiler
finds any error during compilation, it provides
Enter the name:
information about the error to the user. The
If you enter the name Dennis programmer has to review code and check for the
the name you entered = Dennis will be outputted on solution. And if there are no errors the translated
the screen. program is stored in computers main memory as
object file and the program is executed and
Note: %s implies the format specifier for string. Hello, crazy world!
is displayed on the screen. Like C language, C++ is
“The best programs are written so that computing also a case sensitive language: only lower case letters
machines can perform them quickly and so that human (or small letters) must be used. Capital letters (or
beings can understand them clearly. A programmer is upper case letters) must be avoided to prevent the
ideally an essayist who works with traditional display of error on the screen (For example: If the
aesthetic and literary forms as well as mathematical statement STD:: COUT<<"Hello, crazy world!"; is
concepts, to communicate the way that an algorithm written instead of std::cout<<"Hello, crazy world!"; or
MAIN() is written instead of main(), compilation
Error will be displayed on the screen). And if we
75
forget to end each statement within the curly braces{}
or each statement within the body of the main function } → body of the main function within which the
main() sequence of instructions in the form of statements i.e.,
{ the program is written and executed.
} with a semicolon (;), then the compilation Error will Note: if a program begins its execution with main
be displayed on the screen. There should be no space function “main()”, it takes the control of the computer
between main and the parentheses () and no space from the operating system. And after the complete
inside the parentheses () to prevent the display of execution of the program, the execution is terminated
compilation error on the screen. and the function main() returns back the control to the
operating system. Semicolon: program is a well-
defined set of instructions and each well-defined
#include <iostream> is to C++ what #include<stdio.h>
instruction (in the form of a statement) is ended by a
is to C (note one thing: there is no .h extension to the
semicolon (which is also C ++ language punctuation
name iostream. The reason is that <iostream> is one of
— like a period in English i.e., in an English
the modern – style headers) → if we type a program (a
paragraph each sentence is ended by a full stop which
well-defined set of instructions in the form of
tells that one sentence ends and another begins,
statements) in C ++ editor, (as said earlier) the
semicolon implies that one instruction (or statement)
program is saved as source program and this source
ends and another begins).
program is sent to the C ++ compiler where the source
program is compiled i.e., it is translated into machine cout→ output function of the C++ language which
level language i.e., into a machine code sequence of make provision to print the output
0’s and 1’s (because computer can understand only Hello, crazy world!
machine level language). The statement #include on the screen.
<iostream> tells the complier to include the text from In std::cout
the file iostream (which is already present in the std → standard
operating system) before it translates or complies the
:: → scope resolution operator
program into a sequence of 0’s and 1’s. iostream
means input output screen (i→ input, o → output, cout→ console output
stream → screen) and iostream comprises input output std::cout basically means: look in standard library and
functions like cout, cin etc. — note: cin is a input get cout function. The sentence / text Hello, crazy
function (cin means console input) and cout is a world! should be enclosed by the double quotation
output function (cout means console output) and it is marks (" ") and if the statement using namespace std;
included into the C ++ program by writing the is added below #include<iostream> in the above
statement #include <iostream>). #include tell the program, then the cout statement std::cout<<"Hello,
compiler to include the contents of the file iostream crazy world!"; take the form:
before compilation. If a program is written without the cout<<"Hello, crazy world!";
statement #include<iostream>, then the C++ compiler i.e., no need to include std:: in the statement
can’t compile and a compilation error is displayed on std::cout<<"Hello, crazy world!"; i.e.,
the screen. #include<iostream>
main() →After the compilation of the source program, using namespace std;
the translated (or the complied) program is stored in
main()
the computer’s memory as object file and the program
is executed. The program begins its execution with the {
function main() (which is called the user defined cout<<"Hello, crazy world!";
function (function defined by the user) – the main }
function -- the entry point of the program execution The statement
i.e., the function from where the execution of C ++
cout<<"Hello, crazy world!";
program begins) . The left curly brace “{” implies the
beginning of the main function and the right curly make provision to display the output:
brace “}”implies the end of the main function Hello, crazy world!
main() → main function on the screen.
main() Note: if “ ” is used instead of " ", Error will be
{ displayed on the screen
76
The statement cout<<"Hello, crazy world!"; will not }
display any error on the screen.
The statement cout<<“Hello, crazy world!”; will (b) #include<iostream>
display error on the screen. main()
Past few years back, the statement return(0); was {
included in the body of the main function i.e.,
cout<< "Hello, crazy world!";
{
return (1);
cout<< "Hello, crazy world!";
}
return(0);
}
(c) #include<iostream>
But now due to the advancement of technology and
main()
emergence of advanced online compilers like
CodeChef (www.codechef.com/) {
& cout<<"Hello, crazy world!";
Coding Ground – TutorialsPoint return (-2);
(www.tutorialspoint.com/codingground.htm) }
-- without the statement return(0); the program is
compiled and executed without flag of any error on (d) #include<iostream>
the screen. However, as the execution encounters the main()
statement return (0); the execution stops and the main {
function ends at “}” and the main function returns
cout<<"Hello, crazy world!";
back the control to the operating system.
return;
The abacus (plural abaci or abacuses), also called a }
counting frame, is a calculating tool that was in use in
Europe, China and Russia, centuries before the adoption The output on the screen is:
of the written Hindu–Arabic numeral system and is still
Hello, crazy world!
used by merchants, traders and clerks in some parts of
Eastern Europe, Russia, China and Africa. i.e., there will be no change in the output on the
screen.
Note:
Program 4.4
If the statement return (0); is replaced by the statement
return 0; C ++ program to print the word “hello Steve Jobs” on
screen
or
return (1);
#include<iostream>
or
using namespace std;
return(-2);
main()
or
{
return;
cout<< "hello Steve Jobs ";
there will be no change in the output on the screen
(and no error will be flagged or displayed on the }
screen) i.e., for the programs
The output on the screen:
(a) #include<iostream> hello Steve Jobs
main() Note: (As said earlier) Like the header file stdio.h in
{ C, iostream has no extension i.e., if you write
#include< iostream.h> instead of #include< iostream>
cout<<"Hello, crazy world!";
the compilation ERROR will be flagged on the screen.
return 0;
77
*******
Even if ****
main(void) is written instead of main() *
int main is written instead of main() (b)
No error will be displayed on the screen.
hello Bill Gates will be outputted on the screen. ****************
**
Unlike in C language, if * Hello World! *
void main is written instead of main() **
main(computer) is written instead of main() ****************
main(comp2016) is written instead of main()
Error will be flagged on the console screen. (c)
#include<iostream> Answers:
using namespace std;
main() #include<iostream>
{ using namespace std;
cout<<"\n * "; main()
cout<<"\n **Hi Silicon Valley** "; {
cout<<"\n ***** "; cout<< "\n * ";
cout<<"\n ***** "; cout<< "\n **** ";
} cout<< "\n ******* ";
The output on the screen: cout<< "\n **** ";
* cout<< "\n * ";
**Hi Silicon Valley** }
*****
***** #include<iostream>
If \n is not included in the above program then the using namespace std;
output on the screen is: main()
***Hi Silicon Valley************ {
cout<<"\n **************** ";
Write a program to print the following outputs: cout<<"\n ** ";
cout<<"\n * Hello World! * ";
(b) cout<<"\n ** ";
cout<<"\n **************** ";
* }
****
78
#include<iostream> The statement area = 4 × 3.14 × r × r; is written
using namespace std; instead of area = 4 * 3.14 * r * r
main() then the compilation error is displayed on the screen.
{ Like the statement
cout<< "\n Braces come in pairs!"; printf("The area of the circle = %d", area);
cout<<"\n Comments come in pairs!"; in C language
cout<<"\n All statements end with a semicolon!"; The statement
cout<< "\n No format strings are used"; cout<<"The area of the circle = " << area;
cout<<"\n Must have a main function!"; make provision to print the output:
cout<<"\n Object oriented language"; The area of the circle = 50
cout<<"\n Like C C++ is done mostly in lowercase. on the screen (in the case of C++ language). Notice
It’s also a case-sensitive language"; one thing there is no need to write format strings in
} the C ++ language.
Program 4.5 The area of the circle is 50. 24 ( for r = 2) but The area
of the circle = 50 is displayed on the screen because
data type int is used instead of float.
C ++ program to find the area of a circle
If float r, area; is used instead of int r, area;
i.e.,
#include<iostream>
#include<iostream>
using namespace std;
using namespace std;
main()
main()
{
{
int r, area;
float r, area;
r = 2;
r = 2;
area = 4 * 3.14 * r * r;
area = 4 * 3.14 * r * r;
cout<<"The area of the circle = " << area;
cout<<"The area of the circle = " << area;
}
}
The output on the screen:
Then the output on the screen:
The area of the circle = 50
The area of the circle = 50.24
The statement
The statement
int r, area; imply that we are creating the integer
float r, area; imply that we are creating the
variables r , area.
floating variables r, area.
The statements
(floating point variable means fractional variable or
r = 2; decimal number (for example: 1.5, 2.5, 3.5, 4.7…etc.)
area = 4 * 3.14 * r * r; whereas integer means non-fractional variable or
imply that we are assigning the values to the created whole number (for example: 1, 2, 3, 4…etc.))
variables (i.e., we are assigning the value 2 for r and 4
* 3.14 * r * r for area). data type float is used instead of int because if the data
Comma in the statement int r, area; imply variable type int is used instead of float then the result will not
separator. be clearly outputted i.e., instead of 50.24 the computer
If the multiplication sign × is used instead of the displays only 50.
multiplication operator * i.e.,
79
If you want to supply the value for r through the key Left shift operator << denote stream insertion operator
board, then the statement (insert data into an output screen)
float r = 2; << and >> are termed overloaded operators and the
is replaced by the statements file iostream defines these operators.
cout<< "Enter any number:";
cin>>r; Note: As told earlier: when you enter an integer for x
i.e., through the keyboard, this integer will be stored in the
computer memory. If you yearn to know the storage
#include<iostream>
size of the integer in computer memory (i.e., space
using namespace std; occupied by the entered integer in the computer
main() memory), you need to appeal to the following
{ program:
float r, area;
cout<< "Enter any number:"; #include<iostream>
cin>>r; using namespace std;
area = 4 * 3.14 * r * r; main()
cout<<"The area of the circle = " << area; {
} int x;
The output on the screen: x=10;
Enter any number: cout<<"size of x = " << sizeof(x);
If you the number 2 }
The area of the circle = 50.24 will be outputted on the The output on the screen:
screen. size of x = 4
As told earlier: cout is an output function and cin is an i.e., integer entered for x i.e., 10 has occupied a space
input function. of 4 bytes in the computer memory.
The statement cout<< "Enter any number:"; make
provision to print the sentence / text Write a program to print the circumference of the
Enter any number: circle (given r = 2.5)
on the screen.
cin>> r; is to C++ what scanf("%d", &r); is to C Answer:
If you write area = 4 * 3.14 * r ^ 2; instead of area = 4 #include<iostream>
* 3.14 * r * r; (where r ^ 2 → r to the power of 2 or r using namespace std;
square), then error is displayed on the screen because
main()
like in C– there is no operator for performing
exponentiation operation i.e., there is no operator for {
performing r ^ 2 operation so the statement area = 4 * float r, area;
3.14 * r ^ 2; is invalid. r = 2.5;
circumference = 3.14 * r * r;
Note: cout and cin are not part of C++ language but cout<< "The circumference of the circle = " <<
they are part of input output file i.e., (iostream file) so circumference;
the statement #include<iostream> should be included }
in the C++ program otherwise cout and cin will not
work and the compilation error will be displayed on
Write a program to print the area of the rectangle
the console screen.
(given l = 2.5 and b = 3)
Note:
Answer:
Right shift operator >> denote stream extraction
#include<iostream>
operator (extract data entered through the keyboard)
using namespace std;
80
main() }
{
float l, b, area; Program 4.6
l = 2.5;
b = 3; C++ program to find the sum of two numbers
area = 1*b;
cout<< "The area of the rectangle = " << area; #include<iostream>
} using namespace std;
main()
What is the mistake in the following programs? {
int a, b, sum;
(a) a=1;
b=2;
#include<iostream> sum = a + b;
using namespace std; cout<<"the sum of a and b = "<< sum;
main() }
{ The output on the screen:
float r, area; the sum of a and b = 3
cout>>"Enter any number: "; If you assign the floating point values 1.5 & 2.6 for a
cin << r; & b, then the statement int a, b, sum; should be
area = 4 * 3.14 * r * r; replaced by the statement float a, b, sum;
cout >> "The area of the circle = " >> area; i.e.,
} #include<iostream>
using namespace std;
(b) main()
{
#include<iostream> float a, b, sum;
main() a=1.5;
{ b=2.6;
int l; area; sum = a + b;
cout<< “Enter any number:”; cout<<"the sum of a and b = "<< sum;
cin >> r; }
area = l × l; The output on the screen:
cout<< “The area of the square = ” << area; the sum of a and b = 4.1
} The statement
cout<<"the sum of a and b = "<< sum;
(c) make provision to print the output:
81
a=1.5; {
b=2.6; float a, b, sum;
should be replaced by the statements cout<<"Enter any number:";
cout<<"Enter any two numbers:"; cin>>a;
cin>>a; cout<<"Enter any number:";
cin>>b; cin>>b;
i.e., sum = a+ b;
#include<iostream> cout<<"the sum of a and b = "<< sum;
using namespace std; }
main() The output on the screen:
{ Enter any number:
float a, b, sum; If you enter the number 2.9
cout<<"Enter any two numbers:"; Enter any number:
cin>>a; If you enter the number 3.6
cin>>b; the sum of a and b = 6.5 will be outputted on the
sum = a+ b; screen.
cout<<"the sum of a and b = "<< sum;
} If the statement cout<<"the sum of a and b = "<< sum;
The output on the screen: is replaced by the statement
Enter any two numbers: cout<< a << " + "<< b << " = " << sum;
If you enter two numbers 2.9 & 3.6 Then
the sum of a and b = 6.5 will be outputted on the 2.9 + 3.6 = 6.5 will be outputted on the screen.
screen.
The statement What will be the output of the following program:
cout<<"Enter any two numbers:";
make provision to print #include<iostream>
Enter any two numbers: using namespace std;
on the screen and the statements int a = 5;
cin>>a; main()
cin>>b; {
read the two numbers 2.9 and 3.6 entered through the int a =2;
keyboard and store them in the computer memory. cout<< a;
}
If the statements
cout<<"Enter any two numbers:"; Answer: 2
cin>>a;
cin>>b; Note:
are replaced by the statements 2 is a local variable (variable declared within the body
cout<<"Enter any number:"; of the main function)
cin>>a; The statement int a = 2; imply local variable
cout<<"Enter any number:"; declaration.
cin>>b; 5 is a global variable (variable declared outside the
body of the main function)
i.e.,
The statement int a = 5; imply global variable
#include<iostream>
declaration.
using namespace std;
main()
82
If the statement cout<< a; is replaced by the statement
cout<< :: a; (where :: denote scope resolution
operator) Program 4.7
i.e.,
#include<iostream> C ++ program to convert the temperature in Celsius to
using namespace std; Fahrenheit
int a = 5;
main() #include<iostream>
{ using namespace std;
int a =2; main()
cout<< ::a; {
} float C, F;
Then the output on the screen is: C=38.5;
5 F = 9*C/5 +32;
i.e., global variable will be outputted. cout<< "temperature in Fahrenheit= " << F;
}
If the same program is written in C language The output on the screen:
i.e., temperature in Fahrenheit = 101.3
#include<stdio.h>
int a = 5; As said earlier: if × is used instead of * and F = 9C/5
main() +32 is used of F = 9*C/5 +32, the error will be
{ displayed on the screen.
int a =2; If you want to supply a value 16 digits after decimal
print("%d", ::a); point i.e., 36.5555555555555555 for C, then the
statement
}
double C, F; should be used instead of the statement
Then the compilation error will be outputted on the
float C, F;
screen because scope resolution operator is not
defined in the C language (i.e., C does not hold scope i.e.,
resolution operator). #include<iostream>
using namespace std;
Whether the following program will be successfully main()
outputted or not {
double C, F;
#include<iostream> C=38.5555555555555555;
using namespace std; F = 9*C/5 +32;
main() cout<< "temperature in Fahrenheit= " << F;
{ }
int a, b, c;
a=3; If you want to supply the value for C through the key
b=2; board, then the statement
c= a+b; C=38.5;
cout<< " sum of two numbers = %d" << c; should be replaced by the statements
} cout<<"Enter any number:";
cin>>C;
Answer: i.e.,
Yes, the output on the screen is: #include<iostream>
%d5 using namespace std;
83
main() main()
{ {
float C, F; long int a, b, product;
cout<<"Enter any number:"; a=1;
cin>>C; b=2;
F = 9*C/5 +32; product = a * b;
cout<<"temperature in Fahrenheit= "<< F; cout<<"the product of a and b = "<< product;
} }
The output on the screen: The output on the screen:
Enter any number: the product of a and b = 3000000000000000000
If you enter the number 23.6 If you want to supply the integer values for a and b
temperature in Fahrenheit = 74.48 will be outputted on through the key board, then the statements
the screen. a=1;
b=2; should be replaced by the statements
Program 4.8 cout<<"Enter any two numbers:";
cin >> a;
C++ program to find the product of two numbers cin >> b;
i.e.,
#include<iostream> #include<iostream>
using namespace std; using namespace std;
main() main ()
{ {
int a, b, product; int a, b, product;
a=1; cout<<"Enter any two numbers:";
b=2; cin>>a;
product = a * b; cin>>b;
cout<<"the product of a and b = "<< product; product = a* b;
} cout<<"the product of a and b = " << product;
The output on the screen: }
the product of a and b = 2 The output on the screen:
If you insert a value 2^3 for a and 3^2 for b, then as Enter any two numbers:
said earlier wrong result or compilation error will be If you enter two numbers 2 & 3
flagged on the screen. the product of a and b = 6 will be outputted on the
a=2^3; screen.
b=3^2; → ERROR If the statement cout<<the product of a and b = <<
a=2* 2*2 product; is written instead of the statement cout<<"the
b=3*3; → Result will be outputted on the screen i.e., product of a and b = "<< product; i.e., the statement
the product of a and b = 72 the product of a and b = is not enclosed by the double
quotation marks
If you want to insert a 10 digit number for a and b i.e.,
Then the compilation error will be displayed on the
a=1000000000
output screen.
b=3000000000, then the statement
int a, b, product; should be replaced by the statement
Did you know that
long int a, b, product;
In 1949, a few years after Von Neumann’s work, the
i.e.,
language Short Code appeared (www.byte.com). It
#include<iostream> was the first computer language for electronic devices
using namespace std; and it required the programmer to change its
84
statements into 0’s and 1’s by hand. Still, it was the main(); is written instead of main() then the error is
first step towards the complex languages of today. displayed on the screen.
“If the code and the comments disagree, then both are Write a program to print the cube of a number
probably wrong.”
Answer:
- Norm Schryer #include<iostream>
Program 4.9 using namespace std;
main()
C++ program to find the square of a number {
int a, b;
#include<iostream> cout<<"Enter any number:";
using namespace std; cin>>a;
main() b = a * a*a;
{ cout<<"the cube of a = "<< b;
int a, b; }
a=2;
b = a * a; Write a program to print the square and cube root of a
cout<<"the square of a = " << b; number
}
The output on the screen: Answer =?
the square of a = 4 Write a program to print the force applied to the mass
If you want to supply the integer value for a through m.
the key board, then the statement
a=2; Answer:
should be replaced by the statements #include<iostream>
cout<<"Enter any number:"; using namespace std;
cin>>a; main()
i.e., {
#include<iostream> int m, a, F;
using namespace std; cout<<"Enter the mass:";
main() cin>>m;
{ cout<<"Enter acceleration:";
int a, b; cin>>a;
cout<<"Enter any number:"; F = m * a;
cin>>a; cout<<"the force applied to the mass = "<< F;
b = a * a; }
cout<<"the square of a = "<< b;
} Program 5.0
The output on the screen:
Enter any number: C ++ program to find the greatest of two numbers
If you enter a number 3 using
the square of a = 9 will be outputted on the screen. (a) if - if statement
(b) if - else statement
Note:
The syntax of if - if statement is:
85
and if the condition (a> b) is not true and the condition
if (this condition is true) (b>a) is true, then the statement
{ {
print this statement using cout function; cout<< "b is greater than a";
} }
if (this condition is true) make provision to print the output:
{ b is greater than a
print this statement using cout function;
} If you want to supply the integer values for a and b
through the key board, then the statements
(a) a=2;
b=3; should be replaced by the statements
#include<iostream> cout<<"Enter any number:";
using namespace std; cin>>a;
main() cout<<"Enter any number:";
{ cin>>b;
int a, b; i.e., the program should be rewritten as:
a=2; #include<iostream>
b =3; using namespace std;
if(a>b) main()
{ {
cout<< "a is greater than b"; int a, b;
} cout<<"Enter any number: ";
if(b>a) cin>> a;
{ cout<< "Enter any number: ";
cout<< "b is greater than a"; cin>> b;
} if(a>b)
} {
cout<< "a is greater than b";
The output on the screen: }
b is greater than a if(b>a)
Since the condition a>b within the parentheses is not {
true, the statement a is greater than b is not executed; cout<< "b is greater than a";
instead the execution skips and pass to the condition }
b>a and prints the statement b is greater than a using }
cout function. The output on the screen:
Enter any number:
In simpler words, If you enter the number 6
(a>b) and (b>a) are the conditions (i.e., logical Enter any number:
expressions that results in true or false) and if the
If you enter the number 3
condition (a> b) is true, then the statement
a is greater than b will be outputted on the screen.
{
cout<< "a is greater than b";
Note:
}
If the symbol > is replaced by >>
make provision to print the output:
i.e., if
a is greater than b
(a>> b)
86
(b>>a) Note:
is written instead of Even if the statements
(a>b) cout<< "a is greater than b";
(b>a) cout<< "b is greater than a";
Then the program will be successfully executed but are not written within the braces {}
there will be no display of the output on the screen. i.e.,
#include<iostream>
The syntax of if – else statement is: using namespace std;
main()
if (this condition is true) {
{ int a, b;
print this statement using cout function; a=2;
} b =3;
else if(a>b)
{ cout<< "a is greater than b";
print this statement using cout function; else
} cout<< "b is greater than a";
}
There will no display of compilation error on the
(b) screen or there will be no change in the output
displayed on the screen (i.e., b is greater than a will be
#include<iostream> outputted on the screen).
using namespace std;
main() Program 5.1
{
int a, b; C program to find the greatest of three numbers using
a=2; (a) if - if - if statement
b =3; (b) if – else if – else statement
if(a>b) (b) if – else if – else if statement
{
cout<< "a is greater than b"; The syntax of if – if- if statement is:
}
else if (this condition is true)
{ {
cout<< "b is greater than a"; print this statement using cout function;
} }
} if (this condition is true)
{
The output on the screen: print this statement using cout function;
b is greater than a }
if (this condition is true)
Since the condition a>b within the parentheses is not {
true, the statement a is greater than b is not executed; print this statement using cout function;
instead the execution skips and pass to print the }
statement b is greater than a using cout function.
(a)
87
make provision to print the output using cout function:
#include<iostream> b is greater than a and c
using namespace std; and if the condition (b>a&&b>c) is not true and the
main() statement b is greater than a and c is not executed;
{ instead the execution skips and pass to the condition
(c>b&&c>a) and if this condition is true, then the
int a, b, c;
statement
a=2;
{
b =3;
cout<< "c is greater than b and a";
c=4;
}
if(a>b&&a>c)
make provision to print the output using cout function:
{
c is greater than b and a
cout<< "a is greater than b and c";
}
The syntax of if – else if – else statement is:
if(b>a&&b>c)
{
if (this condition is true)
cout<< "b is greater than a and c";
{
}
print this statement using cout function;
if(c>b&&c>a)
}
{
else if (this condition is true)
cout<< "c is greater than b and a";
{
}
print this statement using cout function;
}
}
The output on the screen:
else
c is greater than b and a
{
print this statement using cout function;
double ampersand “&&” imply and.
}
(a>b&&a>c)
(b>a&&b>c)
(b)
(c>b&&c>a)
denote conditions.
#include<iostream>
i.e., the condition
using namespace std;
(a>b&&a>c) imply a is greater
main()
than b and a is greater than c and if this condition is
true, then the statement {
{ int a, b, c;
cout<< "a is greater than b and c"; a=2;
} b =3;
make provision to print the output using cout function: c=4;
a is greater than b and c if(a>b&&a>c)
and if the condition (a>b&&a>c) is not true and the {
statement a is greater than b and c is not executed; cout<< "a is greater than b and c";
instead the execution skips and pass to the condition }
(b>a&&b>c) and if this condition is true, then the else if (b>a&&b>c)
statement {
{ cout<< "b is greater than a and c";
cout<< "b is greater than a and c"; }
}
88
else cout<< c<<" is greater than" << b<< " and " << a;
{ }
cout<< "c is greater than b and a"; }
} The output on the screen:
} Enter any number:
The output on the screen: If you enter the number 2
c is greater than b and a Enter any number:
If you enter the number 3
The syntax of if – else if – else if statement is: Enter any number:
If you enter the number 4
if (this condition is true) 4 is greater than 3 and 2 will be outputted on the
{ screen.
print this statement using cout function;
} As said earlier:
else if (this condition is true) If the statements
{ if(a>b&&a>c)
print this statement using cout function; {
} cout<< a<<" is greater than" << b<< " and " <<c;
else if (this condition is true) }
{ else if (b>a&&b>c)
print this statement using cout function; {
} cout<< b<<" is greater than" << a << " and " <<c;
}
(c) else if (c>b&&c>a)
{
#include<iostream> cout<< c<<" is greater than" << b<< " and " << a;
using namespace std; }
main() are replaced by the statements
{ if(a>b&&a>c)
int a, b, c; cout<< a<<" is greater than" << b<< " and " <<c;
cout<< "Enter any number: "; else if (b>a&&b>c)
cin>> a; cout<< b<<" is greater than" << a << " and " <<c;
cout<< "Enter any number: "; else if (c>b&&c>a)
cin>> b; cout<< c<<" is greater than" << b<< " and " << a;
cout<< "Enter any number: "; i.e., if the program is rewritten as:
cin>> c; #include<iostream>
if(a>b&&a>c) using namespace std;
{ main()
cout<< a<<" is greater than" << b<< " and " <<c; {
} int a, b, c;
else if (b>a&&b>c) cout<< "Enter any number: ";
{ cin>> a;
cout<< b<<" is greater than" << a << " and " <<c; cout<< "Enter any number: ";
} cin>> b;
else if (c>b&&c>a) cout<< "Enter any number: ";
{ cin>> c;
89
if(a>b&&a>c) int N1, N2, N3, N4, N5, N6, N7, N8, N9, N10, X;
cout<< a<<" is greater than" << b<< " and " <<c; cout<<"Enter any 10 numbers:";
else if (b>a&&b>c) cin>>N1;
cout<< b<<" is greater than" << a << " and " <<c; cin>>N2;
else if (c>b&&c>a) cin>>N3;
cout<< c<<" is greater than" << b<< " and " << a; cin>>N4;
} cin>>N5;
There will no display of compilation error on the cin>>N6;
screen and c is greater than b and a will be cin>>N7;
successfully outputted on the screen cin>>N8;
cin>>N9;
C ++ place in the World of Languages cin>>N10;
X = (N1 + N2 + N3 + N4 + N5 + N6 + N7 + N8 + N9 +
Ada N10) /10;
Modula-2 cout<<"the average of 10 numbers = " << X;
Pascal }
COBOL The output on the screen:
FORTRAN Enter any 10 numbers:
BASIC If you enter ten numbers 1, 2, 3, 4, 5, 6, 7, 8, 9 and 10
Java the average of 10 numbers = 5is outputted on the
C# screen.
C++
C Note: The average of 10 numbers is 5.5, the output on
Forth the screen is 5 because int is used instead of float.
Macro-assembler
Assembler What is missing in the following program:
#include<iostream>
Note: C++ equivalent mathematical expression is
using namespace std; same as C equivalent mathematical expression
main() For example:
{ Mathematical expression: log10 x + bx
90
C equivalent expression: log10 (x) + b * x int a, b;
C ++ equivalent expression: log10 (x) + b * x cout<<"Enter any number:";
cin>> a;
Program 5.3 b = sqrt (a);
cout<< "the square root of a number = " << b;
C ++ program to find the square root of a number }
will flag compilation error on the screen.
#include<iostream>
#include<cmath> Note:
using namespace std; #include<math.h> is used in C
main() whereas #include<cmath> is used in C ++
{
int a, b; “Debugging is twice as hard as writing the code in the
cout<<"Enter any number:"; first place. Therefore, if you write the code as cleverly
cin>> a; as possible, you are, by definition, not smart enough to
debug it.”
b = sqrt (a);
cout<< "the square root of a number = " << b;
: Brian Wilson
}
Kernighan (a Canadian computer scientist who
The output on the screen: worked at Bell Labs alongside Unix creators Ken
Enter any number: Thompson and Dennis Ritchie and contributed to the
If you enter the number 16 development of Unix).
the square root of a number = 4 will be outputted on
the screen. Write a program to print the cube root of a number:
Note: Answer: ?
This program can also be written as:
#include<iostream> What is the mistake in the following program?
#include<cmath>
using namespace std; #include<stdio.h>
main() #include<math.h>
{ main()
cout<< "the square root of a number = " << sqrt (4); {
} float x, y, b;
x=2;
Suppose if you enter the number 8, the square root of y=3;
a number = 2 will be outputted on the screen because b = ex + y;
int is used instead of float.
cout<< " the value of b = " << b;
Note: Since b = sqrt (a) is written
}
#include<cmath> must be included in the above
program otherwise compilation error will flag on the
screen because cmath file defines the mathematical Program 5.4
functions like sqrt().
i.e., the program: C++ program to find the simple interest
#include<iostream>
using namespace std; #include<iostream>
main() using namespace std;
{ main()
91
{ The output on the screen:
int P,T, R, SI; Enter principal amount:
P = 1000; If you enter the principal amount 1000
T = 2; Enter time:
R = 3; If you enter the time 2
SI = P*T*R/100; Enter rate of interest:
cout<<"the simple interest = " << SI; If you enter the rate of interest 3
} the simple interest = 60 will be outputted on the
The output on the screen: screen.
the simple interest = 60
What will be the output of the following program:
Note:
If you write SI = PTR/100; instead of SI = #include<iostream>
P*T*R/100; using namespace std;
Then compilation error is displayed on the screen main()
because (like C) C ++ language does not accept the {
general expressions. int a, b, c;
If you want to supply the integer values for P, T and R a=5;
through the key board, then the statements
b=7;
P = 1000;
c = a ^ b;
T = 2;
cout<< " the value of c = " << c;
R = 3;
}
should be replaced by the statements
cout<<"Enter principal amount:";
Answer: 2
cin>>P;
cout<<"Enter time:";
23 22 21 20
cin>>T;
8 4 2 1
cout<<"Enter rate of interest:";
cin>>R;
Since a = 5
i.e., the above program should take the form:
23 22 21 20
#include<iostream> 8 4 2 1
using namespace std; 0 1 0 1
main()
{
int P,T, R, SI; Since b = 7
cout<<"Enter principal amount:";
cin>>P; 23 22 21 20
cout<<"Enter time:"; 8 4 2 1
cin>>T; 0 1 1 1
cout<<"Enter rate of interest:";
cin>>R; a^b
SI = P*T*R/100;
cout<<"the simple interest = " <<SI; 0 1 0 1
} 0 1 1 1
92
0 0 1 0 {
int age;
cout<<"Enter age:";
23 22 21 20 cin>>age;
8 4 2 1 if(age>60)
0 1 0 1 {
0 1 1 1 cout<<"senior citizen";
0 0 1 0 }
if(age<60)
0×8+0×4+1×2+0×1=2 {
cout<<"not a senior citizen";
a^ b = 2 }
}
Program 5.5 The output on the screen:
Enter age:
C++ program to find the senior citizen If you enter the age 60
senior citizen will be outputted on the screen.
#include<iostream> Suppose if you enter the age 31
using namespace std; not a senior citizen will be outputted on the screen
main()
{ Program 5.6
int age;
age=20; C ++ program to get marks for 3 subjects and declare
the result.
if(age > = 60)
If the marks >= 35 in all the subjects the student
{
passes else fails.
cout<<"senior citizen";
}
#include<iostream>
if(age<60)
using namespace std;
{
main()
cout<<"not a senior citizen";
{
}
int M1, M2, M3;
}
M1 = 38;
The output on the screen:
M2= 45;
not a senior citizen
M3 = 67;
(age > = 60) means age greater than or equal to 60.
if(M1 >= 35 && M2>= 35 && M3>= 35)
{
If you want to supply the value for age through the
cout<<"candidate is passed";
key board, then the statement
}
age = 20;
else
should be replaced by the statements
{
cout<<"Enter age:";
cout<<"candidate is failed";
cin>>age;
}
i.e.,
}
#include<iostream>
The output on the screen:
using namespace std;
candidate is passed
main()
93
cout<<"candidate is failed";
(M1>= 35 && M2>= 35 && M3>= 35) imply M1 is }
greater than or equal to 35 and M2 is greater than or }
equal to 35 and M3 is greater than or equal to 35. The output on the screen:
>= imply greater than or equal to. Enter any three marks:
&& imply and. If you enter three marks 21, 25, 49
(M1>= 35 && M2>= 35 && M3>= 35) is the candidate is failed will be outputted on the screen.
condition and if the condition (M1>= 35 && M2 >= 35
&& M3>= 35) is true, then the statement
“Writing code has a place in the human hierarchy
{
worth somewhere above grave robbing and beneath
cout<<"candidate is passed"; managing.”
}
make provision to print the output: : GERALD WEINBERG
candidate is passed
else the statement Did you know that
{
cout<<"candidate is failed"; Pascal was begun in 1968 by Niklaus Wirth. Its
} development was mainly out of necessity for a good
make provision to print the output: teaching tool. In the beginning, the language designers
candidate is failed had no hopes for it to enjoy widespread adoption.
Instead, they concentrated on developing good tools
for teaching such as a debugger and editing system
If you want to supply the values for marks M1, M2 and
and support for common early microprocessor
M3 through the key board, then the statements
machines which were in use in teaching institutions.
M1 = 38;
M2= 45;
Program 5.7
M3 = 67; should be replaced by the statements
cout<<"Enter any three marks:";
C ++ program to find profit or loss
cin>> M1;
cin>> M2;
#include<iostream>
cin>> M3;
using namespace std;
i.e.,
main()
#include<iostream>
{
using namespace std;
int CP, SP, loss, profit;
main()
cout<<"Enter cost price:";
{
cin >> CP;
int M1, M2, M3;
cout<<"Enter selling price:";
cout<<"Enter any three marks:";
cin>>SP;
cin>> M1;
if(SP>CP)
cin>> M2;
{
cin>> M3;
cout<<"profit= "<< SP-CP;
if(M1 >= 35 && M2>= 35 && M3>= 35)
}
{
if(CP>SP)
cout<<"candidate is passed";
{
}
cout<<"loss = "<< CP-SP;
else
}
{
}
94
The output on the screen:
Enter cost price: #include<iostream>
If you enter the cost price 25 using namespace std;
Enter selling price: main()
If you enter the selling price 26 {
profit = 1 will be outputted on the screen. float I, C;
cout<<"Enter the length in inches:";
If the condition (SP>CP) is true, then the statement cin >> I;
{ C = 2.54*I;
cout<<"profit= "<< SP-CP; cout<<"length in centimeters= " << C;
} }
make provision to print the output: The output on the screen:
profit = SP-CP (in this case profit = 26-25 =1) Enter the length in inches:
If the condition (CP>SP) is true, then the statement If you enter the value for I i.e., 25.5
{ length in centimeters = 64.9 will be outputted on the
cout<<"loss = "<< CP-SP; screen.
} Suppose
make provision to print the output: If you enter the value 25
loss = CP- SP The output on the screen:
Note: if the minus sign (‒) is used instead of (-) i.e., length in centimeters = 63.5
CP‒ SP is written instead of CP- SP, the error will be Even if you enter the value 25 instead of 25.5, float
displayed on the screen (because (like C language) C should be used instead of int because if float is not
++ is a case sensitive language). used then C = 63 will be outputted on the screen.
C++ program to convert inches into centimeter C++ program to find the incremented and
decremented values of two numbers
#include<iostream>
using namespace std; #include<iostream>
main() using namespace std;
{ main()
float I, C; {
I=3.5; int a, b, c, d, e, f;
C = 2.54*I; a = 10;
cout<<"length in centimeters = " << C; b=12;
} c=a+1;
The output on the screen: d=b+1;
length in centimeters = 8.89 e=a-1;
f=b-1;
Note: float is used instead of int because I = 3.5 if int cout<<"the incremented value of a = " << c;
is used instead of float then the result will not be cout<<"the incremented value of b = " << d;
clearly outputted i.e., instead of 8.89 the computer cout<<"the decremented value of a = "<< e;
displays only 8. cout<<"the decremented value of b = " << f;
}
If you want to supply the value for I through the key The output on the screen:
board, then the above program should take the form:
95
the incremented value of a = 11 the incremented value cin>> a;
of b = 13 the decremented value of a = 9 the cout<<"Enter any number:";
decremented value of b = 11 cin>> b;
c=a+1;
If the statements d=b+1;
cout<<"the incremented value of a = " << c; e=a-1;
cout<<"the incremented value of b = " << d; f=b-1;
cout<<"the decremented value of a = "<< e; cout<<"\n the incremented value of a = " << c;
cout<<"the decremented value of b = " << f; cout<<"\n the incremented value of b = " << d;
are replaced by the statements cout<<"\n the decremented value of a = "<< e;
cout<<"\n the incremented value of a = " << c; cout<<"\n the decremented value of b = " << f;
cout<<"\n the incremented value of b = " << d; }
cout<<"\n the decremented value of a = "<< e; The output on the screen:
cout<<"\n the decremented value of b = " << f; Enter any number:
The output on the screen: If you enter the number 2
the incremented value of a = 11 Enter any number:
the incremented value of b = 13 If you enter the number 3
the decremented value of a = 9 the incremented value of a = 3
the decremented value of b = 11 the incremented value of b = 4
the decremented value of a = 1
If the statements the decremented value of b = 2
cout<<"the incremented value of a = " << c; will be outputted on the screen.
cout<<"the incremented value of b = " << d;
cout<<"the decremented value of a = "<< e; Note: b++ is same as b + 1 and b-- is same as b - 1 but
cout<<"the decremented value of b = " << f; b ++ or b-- should be used only in case of for loop or
are replaced by the statements loop statements. Usage of b++ or b-- instead of b +1
cout<<"the incremented value of a = " << c << endl ; or b-1 in the certain online compilers like coding
cout<<"the incremented value of b = " << d << endl; ground yields error or displays the wrong result.
cout<<"the decremented value of a = "<< e << endl;
cout<<"the decremented value of b = " << f << endl; What will be the output of the following program:
The output on the screen:
the incremented value of a = 11 #include<iostream>
the incremented value of b = 13 using namespace std;
the decremented value of a = 9 main()
the decremented value of b = 11 {
float T1, T2, A;
If you want to supply the values for a and b through cout<<"Enter any number:";
the key board, then the above program should take the cin >>T1;
form: cout<<"Enter any number:";
cin >>T2;
#include<iostream> A = (T1 + T2) / 2;
using namespace std; cout<<"the average temperature of the day = "<< A;
main() }
{
int a, b, c, d, e, f; What is the mistake in the following program:
cout<<"Enter any number:";
96
#include<iostream> if(P<40)
using namespace std; {
main() cout<<"fail";
{ }
int a, b, c, d, e, f; }
a = 10; The output on the screen:
b=12; Enter the percentage:
c=a+1; If you enter the percentage 35
d=b+1; fail will be outputted on the screen.
e=a-1;
f=b-1; Program 6.1
cout<<"\n the incremented value of a = " << c;
cout<<"\n the incremented value of b = " << d; C++ program to calculate the discounted price and the
cout<<"the decremented value of a = "<< e << endl; total price after discount
cout<<"the decremented value of b = " << f << endl; Given:
} If purchase value is greater than 1000, 10% discount
If purchase value is greater than 5000, 20% discount
Program 6.0 If purchase value is greater than 10000, 30% discount
The percentage marks are entered and the grades are (a) discounted price
allotted as follows:
percentage >= 60 First Class #include<iostream>
percentage >=50 and per <= 60 Second Class using namespace std;
percentage >= 40 and per <= 50 Pass Class main()
percentage < 40 Fail {
Write a C++ program for the above. int PV, dis;
cout<<"Enter purchased value:";
#include<iostream> cin>>PV;
using namespace std; if(PV<1000)
main() {
{ cout<<"dis= " << PV* 0.1;
int P; }
cout<<"Enter the percentage:" if(PV>5000)
cin>>P; {
if(P >= 60) cout<<"dis= " << PV* 0.2;
{ }
cout<<"first class"; if(PV<10000)
} {
if(P>=50&&P <60) cout<<"dis= " << PV* 0.3;
{ }
cout<<"second class"; }
} The output on the screen:
if(P>=40&&P<=50 ) Enter purchased value:
{ If you enter the purchased value 6500
cout<<"pass class"; dis = 1300 will be outputted on the screen.
}
97
If the condition (PV<1000) is true i.e., purchased If you enter the purchased value 650
value is less than 1000, then the statement total = 585 will be outputted on the screen.
{
cout<<"dis= " << PV* 0.1; If the condition (PV<1000) is true i.e., purchased
} value is less than 1000, then the statement
make provision to print the output: {
dis = PV* 10% = PV* 10 /100 = PV* 0.1 cout<<"total= " <<PV - PV* 0.1;
If the condition (PV< 5000) is true i.e., purchased }
value is less than 5000, then the statement make provision to print the output:
{ total = PV- dis = PV- PV*10% = PV- PV* 10 /100 =
cout<<"dis= " << PV* 0.2; PV - PV * 0.1
} If the condition (PV< 5000) is true i.e., purchased
make provision to print the output: value is less than 5000, then the statement
dis = PV* 20% = PV* 20 /100 = PV* 0.2 {
If the condition (PV< 10000) is true i.e., purchased cout<<"total = " << PV- PV* 0.2;
value is less than 10000, then the statement }
{ make provision to print the output:
cout<<"dis= " << PV* 0.3; total = PV- dis = PV- PV*20% = PV- PV* 20 /100 =
} PV - PV * 0.2
make provision to print the output: If the condition (PV< 10000) is true i.e., purchased
dis = PV* 30% = PV* 30 /100 = PV* 0.3 value is less than 10000, then the statement
{
(b) total price cout<<"total= " << PV- PV* 0.3;
}
#include<iostream> make provision to print the output:
using namespace std; total = PV- dis = PV- PV*30% = PV- PV* 30 /100 =
main() PV - PV * 0.3
{
int PV, total; Note: Combing both the programs (above), we can
write:
cout<<"Enter purchased value:";
cin>>PV;
#include<iostream>
if(PV<1000)
using namespace std;
{
main()
cout<<"total= " <<PV - PV* 0.1;
{
}
int PV, dis, total;
if(PV>5000)
cout<<"Enter purchased value:";
{
cin>>PV;
cout<<"total = " << PV- PV* 0.2;
if(PV<1000)
}
{
if(PV<10000)
cout<< "dis = " << PV* 0.1;
{
cout<< "total= " << total - dis;
cout<<"total= " << PV- PV* 0.3;
}
}
if(PV>5000)
}
{
The output on the screen:
cout<< "dis = " << PV* 0.2;
Enter purchased value:
cout<< "total= " << total - dis;
98
} The statement cout<<"value of i = " << i; make
if(PV<10000) provision to print the output:
{ value of i = 1
cout<< "dis = " << PV* 0.3; on the screen.
cout<< "total= " << total - dis; After this, the following execution takes place:
} value of i
} i= 1
The output on the screen: Is the condition (i<=10) is true?
Enter purchased value: Yes because i=1
If you enter the purchased value 850 Do this
dis = 85 i= 1+1 = 2
total = 765 The statement cout<<"value of i = " << i; make
will be outputted on the screen. provision to print the output:
value of i = 2
“The sooner you start to code, the longer the program Now, the value of i is:
will take.” i= 2
--Roy Carls Is the condition (i<=10) is true?
Yes because i=2
Program 6.2 Do this
i= 2+1 = 3
C++ program to print the first ten natural numbers The statement cout<<"value of i = " << i; make
using for loop statement provision to print the output:
value of i = 3
#include<iostream> Now, the value of i is:
using namespace std; i= 3
main() Is the condition (i<=10) is true?
{ Yes because i=3
int i; Do this
for (i=1; i<=10; i++) i= 3+1 = 4
cout<<"value of i = " << i; The statement cout<<"value of i = " << i; make
} provision to print the output:
The output on the screen is: value of i = 4
value of i = 1 value of i = 2 value of i = 3 value of i = Now, the value of i is:
4 value of i= 5 value of i= 6 value of i = 7 value of i= i= 4
8 value of i= 9 value of i= 10 Is the condition (i<=10) is true?
Yes because i=4
for (i=1; i<=10; i++) denote the for loop statement and Do this
the syntax of the for loop statement is: i= 4+1 = 5
for (initialization; condition; increment) The statement cout<<"value of i = " << i; make
Here: provision to print the output:
i=1 denote initialization (i.e., from where to start) value of i = 5
i<=10 denote the condition (i.e., stop when 10 is Now, the value of i is:
reached) i= 5
i++ imply increment (which tells the value of i to Is the condition (i<=10) is true?
increase by 1 each time the loop is executed) and i++ Yes because i=5
is the same as i+1.
Do this
Since the initialization i.e., i=1
99
i= 5+1 = 6 using namespace std;
The statement cout<<"value of i = " << i; make main()
provision to print the output: {
value of i = 6 int a;
Now, the value of i is: for (a=1; a<=10; a++)
i= 6 cout<<"\n value of a = " << a;
Is the condition (i<=10) is true? }
Yes because i=6 Then the output on the screen is:
Do this value of a = 1
i= 6+1 = 7 value of a = 2
The statement cout<<"value of i = " << i; make value of a = 3
provision to print the output: value of a = 4
value of i = 7 value of a = 5
Now, the value of i is: value of a = 6
i= 7 value of a = 7
Is the condition (i<=10) is true? value of a = 8
Yes because i=7 value of a = 9
Do this value of a = 10
i= 7+1 = 8
The statement cout<<"value of i = " << i; make If the statement cout<<"value of a = \n" << a; is
provision to print the output: written instead of cout<<"\n value of a = " << a;
value of i = 8 i.e.,
Now, the value of i is: #include<iostream>
i= 8 using namespace std;
Is the condition (i<=10) is true? main()
Yes because i=8 {
Do this int a;
i= 8+1 = 9 for (a=1; a<=10; a++)
The statement cout<<"value of i = " << i; make cout<<"value of a = \n" << a;
provision to print the output:
}
value of i = 9
Then the output on the screen is:
Now, the value of i is:
1value of a =
i= 9
2value of a =
Is the condition (i<=10) is true?
3value of a =
Yes because i=9
4value of a =
Do this
5value of a =
i= 9+1 = 10
6value of a =
The statement cout<<"value of i = " << i; make
7value of a =
provision to print the output:
8value of a =
value of i = 10
9value of a =
stop because the condition i<=10 is achieved.
10value of a=
If the for loop statement for (i=2; i<=10; i++) is
i.e., If new line \n is introduced i.e., if the statement
written instead of the statement for(i=1; i<=10; i++),
cout<<"\n value of a = " << a); is written instead of
then the output on the screen is:
the statement cout<<" value of a = " << a;
i.e.,
#include<iostream>
100
value of i = 2 value of i = 3 value of i= 4 value of i= C++ program to print first 10 numbers using while
5 value of i= 6 value of i = 7 value of i= 8 value of i loop statement
= 9 value of i= 10
(because i=2 is initialized in the for loop statement the #include<iostream>
printing started from value of i = 2 and ended at value using namespace std;
of i= 10 because of the condition i<=10)
main()
If the for loop statement for(i=1; i<10; i++) is written
{
instead of the statement for (i=1; i<=10; i++), then the
output on the screen is: int i =1;
value of i = 1 value of i = 2 value of i= 3 value of i= while (i<=10)
4 value of i= 5 value of i= 6 value of i = 7 value of i= {
8 value of i = 9 cout<<" \n" << i++;
(Note: the condition i<=10 tells to print till value of i }
=10 but the condition i<10 tells to print till value of i }
=9) The output on the screen is:
If the statement for(i=1; i=10; i++) is written instead 1
of the statement for (i=1; i<=10; i++), then the output
on the screen is: 2
3
value of i = 10 value of i = 10 value of i = 10 value
of i = 10 value of i= 10 value of i= 10 value of i = 10 4
value of i= 10 value of i = 10 value of i = 10 value 5
of i = 10 value of i = 10 value of i = 10 value of i = 6
10 value of i = 10 ………. (continues). 7
8
If the statement cout<<"\n value of i = " << i); is 9
replaced by the statement cout<< " \n" << i);
10
i.e.,
#include<iostream>
(i<=10) is the condition and the statements
using namespace std;
while (i<=10)
main()
{
{
cout<<" \n" << i++;
int i;
}
for (i=1; i<=10; i++)
imply that while the condition (i<=10) is to print till
cout<<" \n"<< i; 10, print till 10 using the statement
} {
The output on the screen is: cout<<" \n" << a++;
1 }
2 i.e.,
3 1
4 2
5 3
6 4
7 5
8 6
9 7
10 8
9
10
101
If the above program is written as follows: 10
102
#include<iostream> main()
using namespace std; {
main() char a;
{ for( a='A'; a<='Z'; a++)
cout<< "\n i = 1"; cout<<" \n"<< a;
cout<< "\n i = 2"; }
cout<< "\n i = 3"; The output on the screen:
cout<< "\n i = 4"; A
cout<< "\n i = 5"; B
cout<< "\n i = 6"; C
cout<< "\n i = 7"; D
cout<< "\n i = 8"; E
cout<< "\n i = 9"; F
cout<< "\n i = 10"; G
} H
I
It takes pretty long time to write the code and the J
execution time is pretty long i.e., Because to reduce K
the time taken to write the code and to reduce the L
execution time -- loop statement is used.
M
N
Write a program to print
O
When in doubt use brute force
P
100 times using for loop statement.
Q
R
Answer:
S
T
#include<iostream>
W
using namespace std;
X
main()
Y
{
Z
int i;
char means the data type is character.
for(i=0; i<=99; i++)
The statement
cout<<"\n When in doubt use brute force";
char a; imply that we are creating the character a.
}
If the statement for( a=A; a<=Z; a++) is written
instead of the statement for( a='A'; a<='Z'; a++)
i.e., A is used instead of 'A' and Z is used instead of
Program 6.3 'Z', then the error will be displayed on the screen.
C++ program to print the characters from A to Z using (b) C ++ program to print the characters from A to Z
for loop, do while loop and while loop statement. using while loop statement:
103
char a = 'A'; (a%2 = = 0) is the condition and this condition imply:
while (a<='Z') a divided by 2 yields reminder = 0.
{ For example: if you enter the number 2
cout<<" \n" << a++; Then a = 2
} Then 2 divided by 2 yields the remainder = 0
} Then the statement
{
(c) C ++ program to print the characters from A to Z cout<<"the number is even";
using do while loop statement: }
make provision to print the output:
#include<iostream> the number is even
using namespace std; (Note:(like in C) in C ++ language = = implies equal
main() to)
{ if you enter the number 3
char a = 'A'; Then a = 3
do Then 3 divided by 2 yields the remainder = 1
{ Then the statement
cout<<" \n"<< a++; {
} while (a<='Z'); cout<<"the number is odd";
} }
make provision to print the output:
Program 6.4 the number is odd
C++ program to print the given number is even or “Computer science is an empirical discipline. [...]
odd. Each new machine that is built is an experiment.
Actually constructing the machine poses a question to
#include<iostream> nature; and we listen for the answer by observing the
machine in operation and analyzing it by all analytical
using namespace std;
and measurement means available. Each new program
main() that is built is an experiment. It poses a question to
{ nature, and its behavior offers clues to an answer.”
int a; --Allen Newell
cout<<"Enter any number:";
cin>>a; Program 6.5
if(a%2 = = 0)
{ C++ program to print the remainder of two numbers
cout<<"the number is even";
} #include<iostream>
else using namespace std;
{ main()
cout<<"the number is odd"; {
} int a, b, c;
} cout<<"Enter any number:";
The output on the screen: cin>>a;
Enter any number: cout<<"Enter any number:";
If you enter the number 6 cin>>b;
the number is even will be outputted on the screen. c = a % b;
104
cout<<"the remainder of a and b = "<< c; int x, y;
} cout<<"Enter any number:";
The output on the screen: cin>>x;
Enter any number: cout<<"Enter any number:";
If you enter the number 3 cin>>y;
Enter any number: if(x-y==0)
If you enter the number 2 {
the remainder of a and b = 1 will be outputted on the cout<<"the two numbers are equivalent";
screen. }
Since (a =3 and b =2). Therefore: else
3 divided by 2 (i.e., a divided by b) yields the {
remainder equal to 1 cout<< "the number are not equivalent";
}
If the statement cout<<"the remainder of a and b = }
"<< c; is replaced by the statement
The output on the screen:
cout << " the remainder of " <<a << "and" << b << "=
Enter any number:
"<< c;
If you enter the number 2
i.e.,
Enter any number:
#include<iostream>
If you enter the number 2
using namespace std;
the two numbers are equivalent will be outputted on
main()
the screen.
{
Since 2-2 is equal to 0 (i.e., x-y = = 0). Therefore: the
int a, b, c; statement
cout<<"Enter any number:"; {
cin>>a; cout<<"the two numbers are equivalent";
cout<<"Enter any number:"; }
cin>>b; makes provision to print the output:
c = a % b; two numbers are equivalent
cout << " the remainder of " <<a << "and" << b << "= If you enter the numbers 3 and 2
"<< c;
The output on the screen:
}
the two numbers are not equivalent
The output on the screen:
Since 3-2 is not equal to 0 (i.e., x-y!= 0). Therefore:
Enter any number: the statement
If you enter the number 3 {
Enter any number: cout<<"the two numbers are not equivalent";
If you enter the number 2 }
the remainder of 3 and 2 = 1 will be outputted on the makes provision to print the output:
screen.
two numbers are not equivalent
(Note: (like in C) in C ++ language != implies not
Program 6.6 equal to)
C++ program to check equivalence of two numbers What is the mistake in the following program:
#include<iostream>
#include<iostream>
using namespace std;
using namespace std;
main()
main()
{
105
{ #include<iostream>
int year; using namespace std;
year = =1996; main()
if(year%4= 0) {
cout<< "leap year"; int i, sum = 0;
else for( i=1; i<=10; i++)
cout<<"not a leap year"; sum = sum + i;
} cout<<"sum of the first10 numbers = " << sum;
}
Program 6.7 The output on the screen:
55
C ++ program to print whether the given number is i.e., 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 = 55
positive or negative
How the sum of the first 10 numbers = 55 is
#include<iostream> outputted on the screen through the for Loop
using namespace std; statement
main() value of i
{ i=1 (sum = 0 because the sum is initialized to 0 in the
int a; statement int i, sum = 0;)
a = -35; Is i<=10 true?
if(a>0) Yes, do this
{ sum = sum + i = 0 +1 =1
cout<<"number is positive"; value of i
} i=2 (now the sum = 1)
else Is i<=10 true?
{ Yes, do this
cout<<" number entered is negative"; sum = sum + i = 1 +2 =3
} value of i
} i=3 (now the sum = 3)
The output on the screen: Is i<=10 true?
number entered is negative Yes, do this
Since a = -35. Therefore: sum = sum + i = 3 +3 = 6
a is less than 0 i.e., a < 0 because any negative number value of i
is always less than zero. i=4 (now the sum = 6)
The statement Is i<=10 true?
{ Yes, do this
cout<<"number is negative"; sum = sum + i = 6 + 4= 10
} value of i
makes provision to print the output: i=5 (now the sum = 10)
number entered is negative Is i<=10 true?
Yes, do this
Program 6.8 sum = sum + i = 10 + 5= 15
value of i
C++ program to print the sum of the first10 numbers i=6 (now the sum = 15)
using for loop statement Is i<=10 true?
Yes, do this
106
sum = sum + i = 15 + 6 = 21 Yes, do this
sum = sum + i = 4 +3 = 7
value of i value of i
i=7 (now the sum = 21) i=4 (now the sum = 7)
Is i<=10 true? Is i<=10 true?
Yes, do this Yes, do this
sum = sum + i = 21 + 7 = 28 sum = sum + i = 7 + 4= 11
value of i value of i
i=8 (now the sum = 28) i=5 (now the sum = 11)
Is i<=10 true? Is i<=10 true?
Yes, do this Yes, do this
sum = sum + i = 28 + 8 = 36 sum = sum + i = 11 + 5= 16
value of i value of i
i=9 (now the sum = 36) i=6 (now the sum = 16)
Is i<=10 true? Is i<=10 true?
Yes, do this Yes, do this
sum = sum + i = 36 + 9 = 45 sum = sum + i = 16 + 6 = 22
value of i
i=10 (now the sum = 45) value of i
Is i<=10 true? i=7 (now the sum = 22)
Yes, do this Is i<=10 true?
sum = sum + i = 45 + 10 = 55 Yes, do this
stops because the condition is i<=10 sum = sum + i = 22 + 7 = 29
The cout statement i.e., cout<<"sum of the first10 value of i
numbers = " << sum; make provision to display the i=8 (now the sum = 29)
output: Is i<=10 true?
sum of the first10 numbers = 55 Yes, do this
on the screen. sum = sum + i = 29 + 8 = 37
value of i
If the statement int i, sum = 0; is replaced by int i, sum i=9 (now the sum = 37)
= 1;
Is i<=10 true?
Then
Yes, do this
value of i
sum = sum + i = 37 + 9 = 46
i=1 (sum = 1 because the sum is initialized to 1 in the
value of i
statement int i, sum = 1;)
i=10 (now the sum = 46)
Is i<=10 true?
Is i<=10 true?
Yes, do this
Yes, do this
sum = sum + i = 1 +1 = 2
sum = sum + i = 46 + 10 = 56
value of i
stops because the condition is i<=10
i=2 (now the sum = 2)
Is i<=10 true?
The cout statement i.e., cout<<"sum of the first10
Yes, do this
numbers = " << sum; make provision to display the
sum = sum + i = 2 + 2 = 4 output:
value of i sum of the first10 numbers = 56
i=3 (now the sum = 4) on the screen.
Is i<=10 true?
107
(wrong result because the sum of the first 10 numbers average of the first 10 numbers = 5
is 55) because int is used instead of float.
What will be the output if the for loop statement for(i If the data type float is used i.e.,
=1; i<=10; i++) is replaced by the statement for(i =0; #include<iostream>
i<10; i++)?
using namespace std;
main()
Answer: ?
{
float a, avg, sum = 0;
If the statement int i, sum, sum = 0; is written instead
for( i=1; i<=10; i++)
of int i, sum = 0;
sum = sum + i;
Then the compilation error message will be displayed
on the screen (stating that sum is twice declared). avg = sum/10;
cout<<"sum of the first 10 numbers = " << sum;
If the for loop statement is ended with a semicolon cout<<"average of the first10 numbers = " << avg;
i.e., }
for(i=1; i<=10; i++); The output on the screen:
then the compilation error will be displayed on the sum of the first10 numbers = 55
screen. average of the first numbers = 5.5
108
Coding ground (Tutorials point)) and if the statement value of i
for( i=1; i<=10; i++); is written instead of the i=8 (now the product =5040)
statement Is i<=10 true?
for (i=1; i<=10; i++) Yes, do this
Then the Error will be flagged on the screen because product = product * i = 5040 * 8 = 40320
for loop statement is ended by a semicolon (;).
value of i
i=9 (now the product = 40320)
How the product of the first 10 digits = 3628800 is
Is i<=10 true?
outputted on the screen through the for Loop
statement Yes, do this
product = product * i = 40320 * 9 = 362880
value of i value of i
i=1 (product = 1 because the product is initialized to 1 i=10 (now the product = 362880)
in the statement int i, product = 1;) Is i<=10 true?
Is i<=10 true? Yes, do this
Yes, do this product = product * i = 362880 * 10 = 3628800
product = product * i = 1 * 1 =1 stops because the condition is i<=10
value of i
i=2 (now the product = 1) The cout statement i.e., cout<< "the product of the
Is i<=10 true? first 10 digits = " << product; make provision to
display the output:
Yes, do this
the product of the first 10 digits = 3628800
product = product * i = 1 * 2 = 2
on the screen.
value of i
i=3 (now the product = 2)
If the statement int a, product = 1; is replaced by int a,
Is i<=10 true?
product = 0;
Yes, do this
Then
product = product * i = 2 * 3 = 6
value of i
value of i
i=1 (product = 0 because the product is initialized to 0
i=4 (now the product = 6) in the statement int i, product = 0;)
Is i<=10 true? Is i<=10 true?
Yes, do this Yes, do this
product = product * i = 6 * 4 = 24 product = product * i = 0 * 1 = 0
value of i value of i
i=5 (now the product =24) i=2 (now the product = 0)
Is i<=10 true? Is i<=10 true?
Yes, do this Yes, do this
product = product * i = 24 * 5 =120 product = product * i = 0 * 2 = 0
value of i value of i
i=6 (now the product =120) i=3 (now the product = 0)
Is i<=10 true? Is i<=10 true?
Yes, do this Yes, do this
product = product * i = 120 * 6 = 720 product = product * i = 0 * 3 = 0
value of i value of i
i=7 (now the product =720) i=4 (now the product = 0)
Is i<=10 true? Is i<=10 true?
Yes, do this Yes, do this
product = product * i = 720 * 7 = 5040
109
product = product * i = 0 * 4 = 0 Is i<=8 true?
value of i Yes, do this
i=5 (now the product = 0) product = product * i = 5 * 1 = 5
Is i<=10 true? value of i
Yes, do this i=6 (now the product = 5)
product = product * i = 0 * 5 = 0 Is i<=8 true?
value of i Yes, do this
i=6 (now the product = 0) product = product * i = 5 * 6 = 30
Is i<=10 true? value of i
Yes, do this i=7 (now the product = 30)
product = product * i = 0 * 6 = 0 Is i<=8 true?
value of i Yes, do this
i=7 (now the product = 0) product = product * i = 30 * 7 = 210
Is i<=10 true? value of i
Yes, do this i=8 (now the product = 210)
product = product * i = 0 * 7 = 0 Is i<=8 true?
value of i Yes, do this
i=8 (now the product = 0) product = product * i = 210 * 8 = 1680
Is i<=10 true? stops because the condition i<=8 is achieved and the
Yes, do this statement
product = product * i = 0 * 8 = 0 cout<< "the product of the first 10 digits = " <<
value of i product;
i=9 (now the product = 0) make provision to display the output:
Is i<=10 true? the product of the first 10 digits = 1680
Yes, do this on the screen.
product = product * i = 0 * 9 = 0
value of i Note: If the statement int a, product, product = 1; is
written instead of int a, product = 1; Then the error is
i=10 (now the product = 0)
displayed on the screen (i.e., product is twice
Is i<=10 true? declared).
Yes, do this
product = product * i = 0 * 10 = 0 Program 7.0
stops because the condition is i<=10
The cout statement i.e., cout<< "the product of the C++ Program to print the table of a number
first 10 digits = " << product; make provision to
display the output:
#include<iostream>
the product of the first 10 digits = 0
using namespace std;
on the screen.
main()
(wrong result because the product of the first10 digits
{
is 3628800)
int n, i;
cout<<"Enter any number:";
If the statement for(a=1; a<=10; a++) is replaced by
for(a=5; a<=10; a++) cin>> n;
Then for( i=1; i<=5; i++)
value of i cout<< n << " * " << i << " = " << n*i;
i=5 (product = 1 because the product is initialized to 1 }
in the statement int i, product = 1;) The output on the screen:
Enter any number:
110
If you enter the number 2 (i.e., n=2) will be outputted on the screen.
2 * 1 = 22 * 2 = 42 * 3 = 62 * 4 = 82 * 5 = 10 will be
outputted on the screen. Program 7.1
And 2 * 1 = 2 2 * 2 = 42 * 3 = 62 * 4 = 82 * 5 =
10Ends because the condition is a<=5. C++ program:
If you enter a character M
If the statement cout<< n << " * " << i << " = " << Output must be: ch = M
n*i; is replaced by the statement
cout<< n << " * " << i << " = " << n*i<<endl;
#include<iostream>
i.e.,
using namespace std;
#include<iostream>
main()
using namespace std;
{
main()
char M;
{
cout<<"Enter any character:";
int n, i;
cin>>M;
cout<<"Enter any number:";
cout<<"ch= "<< M;
cin>> n;
}
for( i=1; i<=5; i++)
The output on the screen:
cout<< n << " * " << i << " = " << n*i <<endl;
Enter any character:
}
If you enter the character S
Then the output on the screen:
ch = S will be outputted on the screen.
2*1=2
2*2=4
If we replace the statement cin>>M; by the statement
2*3=6
M = getchar();
2*4=8
i.e.,
2 * 5 = 10
#include<iostream>
If * is replaced by +
using namespace std;
i.e.,
main()
#include<iostream>
{
using namespace std;
char M;
main()
cout<<"Enter any character:";
{
M = getchar();
int n, i;
cout<<"ch= "<< M;
cout<<"Enter any number:";
}
cin >> n;
There will be no change in the output on the screen
for( i=1; i<=5; i++) i.e., The output on the screen is:
cout<< n << " + " << i << " = " << n + i <<endl; Enter any character:
} If you enter the character K
The output on the screen: ch = K will be outputted on the screen.
Enter any number:
If you enter the number 3 (i.e., n=3) If we replace the statement cout<<"ch= "<< M; by the
3+1=4 statement putchar (M); i.e.,
3+2=5 #include<iostream>
3+3=6 using namespace std;
3+4=7 main()
3+5=8 {
111
char M;
cout<<"Enter any character:"; Program 7.2
cin>>M;
putchar (M); C ++ program to print the first 5 numbers starting
} from one together with their squares
There will be no change in the output on the screen
i.e., The output on the screen is: #include<iostream>
Enter any character: using namespace std;
If you enter the character M main()
M will be outputted on the screen. {
int i;
If we replace the statement cin>>M; by the statement for( i=1; i<=5; i++)
M = getchar(); cout<<"\n number = "<< i << "its square = "<< i*i;
and the statement cout<<"ch= "<< M; by the }
statement putchar (M); i.e., The output on the screen:
#include<iostream> number=1 its square=1
using namespace std; number=2 its square=4
main() number=3 its square=9
{ number=4 its square=16
char M; number=5 its square=25
cout<<"Enter any character:";
M = getchar(); How the execution takes its way through the for
putchar (M); loop statement
}
The output on the screen: value of i
Enter any character: i=1
If you enter the character S Is i<=5 true?
S will be outputted on the screen. Yes, print this
number=1 its square=1
Write a program to print the absolute value of a using the statement cout<<"\n number = "<< i << "its
number square = "<< i*i;
Answer: value of i
i=2
#include<iostream> Is i<=5 true?
#include<cmath> Yes, print this
using namespace std; number=2 its square=4
main() using the statement cout<<"\n number = "<< i << "its
{ square = "<< i*i;
int a, b;
a= - 2; value of i
b= abs(a); i=3
cout<<" absolute value of a = " << b<< endl; Is i<=5 true?
} Yes, print this
The output on the screen: number=3 its square=9
absolute value of a = 2
112
using the statement cout<<"\n number = "<< i << "its number=1 and its square=1
square = "<< i*i;
Suppose cout<<"\n number = " << i << "\t its square
value of i = "<< i*i; is replaced by the statement
i=4 cout<<"\n number = " << i << "\n its square = "<<
Is i<=5 true? i*i;
Yes, print this Then the output on the screen is:
number=4 its square=16 number=1
using the statement cout<<"\n number = "<< i << "its its square=1
square = "<< i*i; number=2
its square=4
value of i number=3
i=5 its square=9
Is i<=5 true? number=4
Yes, print this its square=16
number=5 its square=25 number=5
using the statement cout<<"\n number = "<< i << "its its square=25
square = "<< i*i;
Write a program to print the first 20 numbers starting
value of i from one together with their squares and cubes?
i=6
Is i<=5 true? Answer:
No, stop Now
Note: #include<iostream>
using namespace std;
If the statement cout<<"\n number = "<< i << "its main()
square = " << i*i; is replaced by the statement {
cout<<"\n number = " << i << "\t its square = "<< int i;
i*i; for( i=1; i<=20; i++)
i.e., cout<<"number = " << i <<" its square = " << i*i <<
#include<iostream> " its cube = " << i*i*i<< endl;
using namespace std; }
main()
{ What is the mistake in the following program:
int i;
for( i=1; i<=10; i++) #include<iostream>
cout<<"\n number = " << i << "\t its square = "<< using namespace std;
i*i; main()
} {
Then the output on the screen is: int i =1;
number=1 its square=1 for( i=0; i<=25; i++)
number=2 its square=4 cout<<"\n number = "<< i <<" its square = " << i*i;
number=3 its square=9 }
number=4 its square=16
number=5 its square=25
ENIAC wasThe FIRST Programming Language
tab /t is included because to leave space between Continuum
113
The value of the variable x = 1 because you have
Program 7.3 assigned the value 1 to the variable x by entering 1
through the keyboard.
C ++ program to print the sum of two numbers using
pointers If the statements
cout<<"The address of the variable x = "<< p;
If we create a integer variable x by declaring the cout<<"The value of the variable x = "<< *p;
statement int x; within the body of the main function are replaced by the statement
main() -- this variable is stored in the computer cout<<"The address of the variable x = " << p << "its
memory i.e., this variable occupies a specific location value = " << *p;
in the space of computer memory. And this integer i.e.,
variable x is assigned an address (i.e., &x) to locate its
#include<iostream>
position in the computer memory (like a house in the
street is assigned an address to locate its position in using namespace std;
the street). Pointers are the variables that represent the main()
address of x in the computer memory i.e., p = &x, {
where &x imply the address of x in the computer int x, *p;
memory and p is the pointer variable (which is the cout<<"Enter any integer:";
variable that represent the address of x in the computer
cin >> x;
memory). And further if you assign a value to the
variable x by declaring the statement x=1; within the p = &x;
body of the main function—this value is stored in the cout<< "The address of the variable x = " << p << "its
address of x in the computer memory. “*” denote value = " << *p;
pointer operator and *p denote the pointer (which }
represent the value stored in the address of x in the Then the output on the screen is:
computer memory).
The address of the variable x = 0x7fff78508cc4 its
value = 2
C ++ program to print the address of x and the value
assigned to x
#include<iostream>
using namespace std;
#include<iostream>
main()
using namespace std;
{
main()
int x, y, *p, *q, sum;
{
cout<<"Enter any number:";
int x, *p;
cin >> x;
cout<<"Enter any integer:";
cout<< "Enter any number:";
cin>>x;
cin >> y;
p = &x;
p = &x;
cout<<"The address of the variable x = " << p;
q = &y;
cout<< "The value of the variable x = " << *p;
sum = *p + *q;
}
cout<< "\n sum of entered numbers = "<< sum;
The output on the screen:
}
Enter any integer:
The output on the screen:
If you enter the integer 1
Enter any number:
The address of the variable x = 0x7fffc60478a4
If you enter the number 4
The value of the variable x = 1
Enter any number:
will be outputted on the screen.
If you enter the number 3
sum of entered numbers = 7 will be outputted on the
screen.
114
Since *p imply the value assigned to the variable x C++ program to find the greatest of two numbers
(i.e., 4) by entering 4 through the keyboard and *q using pointers
imply the value assigned to the variable y (i.e., 3) by
entering 3 through the keyboard. Therefore: #include<iostream>
sum = *p + *q = 4 + 3 = 7 (which is outputted on the using namespace std;
screen).
main()
{
“As soon as we started programming, we found to our
int x, y, *p, *q;
surprise that it wasn't as easy to get programs right as
we had thought. Debugging had to be discovered. I cout<<"Enter any integer:";
can remember the exact instant when I realized that a cin>> x;
large part of my life from then on was going to be cout<< "Enter any integer:";
spent in finding mistakes in my own programmes.” cin>> y;
p = &x;
- Maurice Wilkes discovers debugging, 1949. q = &y;
if(*p>*q)
C++ program to print the product, subtraction and {
division of two numbers using pointers cout<<"x is greater than y";
}
#include<iostream> if(*q>*p)
using namespace std; {
main() cout<<"y is greater than x";
{ }
int x, y, *p, *q, product, subtract, div; }
cout<<"Enter any number:"; The output on the screen:
cin>> x; Enter any integer:
cout<< "Enter any number:"; If you enter the integer 10
cin>> y; Enter any integer:
p = &x; If you enter the integer 16
q = &y; y is greater than x will be outputted on the screen.
product = *p * *q;
subtract = *p - *q; Program 7.4
div= *p / *q;
cout<<"\n product of entered numbers = "<< product; #include <iostream>
cout<<"\n subtract of entered numbers = "<< subtract; using namespace std;
cout<<"\n division of entered numbers = "<< div; int add (int x, int y)
} {
The output on the screen: return x + y;
Enter any number: }
If you enter the number 4 main()
Enter any number: {
If you enter the number 2 int x, y;
product of entered numbers = 8 cout<<"Enter any integer:";
subtract of entered numbers = 2 cin>>x;
division of entered numbers = 2 cout<<"Enter any integer:";
will be outputted on the screen. cin>>y;
115
result = add (x, y); result (i.e., 35) to the statement cout<<"sum of two
cout<<"sum of two integers = "<< result; numbers= "<< result; to make provision to display the
} output of the sum of two entered integers as 35 on the
screen.
The output on the screen:
If the statement int add (int x, int y); is written instead
Enter any integer:
of int add (int x, int y)
If you enter the integer 30
Enter any integer:
#include <iostream>
If you enter the integer 5
using namespace std;
sum of two integers = 35 will be outputted on the
int add (int x, int y);
screen.
{
Note: No function declaration is required in C++ i.e.,
the statement int add (int x, int y); is not required return x + y;
(without the statement int add (int x, int y); the }
program will be successfully executed and the result main()
will be outputted on the screen) {
int x, y;
int add (int x, int y) imply the function to add two cout<<"Enter any integer:";
integers x and y and cin>>x;
{ cout<<"Enter any integer:";
return x + y; cin>>y;
}imply the body of function int add (int x, int y) result = add (x, y);
cout<<"sum of two integers = "<< result;
main() imply main function and }
{ Then the error is displayed on the screen.
} imply the body of main function in which the
program statements:
If the statement int add (intx, inty); is written instead
int x, y; of int add (int x, int y); i.e., no space is left between
cout<<"Enter any integer:"; int and x (and int and y)
cin>>x; Then the compilation error is displayed on the screen.
cout<<"Enter any integer:";
cin>>y; If the above program is rearranged:
result = add (x, y); i.e., the program
cout<<"sum of two integers = "<< result;
are written. #include <iostream>
using namespace std;
The statement int x, y; imply that we creating the main()
integer variables x and y. {
The statements int x, y;
cout<< "Enter any integer: "; cout<<"Enter any integer:";
cin>>x; cin>>x;
cout<< "Enter any integer: "; cout<<"Enter any integer:";
cin>>y; cin>>y;
make provision to supply the values for x and y result = add (x, y);
through the keyboard.
cout<<"sum of two numbers= "<< result;
The statement result = add (x, y); imply function call
}
(i.e., we are calling the function int add (int x, int y) to
add the entered values (i.e., 30 and 5) and return the int add (int x, int y)
{
116
return x + y; product of two numbers = 150 will be outputted on the
} screen.
is written instead of
C ++ program to print the greatest of two numbers
#include <iostream> using functions
using namespace std;
int add (int x, int y) #include <iostream>
{ using namespace std;
return x + y; int max (int x, int y)
} {
main() if(x>y)
{ return x;
int x, y; if(y>x)
cout<<"Enter any integer:"; return y;
cin>>x; }
cout<<"Enter any integer:"; main()
cin>>y; {
result = add (x, y); int x, y;
cout<<"sum of two numbers= "<< result; cout<<"Enter any integer: ";
} cin>>x;
i.e., if the body of main function is written first and cout<<"Enter any integer: ";
the body of the function int add (int x, int y) is written cin>>y;
next result = max (x, y)
Then the compilation error is displayed on the screen. cout<<"largest of two integers = " << result;
}
C ++ program to print the product of two numbers The output on the screen:
using functions Enter any integer:
If you enter the integer13
#include <iostream> Enter any integer:
using namespace std; If you enter the integer 15
int mult (int x, int y) largest of two integers = 15 will be outputted on the
{ screen.
return x * y;
} C++ program to print the greatest of three numbers
main() using functions
{
int x, y; #include <iostream>
cout<<"Enter any two numbers:"; using namespace std;
cin>>x; int max (int x, int y, int z)
cin>>y; {
result = mult (x, y); if(x>y && x>z)
cout<<"product of two numbers= " << result; return x;
} if(y>x && y > z)
The output on the screen: return y;
Enter any two numbers: if(z>x && z>y)
If you enter the two numbers 3 and 50 return z;
117
}
main() Switch (case) allows to make decision from the
{ number of choices i.e., from the number of cases
int x, y, z; For example:
cout<<"Enter any integer: "; #include <iostream>
cin>>x; using namespace std;
cout<<"Enter any integer: "; main()
cin>>y; {
cout<<"Enter any integer: "; char ch;
cin>>z; cout<< "Enter any character: ";
cout<<"largest of three integers = " << result; cin >> ch;
} switch(ch)
The output on the screen: {
Enter any integer: case 'R':
If you enter the integer 3 cout<<"Red";
Enter any integer: break;
If you enter the integer 5 case 'W':
Enter any integer: cout<<"White";
If you enter the integer 10 break;
largest of three integers = 10 will be outputted on the case 'Y':
screen. cout<<"Yellow";
break;
C++ program to print the square of the number using case 'G':
functions cout<<"Green";
break;
#include <iostream> default:
using namespace std; cout<<"Error";
int square (int x) break;
{ }
return x*x; }
} The output on the screen:
main() Enter any character:
{ If you enter a character R
int x; Red will be outputted on the screen.
cout<<"Enter any integer:";
cin>>x; switch(ch) allow to make decision from the number of
result = square (x); choices i.e., from the number of cases
cout<<"square of the number = " << result); case 'R':
} case 'W':
The output on the screen is: case 'Y':
Enter any integer: case 'G':
If you enter an integer 5 Since we have entered the character R (which
square of the number = 25 will be outputted on the corresponds to case 'R': )
screen. The statement
cout<<"Red";
Program 7.5 make provision to display the output
118
Red cout<<"Error";
on the screen. break;
Suppose you enter a character K }
The output on the screen is: i.e., if the statement break; is not written after the
Error statements
(Entered character K does not correspond to any of the case 'R':
cases cout<<"Red";
case 'R':
case 'W': case 'W':
case 'Y': cout<<"White";
case 'G': Then the output on the screen is:
Therefore the statements Red
default: White
cout<<"Error"; make provision to display the output Yellow
Error i.e., the output is printed till yellow even though you
on the screen). have entered the character R.
If the statements
{ Program 7.6
case 'R':
cout<<"Red"; C ++ program to print the output
break;
case 'W': Element [0] = 16
cout<<"White"; Element [1] = 18
break; Element [2] = 20
case 'Y': Element [3] = 25
cout<<"Yellow"; Element [4] = 36
break; using arrays:
case 'G':
cout<<"Green"; #include<iostream>
break; using namespace std;
default: main()
cout<<"Error"; {
break; int i;
} are replaced by the statements int num [5] = {16, 18, 20, 25, 36};
{ for(i=0; i<5; i++)
case 'R': cout<< "Element [" << i << " ] = "<< num[i] << endl;
cout<<"Red"; }
case 'W': The output on the screen:
cout<<"White"; Element [0] = 16
case 'Y': Element [1] = 18
cout<<"Yellow"; Element [2] = 20
break; Element [3] = 25
case 'G': Element [4] = 36
cout<<"Green"; Ends because of the condition i<5.
break;
default:
119
The statement int num [5] = {16, 18, 20, 25, 36}; i=2
imply that we are creating an integer array (and the Is i<5 true?
name of array is num) consisting of 5 values (i.e., 16, Yes, print this
18, 20, 25, 36) of the same data type int. And the
Element [2] = 20
number of values between the braces { } cannot be
larger than the number of values that we declare for using the statement
the array between square brackets [ ]. Because there cout<< "Element [" << i << " ] = "<< num[i] <<
are 5 integers i.e., 16, 18, 20, 25, 36 within the braces endl;
{ }, 5 is written within the square brackets [ ]. If there
were 6 integers i.e., 16, 18, 20, 25, 36, 42 within the value of i
braces { }, then 6 must be written within the square i=3
brackets [ ].
Is i<5 true?
Yes, print this
Note: With the declaration int num [5], computer
Element [3] = 25
creates 5 memory cells with name num[0], num[1],
num[2], num[3], num[4]. And since using the statement
int num [5] = {16, 18, 20, 25, 36}; cout<< "Element [" << i << " ] = "<< num[i] <<
endl;
the values 16, 18, 20, 25, 36 are stored in num[0],
num[1], num[2], num[3], num[4] respectively.
value of i
i=4
An integrated circuit (more often called an IC, Is i<5 true?
microchip, silicon chip, computer chip, or chip) is a piece Yes, print this
of specially prepared silicon (or another semiconductor) Element [4] = 36
into which a very complex electronic circuit is etched
using photographic techniques. using the statement
cout<< "Element [" << i << " ] = "<< num[i] <<
How the execution takes its way through the for endl;
loop statement Stop because the condition is i<5.
value of i
120
Suppose the statement cout<< "Element [" <<i<<" ] = Element [2] = 36
"<< num[i]<< endl; is replaced by the statement Element [3] = 36
cout<< "Element [" <<i<<" ] = "<< num[0]<< endl; Element [4] = 36
Then the output on the screen:
Element [0] = 16 Note:
Element [1] = 16
Element [2] = 16 (a) C++ program to print the sum of the elements in
Element [3] = 16 array.
Element [4] = 16
#include<iostream>
Suppose the statement cout<< "Element [" << i <<" ] using namespace std;
= "<< num[i]<< endl; is replaced by the statement main()
cout<< "Element [" << i <<" ] = "<< num[1]<< endl; {
The output on the screen: int i, sum = 0;
Element [0] = 18 int num [5] = {16, 18, 20, 25, 36};
Element [1] = 18 for(i=0; i<5; i++)
Element [2] = 18 sum = sum + num[i];
Element [3] = 18 cout<<"Sum of the Elements in the array = " << sum;
Element [4] = 18 }
The output on the screen:
Suppose the statement cout<< "Element [" <<i<<" ] = Sum of the Elements in the array = 115
"<< num[i]<< endl; is replaced by the statement i.e., 16 + 18 + 20 + 25 + 36 = 115
cout<< "Element [" <<i<<" ] = "<< num[2]<< endl;
i.e., num[2] corresponds to the output: How the Execution takes its way through the for
Element [0] = 20 loop statement
Element [1] = 20
Element [2] = 20 value of i
Element [3] = 20 i=0 (sum = 0 because the sum is initialized to 0 in the
Element [4] = 20 statement int i, sum = 0;)
Is i<5 true?
Suppose the statement cout<< "Element [" <<i<<" ] = Yes, do this
"<< num[i]<< endl; is replaced by the statement sum = sum + num[i] = sum + num[0] = 0 +16 =16
cout<< "Element [" <<i<<" ] = "<< num[3]<< endl; value of i
i.e., num[3] corresponds to the output: i=1 (now the sum = 16)
Element [0] = 25 Is i<5 true?
Element [1] = 25 Yes, do this
Element [2] = 25 sum = sum + num[i] = sum + num[1] = 16 +18 =34
Element [3] = 25
Element [4] = 25 value of i
i=2 (now the sum = 34)
Suppose the statement cout<< "Element [" <<i<<" ] = Is i<5 true?
"<< num[i]<< endl; is replaced by the statement Yes, do this
cout<< "Element [" << i<<" ] = " << num[4]<< endl; sum = sum + num[i] = sum + num[2] = 34 +20 =54
i.e., num[4] corresponds to the output:
Element [0] = 36 value of i
Element [1] = 36 i=3 (now the sum = 54)
121
Is i<5 true? using namespace std;
Yes, do this main()
sum = sum + num[i] = sum + num[3] = 54 +25 =79 {
int a, b, c;
a=5;
value of i b=7;
i=5 (now the sum = 79) c = a | b;
Is i<5 true? cout<< " the value of c = " << c;
Yes, do this }
sum = sum + num[i] = sum + num[5] = 79 + 36 =115
stops because the condition is i<5 Answer: 7
The cout statement i.e., cout<<"Sum of the Elements
in the array = " << sum; make provision to display the 23 22 21 20
output:
8 4 2 1
Sum of the Elements in the array = 115
on the screen.
Since a = 5
If the statement
23 22 21 20
int i, sum = 0; is replaced by int i, sum = 1;
8 4 2 1
Then The output on the screen:
0 1 0 1
Sum of the Elements in the array = 116
(wrong result because the sum of 5 elements in the
array is 115).
Since b = 7
(b) C ++ program to print the average of the elements
in array 23 22 21 20
8 4 2 1
#include<iostream> 0 1 1 1
using namespace std;
main() | denote bit wise or operator
{ Whereas || denote logical or operator
int i, avg, sum = 0;
int num [5] = {16, 18, 20, 25, 36}; a|b
for(i=0; i<5; i++)
sum = sum + num[i];
0 1 0 1
avg = sum/5;
0 1 1 1
cout<<"Sum of the Elements in the array = " << sum;
0 1 1 1
cout<<"average of the Elements in the array = " <<
avg;
}
The output on the screen: 23 22 21 20
Sum of the Elements in the array = 115 8 4 2 1
average of the elements in the array = 23 0 1 0 1
0 1 1 1
What will be the output of the following program: 0 1 1 1
#include<iostream> 0×8+1×4+1×2+1×1=7
122
0 1 0 1
a|b=7 0 1 1 1
0 1 0 1
What is the output of the following program:
0×8+1×4+0×2+1×1=5
#include<iostream>
using namespace std; a&b=5
main()
{ Note:
int a, b, c; Bitwise OR table
a=5; Hint: addition
b=7;
c = a & b; a b a|b
cout<< " the value of c = " << c; 0 1 1
} 1 0 1
Answer: 5 1 1 1
0 0 0
23 22 21 20
8 4 2 1 Bitwise AND table
Hint: multiplication
Since a = 5
a b a&b
23 22 21 20 0 1 0
8 4 2 1 1 0 0
0 1 0 1 1 1 1
0 0 0
23 22 21 20 a b a^ b
8 4 2 1 0 1 1
0 1 1 1 1 0 1
1 1 0
& denote bit wise and operator 0 0 0
Whereas && denote logical and operator
What will be the output of the following C program:
a&b
#include <stdio.h>
0 1 0 1 main()
0 1 1 1 {
0 1 1 1 int a, b, c;
a=2;
b=3;
23 22 21 20 c= ~ (a ^ b);
8 4 2 1 printf("value of c = %d", c);
123
}
Hello World
Answer: ?
Hello World
Note:
~ denote bit wise negation operator Program 7.7
Negation truth table
C++ program to print the output:
a b a^ b ~ (a ^ b) Name of the book = B
0 1 1 0 Price of the book = 135.00
0 0 1 0 Number of pages = 300
1 1 0 1 Edition = 8
0 1 0 1 using structures
124
pages (which is of data type int), edition (which is of using namespace std;
data type int) – which are placed within the body of struct book {
the structure. char name;
float price;
The statement int pages;
struct book b1; int edition;
imply the structure variable declaration (where b1 };
denote the structure variable)
main()
{
Why structure variable b1 is declared or defined?
struct book b1;
b1.name = 'C';
In order to assign the values to the elements within the
b1.price = 135.00;
body of the structure, each element must be linked
with structure variable with dot operator or period b1.pages = 300;
operator or member accessibility operator. For b1.edition = 8;
example: name is the element which must be linked cout<<"Name of the book = bulgarian " << b1.name
with structure variable b1 with dot operator to assign a << endl;
value B to the element “name”. cout<<"\n Price of the book = " << b1.price;
cout<<"\n Number of pages = " << b1.pages<<endl;
The cout statement cout<< "\n Edition of the book = "<< b1.edition;
cout<<"Name of the book = "<< b1.name<< endl; }
make provision to print the output on the screen:
Name of the book = B What will be the output of the following program:
on the screen.
#include <iostream>
Similarly,
The statement using namespace std;
cout<<"Price of the book = "<< b1.price<<endl; main()
make provision to print the output: {
Price of the book = 135.00 int F, m, a;
on the screen. m=2;
a=3;
The statement F=m*a;
cout<<"Number of pages = "<< b1.pages<<endl; cout << "force applied to the mass = " << F << "\t
make provision to print the output: Newton" << endl;
Number of pages = 300 }
on the screen.
Answer:
The statement force applied to the mass = 6 Newton
cout<<"Edition of the book = "<< b1.edition<< endl;
make provision to print the output: Examine the following program and write the
Edition of the book = 8 output:
on the screen.
125
main() organisms and evolve through a highly sophisticated
{ form of life to primitive mammals"<<endl;
cout<<" \n E=mc squared Einstein's famous equation long int v;
that gave birth to the atom bomb and heralded a new v=300000000;
world of atomic physics"<<endl; c=300000000;
cout<<" \n if (v==c)
"<<endl; cout<<" \n rest mass of the photon is zero because
cout<<" \n E = energy m = mass c = speed of light in light travels at the speed of light"<<endl;
vacuum"<<endl; else
cout<<"\n As we know c squared is huge so if you cout<<" \n Albert Einstein’s special theory of
convert a small amount of mass you'll get a relativity has to be rewritten"<< endl;
tremendous amount of energy" <<endl;
int E1;
cout<<" \n For example if you convert 1kg of mass
E1=2;
you'll get energy of "<<endl;
if (isalpha(E1))
long int E, m, c;
cout<<"\n Einstein’s equation does not hold good"<<
m=1;
endl;
c=300000000;
else
E=m*c*c;
cout<<"\n Einstein’s equation holds good because
cout<<"\n "<< E << " joules "<<endl; light has zero rest mass"<<endl;
cout<<"\n address of Energy E in the computer cout<<"\n masses of the individual substances are 16
memory = " <<&E <<endl; \t 18 \t 19 \t 20\t 21\t kilograms" << endl;
cout<<"\n address of Energy m in the computer int j, sum = 0;
memory = " <<&m <<endl;
int num [5] = {16, 18, 19, 20, 21};
cout<<"\n address of Energy c in the computer
for(j=0; j<5; j++)
memory = " <<&c <<endl;
sum = sum + num [j];
int b, z, a;
cout<<"\n sum of the masses of the individual
b = sizeof(E);
substances = " << sum<< endl;
z = sizeof(m);
cout<<"\n sum of the energies of the individual
a = sizeof(z); substances = " << sum * 300000000 * 300000000 <<
cout<<"\n space occupied by E in the computer endl;
memory = "<< b <<"bytes"<< endl; cout<< "\n average energy = " << sum / 5<< endl;
cout<<"\n space occupied by m in the computer cout<<"\n
memory = "<< z <<"bytes"<< endl; "<< endl;
cout<<"\n space occupied by c in the computer cout<<"\n
memory = "<< a <<"bytes"<< endl; "<< endl;
cout<<" \n Suppose c would have been 3×10 to the int p, q, r;
power of -8 meter per second then For 1 kg of mass E
p= 6;
= 9 ×10 to the power of -16 joules"<< endl;
q= 3;
cout<<" \n hence thousands and thousands of
hydrogen atoms in the sun would have to burn up to cout<< "\n expected energy = " << p << "multiplied
release 4 × 10 to the power of 26 joules of energy per by ten to the power of minus 16 joules calculated
second in the form of radiation"<< endl; using Einstein equation"<< endl;
int i; cout<< "\n experimental energy = " << q <<
"multiplied by ten to the power of minus 16 joules
for(i=0; i<5;i++)
calculated using Einstein equation"<< endl;
cout<<" \n Therefore sun would have ceased "<< endl;
r= q-p;
cout<<"to form black hole even before an ooze of
cout<< "\n difference between experimental energy
organic molecules would react and built earliest cells
and expected energy ="<< r << " multiplied by ten to
and then advance to a wide variety of one celled
the power of minus 16 joules"<< endl;
126
cout<<"\n absolute value of the difference between b1.edition = 8;
experimental energy and expected energy cout<<"\n Name of the book =
="<<abs(r)<<"multiplied by ten to the power of minus "<<b1.name<<"insteinian physics" << endl;
16 joules" << endl; cout<<"\n Price of the book = " << b1.price << endl;
char k; cout<< "\n Number of pages = " << b1.pages<< endl;
char einstein [10] ={'e', 'm', 'c', 's', 'q', 'u', 'a', 'r', 'e', 'd'}; cout<<"\n Edition of the book = "<<b1.edition<<" th
for(k=0; k<10; k++) edition"<< endl;
cout<<"\n Einstein["<<einstein [k]<<"] = " <<einstein cout<<"*************************************
[k] << endl; ********\n" ;
int s; cout<<"*************************************
cout<<"\n Hey! Einstein may not be wrong please *******\n";
repeat the experiment"<<endl; cout<<" According to the Albert Einstein’s law of
for(s=1; s<3; s++) variation of mass with velocity: \n";
cout<<"\n * "; cout<<" M = m0 / sqrt ((1- (u/c) squared) \n ";
cout<<"\n ***** "; cout<<" M = mass of the moving body \t m0 = rest
cout<<"\n **Albert Einstein** "; mass of the body \t u= velocity of the body \t c= speed
cout<<"\n **e= mc squared** "; of light in vacuum\n ";
cout<<"\n *****"; {
double EP, h, f; double M, m0;
f=2; long int u, c, b;
h=pow((6.625), -34); m0 = 0.999;
EP= h*f; u = 200000000;
cout<<"\n energy calculated using the Planck c = 300000000;
equation = " << EP << endl; b = u/c * u /c;
if (E== EP) M = m0 / sqrt (1 - b);
cout<<"\n hf cannot be equivalent to mc squared"<< cout<<" \n Mass of the moving body = "<< M<<endl;
endl; if (M==m0 || M<m0)
if (E>EP) cout<<" \n body is at rest or the body is moving with
cout<<"\n hf can be equivalent to mc squared"<< nonrelativistic speed"<<endl;
endl; else
if (E<EP) cout<<" \n body is moving with relativistic
cout<<"\n Einstein and Planck equation cannot be speed"<<endl;
equalized"<<endl; }
cout<<"\n "<<endl; }
cout<<"\n "<<endl;
cout<<"\n for more details please refer the book IX
"<<endl;
struct book { Java
char name;
float price; “Without requirements or design, programming is the
int pages; art of adding bugs to an empty text file. (Louis
int edition; Srygley)”
};
struct book b1; JAVA is a high level programming language
b1.name = 'E'; conceived by James Gosling, Patrick Naughton, Chris
Warth, Ed Frank, and Mike Sheridan at Sun
b1.price = 135.00;
Microsystems, Inc. in 1991 to create programs to
b1.pages = 300; control consumer electronics (which is now a
127
subsidiary of Oracle Corporation) and released in {
1995, used in internet programming, mobile devices,
games, e-business solutions etc., because of its } imply the body of the main method (Here: the curly
reliability, high performance, simplicity and easy to brace ‘{’ imply the beginning of the main method and
use and quick to learn and rigid versus extensibility. the curly brace ‘}’ imply the end of the main method)
within which the program statements i.e.,
Process of Java program execution: A Java program: System.out.println("Hello, World!");
public class HelloWorld { is written and executed (i.e., main method in java
public static void main(String [] args) { functions like main function main () in C and C++).
System.out.println("Hello, World!"); If the statement public class HelloWorld is replaced
} by the statement public class sample i.e., if the above
} is written in notepad or text pad or java editor is program is rewritten as:
called the source program (Unlike C & C++ language, public class sample {
java is a platform independent language because java public static void main(String [] args) {
program can be written in notepad or text pad or java System.out.println("Hello, World!");
editor and executed) and this source program is saved }
as HelloWorld .java (because the class name is public
}
class HelloWorld {} the source file should be named
as HelloWorld. java) and sent to the java compiler Then the error will be displayed on the screen because
(i.e., javac compiler) where the source program is the program written in notepad or text pad or java
compiled (i.e., the program is entirely read and editor is saved as HelloWorld.java not as sample.java.
translated into Java byte codes (but not into machine If we want to write the statement public class sample
language)). If the javac compiler finds any error instead of the statement public class HelloWorld, then
during compilation, it provides information about the we have to save the program written in notepad or in
error to the user. The programmer has to review code java editor as sample.java or but not as
and check for the solution. And if there are no errors HelloWorld.java. As said earlier, like C & C++, Java
the translated program (i.e., java byte codes -- a highly is not platform dependent because java program can
optimized set of instructions) is stored in computers be written in notepad/ text pad or java editor and can
main memory as HelloWorld.class and since the java be executed (whereas C & C++ program can only be
byte codes cannot be trusted to be correct—therefore written in C & C++ editor and can be executed). And
before execution they are verified and converted to like C & C++, Java is also a case sensitive language
machine level language i.e., machine code sequence of i.e., capital letters (or upper case letters) must be
0’s and 1’s by Java run-time system, which is called avoided to prevent the display of error on the screen
the Java Virtual Machine (JVM) and is executed by a (For example: If the statement PUBLIC static void
Java interpreter and main(String [] args) is written instead of the statement
public static void main(String [] args) or the statement
Hello, World!
Public class HelloWorld is written instead of public
is displayed on the screen. class HelloWorld, compilation Error will be displayed
public class HelloWorld imply class and on the screen). And if we forget to end each program
{ statement within the body of main method with a
semicolon (;), Error will be displayed on the screen
} imply the body of the class (Here: the curly brace ‘{’ i.e., if we forget to end the statement
imply the beginning of the class and the curly brace System.out.println("Hello, World!") with a semicolon
‘}’ imply the end of the class) within which the main (;), Error will be displayed on the screen. After the
method compilation of the source program, the translated (or
the complied) program is stored in the computer’s
public static void main(String [] args) memory as object file and the program is executed.
{ The program begins its execution with the method
} is written. public static void main (String [] args) (which is called
public static void main(String [] args) imply main the main method -- the entry point of the program
method (a collection of statements or methods like execution). If a program begins its execution with
System.out.println( ) that are grouped together to main method, it takes the control of the computer from
perform an operation) and the operating system. And after the complete
128
execution of the program, the execution is terminated If the statement
and the main method returns back the control to the public static void main(String [] args)
operating system. or
Semicolon: program is a set of instructions and each public static void main(String [] jamesgosling)
instruction (or each statement) is ended by a
or
semicolon. Like in an English paragraph each
sentence is ended by a full stop which tells that one public static void main(String [] java)
sentence ends and another begins, semicolon implies is replaced by the statement public static void
that one instruction (or statement) ends and another main(String []) -- Then the error is displayed on the
begins. screen. Because no word is written after String [] –
any word say args or argv or java or jamesgosling
System.out.println (" ") → method which
should be written after string[] to prevent the display
displays the statement enclosed by the double
of error on the screen.
quotation marks with the parenthesis of
System.out.println i.e., displays the output: Note: Most Java programmers prefer args and argv
i.e., the statements
Hello, World!
public static void main(String [] args) and public static
on the screen.
void main(String [] argv) are preferred.
Note: if “ ” is used instead of " ", Error will be
If the statement public static void main (String []
displayed on the screen
jamesgosling) is replaced by the statement public
The statement System.out.println("Hello, World!"); static void main (String [] james gosling) i.e., space is
will not display any error on the screen. left between the words james and gosling. Then the
The statement System.out.println(“Hello, World!”); compilation error will be displayed on the screen.
will display error on the screen. jamesgosling → no error.
Even though the statement System.out.print("Hello, james gosling → error.
World!"); is written instead of the statement
Similarly, if the space is left between the words Hello
System.out.println("Hello, World!"); i.e., instead of
and World i.e., if the statement public class Hello
println only print is used ‒ no compilation error will
World is written instead of the statement public class
be displayed on the screen i.e., Hello, World! will be
HelloWorld. Then the compilation error will be
outputted on the screen without display of any
displayed on the screen.
compilation error on the screen.
If the word args in the statement public static void
main(String [] args) is replaced by another word say Note: All the programs written in java editor is saved
jamesgosling or java as HelloWorld.java and executed – hence public class
HelloWorld corresponds to all programs.
i.e., the above program is rewritten as:
public class HelloWorld
The IBM Personal Computer, commonly known as the
{ IBM PC, is the original version and progenitor of the
public static void main(String [] jamesgosling) IBM PC compatible hardware platform.
{
System.out.println("Hello, World!"); Program 7.8
}
} Java program to print the word “hello Bill Gates” on
or screen
public class HelloWorld {
public static void main (String [] java) { public class HelloWorld {
System.out.println("Hello, World!"); public static void main (String [] args) {
} System.out.println("hello Bill Gates");
} }
No compilation error will be displayed on the screen }
i.e., Hello, World! will be outputted on the screen The output on the screen:
without display of any error on the screen. hello Bill Gates
129
*
Program 7.9 ****
**java**
Java program to print the word “****hello silicon ****
city****” on screen *
(b)
public class HelloWorld {
public static void main(String [] args) { ****************
System.out.println(" ****hello silicon city**** "); **
} * Hello World! *
} **
The output on the screen: ****************
****hello silicon city****
Program 8.0 (c)
130
} If multiplication sign × is used instead of
} multiplication operator * i.e.,
area = 4 × 3.14 × r × r;
then the compilation error is displayed on the screen.
public class HelloWorld { In C language, the statement
public static void main (String [] args) { printf("The area of the circle = %d ", area);
System.out.println("\n Braces come in pairs!"); make the provision to print the output on the screen.
System.out.println("\n Comments come in pairs!"); In C++ language, the statement
System.out.println("\n All statements end with a cout<< "The area of the circle = " << area;
semicolon!"); make the provision to print the output on the screen.
System.out.println("\n Spaces are optional!"); whereas in the Java language, the statement
System.out.println("\n Must have a main method!"); System.out.println("The area of the circle = " + area);
System.out.println("\n java is done mostly in make the provision to print the output on the screen.
lowercase. Like C & C++ it’s also a case-sensitive In the statement System.out.println("The area of the
language"); circle = " + area);
} There are two strings:
} 1. The area of the circle =
2. area
Program 8.1 plus operator (+) functions as the
concatenation operator (concatenation means
connecting two statements to produce a single
Java program to find the area of the circle
statement) – which (here) concatenates the string “The
area of the circle = ” and the string “area (which is 4 *
public class HelloWorld { 3.14 * r * r (=50 since r = 2))” -- producing a String
public static void main (String [] args) { statement
int r, area; The area of the circle = 50 which is displayed on the
r = 2; screen as the result.
area = 4 * 3.14 * r * r;
System.out.println("The area of the circle = " + area); If the statement System.out.println("The area of the
} circle = " area); is written instead of the statement
System.out.println("The area of the circle = " +
}
area); i.e., plus sign is omitted. Then the compilation
The output on the screen: error will be displayed on the screen.
The area of the circle = 50 (Like in C and C++)
int means the integer data type. If the multiplication sign × is used instead of
Note: An integer is a whole number — no fractions, multiplication operator * i.e.,
decimal parts, or funny stuff. The statement area = 4 × 3.14 × r × r; is written
The statement instead of area = 4 * 3.14 * r * r
int r, area; imply that we are creating the integer then the compilation error will be displayed on the
variables r , area. screen.
The statements The area of the circle is = 50. 24 (for r = 2) but The
r = 2; area of the circle = 50 is displayed on the screen
area = 4 * 3.14 * r * r; because the data type int is used instead of data type
float.
imply that we are assigning the values to the created
variables (i.e., we are assigning the value 2 for r and 4 If the data type float is used instead of int i.e., the
* 3.14 * r * r for area). above program is rewritten as:
Comma in the statement int r, area; imply variable public class HelloWorld{
separator. public static void main(String [] args) {
float r;
131
r = 2; l=2;
area = 4 * 3.14 * r * r; b=2.5;
System.out.println("The area of the circle = " + area); area = l*b;
} System.out.println("The area of the rectangle = " +
} area);
Then the output on the screen is: }
The area of the circle = 50.24 }
If you write 4 * 3.14 * r ^ 2; instead of 4 * 3.14 * r * r;
(where r ^ 2 → r to the power of 2 or r square), then public class HelloWorld {
error is displayed on the screen because unlike other public static void main (String [] args) {
high level languages – there is no operator for int a, b, c;
performing exponentiation operation i.e., (like in C
a= 3;
and C++) there is no operator for performing r ^ 2
operation so the statement 4 * 3.14 * r ^ 2; is invalid. b=3;
Even though if we write ARGS instead of args i.e., c=3;
even though if we express args in capital letter, No if ((a + b< c) || (b + c < a) || (a==b && b==c))
error is displayed on the screen. System.out.println(" the triangle is equilateral");
public static void main(String [] ARGS) → no error is else
displayed on the screen. System.out.println(" the triangle is not possible");
}
Note: }
In
public class HelloWorld What is the mistake in the following program:
HelloWorld is the name of the file within the source
program is saved. public class HelloWorld because the public class HelloWorld {
source program is saved in the file named
public static void main (String [] argv) {
HelloWorld.java.
float l, b, area, volume;
l=2;
Program 8.1
b=2.5;
h =2.9
Java program to find the circumference of the circle
area = l*b;
volume = l*b*h;
public class HelloWorld {
public static void main (String [] args) { System.out.println("The volume of the rectangle = " +
area);
float r, circumference;
}
r = 2;
circumference = 3.14 * r * r;
“Shut up and code.”
System.out.println("The circumference of the circle =
ANONYMOUS - NOTICE ON THE OFFICE WALL
" + circumference);
OF AN INDUSTRIAL SOFTWARE MANAGER,
} 1970
}
The output on the screen is: Program 8.2
The circumference of the circle = 12.56
What will be the output of the following programs: Java program to convert the temperature in Celsius to
Fahrenheit
public class HelloWorld {
public static void main (String [] args) { public class HelloWorld{
int l, b, area;
132
public static void main(String [] args){ System.out.print("Enter any two Numbers: ");
float C, F; a = scan.nextInt();
C=38.5; b = scan.nextInt();
F = 9*C/5 +32; sum = a + b;
System.out.println("temperature in Fahrenheit= " +F); System.out.println("the sum of a and b = " + sum);
} }
} }
The output on the screen: The output on the screen:
temperature in Fahrenheit= 101.3 Enter any two Numbers:
Note: If you enter two numbers 2 and 3
the sum of a and b = 5 will be outputted on the screen
Program I:
Program II:
public class HelloWorld
{ public class HelloWorld
public static void main(String [] args) {
{ public static void main(String [] args) {
int a, b, sum; float x;
a=1; x = 233;
b=2; System.out.println(" square root of a number = " +
sum = a + b; Math.sqrt(x));
System.out.println("the sum of a and b = " + sum); }
} }
} The output on the screen:
The output on the screen: square root of a number = 15.264
the sum of a and b = 3
If you want to supply the value for x through the key
If you want to supply the values for a and b through board, then we have to include the statements:
the key board, then we have to include the statements: import java.util.Scanner;
import java.util.Scanner; Scanner scan = new Scanner(System.in);
Scanner scan = new Scanner(System.in); and replace the statement
and replace the statements x = 233;
a=1; by the statements
b=2; System.out.print("Enter any Number: ");
by the statements x = scan.nextFloat();
System.out.print("Enter any two Numbers: "); i.e., the program should be rewritten as:
a = scan.nextInt();
b = scan.nextInt(); import java.util.Scanner;
i.e., the program should be rewritten as: public class HelloWorld {
public static void main(String [] args) {
import java.util.Scanner; int x;
public class HelloWorld Scanner scan = new Scanner(System.in);
{ System.out.print("Enter any Number: ");
public static void main(String [] args) { x = scan.nextFloat();
int a, b, sum; System.out.println(" square root of a number = " +
Scanner scan = new Scanner(System.in); Math.sqrt(x));
133
} If you enter the number 233
} square root of a number = 15.264337522473747 will
The output on the screen: be outputted on the screen.
Enter any Number:
If you enter the number 233 Program IV:
square root of a number = 15.264337522 will be
outputted on the screen. public class HelloWorld{
public static void main(String[] args) {
Program III: char c;
c = 'A';
public class HelloWorld System.out.println("ch= " + c);
{ }
public static void main(String [] args) { }
double x; The output on the screen:
x = 233; ch= A
System.out.println(" square root of a number = " +
Math.sqrt(x)); If you want to supply the value for c through the key
} board, then we have to include the statements:
} import java.util.Scanner;
The output on the screen: Scanner scan = new Scanner(System.in);
square root of a number = 15.264337522473747 and replace the statement
c = 'A';
If you want to supply the value for x through the key by the statements
board, then we have to include the statements: System.out.print("Enter a character:");
import java.util.Scanner; c = (char)System.in.read();
Scanner scan = new Scanner(System.in); i.e., the program should be rewritten as:
and replace the statement
x = 233; public class HelloWorld {
by the statements public static void main(String[] args) throws
System.out.print("Enter any Number: "); Exception {
x = scan.nextDouble(); char c;
i.e., the program should be rewritten as: System.out.print("Enter a character:");
c = (char)System.in.read();
import java.util.Scanner; System.out.println("ch= " + c);
public class HelloWorld { }
public static void main(String [] args) { }
double x; The output on the screen:
Scanner scan = new Scanner(System.in); Enter a character:
System.out.print("Enter any Number: "); If you enter the character K
x = scan.nextDouble(); ch= K will be outputted on the screen.
System.out.println(" square root of a number = " +
Math.sqrt(x)); Note: Exception is a problem that arises during the
} execution of a program. When an exception occurs,
} program abnormally terminates and disrupts—throws
The output on the screen: Exception should be written after the statement public
static void main(String[] args) so that the exceptions
Enter any Number:
are thrown to the operating system to handle and the
134
program will be successfully executed and the output There is no mistake in the above program. The
will be displayed on the screen. statement public static void main(String[] args) can
also be written as
Program V: static public void main(String args [])
The output on the screen is:
import java.util.Scanner; cube root of a number = 6.1534494936636825
public class HelloWorld {
public static void main(String [] args) { Program 8.3
String m;
Scanner in = new Scanner(System.in); Java program to find the product of two numbers.
System.out.print("Enter the word: ");
m = in.nextLine(); public class HelloWorld{
System.out.println(" the word you entered = " + m); public static void main(String [] args) {
} int a, b, product;
} a=1;
The output on the screen: b=2;
Enter the word: product = a * b;
If you enter the word dog System.out.println("the product of a and b = " +
the word you entered = dog will be outputted on the product);
screen. }
}
Note: The output on the screen:
If the statement the sum of a and b = 2
m = scan.nextLine(); is written instead of
m = in.nextLine(); If you want to supply the values for a and b through
Then we have to replace the statement the key board, then we have to include the statements:
Scanner in = new Scanner(System.in); import java.util.Scanner;
by the statement Scanner scan = new Scanner(System.in);
Scanner scan = new Scanner(System.in); and replace the statements
Otherwise compilation error will be displayed on the a=1;
screen. b=2;
by the statements
What is the mistake in the following program: System.out.print("Enter any two Numbers: ");
a = scan.nextInt();
public class HelloWorld b = scan.nextInt();
{ i.e., the program should be rewritten as:
static public void main(String args []) {
float x; import java.util.Scanner;
x = 233; public class HelloWorld{
System.out.println(" cube root of a number = " + public static void main(String [] args) {
Math.cbrt(x)); int a, b, product;
} Scanner scan = new Scanner(System.in);
} System.out.print("Enter any two Numbers: ");
a = scan.nextInt();
Answer: b = scan.nextInt();
product = a * b;
135
System.out.println("the product of a and b = " + If the statement System.out.println("the product of a
product); and b = " + product); is replaced by the statement
} System.out.println(a + "* " + b + " = " + product);
} Then the output on the screen is:
The output on the screen: 2.9 * 3.6 = 10.44
Enter any two Numbers:
If you enter two numbers 6 and 3 Note: The word public in public class HelloWorld
the product of a and b = 18 will be outputted on the implies that the program or the data within the
screen program (such as methods, variables etc.) can be
accessed directly by an external java program.
If you want to assign the floating point values for a & If replace the word public by private i.e., private class
b, then the statement int a, b, sum; should be replaced HelloWorld is written instead of public class
by the statement float a, b, sum; HelloWorld -- then the program or the data within the
program (such as methods, variables etc.) cannot be
and the statements
accessed directly by an external program.
a = scan.nextInt();
b = scan.nextInt();
If you insert a value 2^3 for a and 3^2 for b, then as
should be replaced by the statements said earlier wrong result or compilation error will be
a = scan.nextFloat(); flagged on the screen.
b = scan.nextFloat(); a=2^3
b=3^2; → ERROR
i.e., the above program should be rewritten as: a=2* 2*2
b=3*3; → Result will be outputted on the screen i.e.,
import java.util.Scanner; the product of a and b = 72
public class HelloWorld { If you want to insert a 10 digit number for a and b i.e.,
public static void main(String [] args) { a=1000000000
float a, b, product; b=3000000000, then the statement
Scanner scan = new Scanner(System.in); int a, b, product; should be replaced by the statement
System.out.print("Enter any two Numbers: "); long int a, b, product;
a = scan.nextFloat(); i.e.,
b = scan.nextFloat(); public class HelloWorld{
product = a * b; public static void main(String [] args){
System.out.println("the product of a and b = " + long int a, b, product;
product); a=1000000000;
} b=2000000000;
} product = a * b;
The output on the screen: System.out.println("the product of a and b = " +
Enter any two Numbers: product);
If you enter two floating point values 2.9 and 3.6 }
the product of a and b = 10.44 will be outputted on the }
screen. The output on the screen:
the product of a and b = 3000000000000000000
float is used instead of int because a and b are
assigned fractional values (i.e., 2.9 and 3.6) if int is “Code doesn't exist until it's checked into source
used instead of float then the result will not be clearly control.”
outputted i.e., instead of 10.44 the computer displays
only 10 (as said earlier).
:JEFF ATWOOD
136
Did you know that
import java.util.Scanner;
Harvard MBA candidate Dan Bricklin and public class HelloWorld{
programmer Bob Frankston developed VisiCalc, the public static void main(String [] args) {
program that turned the personal computer into a int a, b;
business machine.
Scanner scan = new Scanner(System.in);
System.out.println("Enter any Number: ");
What will be the output of the following program:
a = scan.nextInt();
b = a * a;
public class HelloWorld{
System.out.println("the square of a = " + b);
static public void main(String args []) {
}
float x;
}
x = 2;
The output on the screen:
System.out.println(" square of a number = " +
Enter any number:
Math.pow((x), 2));
If you enter a number 3
}
the square of a = 9 will be outputted on the screen.
}
Note:
Answer:
square of a number = 4
If scan.nextint() is written instead of scan.nextInt()
public static void main(string [] args); is written
Program 8.4
instead of public static void main(String [] args)
System.out.println(the square of a = + b); is written
Java program to find the square of a number instead of System.out.println("the square of a = " + b);
Then the compilation error will be displayed on the
public class HelloWorld{ screen.
public static void main(String [] args){
int a, b; Program 8.5
a=2;
b = a * a; Java program to find the greatest of two numbers
System.out.println("the square of a = " + b); using
} (a) if - if statement
} (b) if - else statement
The output on the screen:
the square of a = 4 The syntax of if - if statement is:
If you want to supply the value for a through the key if (this condition is true)
board, then we have to include the statements: {
import java.util.Scanner; print this statement using the method
System.out.println( );
Scanner scan = new Scanner(System.in);
}
and replace the statement if (this condition is true)
a=2; {
by the statements print this statement using the method
System.out.print("Enter any Number: "); System.out.println( );
a = scan.nextInt(); }
(a)
i.e., the program should be rewritten as:
137
public class HelloWorld { public class HelloWorld{
public static void main(String [] args){ public static void main(String [] args){
int a, b; int a, b;
a=2; a=2;
b =3; b =3;
if(a>b) if(a>b)
{ {
System.out.println("a is greater than b"); System.out.println("a is greater than b");
} }
if(b>a) else
{ {
System.out.println("b is greater than a"); System.out.println("b is greater than a");
} }
} }
} }
The output on the screen: The output on the screen:
b is greater than a b is greater than a
In the above program:
(a>b) and (b>a) are the conditions and if the condition if the condition (a> b) is true, then the statement
(a> b) is true, then the statement {
{ System.out.println("a is greater than b");
System.out.println("a is greater than b"); }
} make provision to print the output:
make provision to print the output: a is greater than b
a is greater than b else
and if the condition (a> b) is not obeyed and the the statement
condition (b>a) is true, then the statement {
{ System.out.println("b is greater than a");
System.out.println("b is greater than a"); }
} make provision to print the output:
make provision to print the output: b is greater than a
b is greater than a
If you want to supply the values for a and b through
(b) the key board, then the above program should be
The syntax of if – else statement is: rewritten as:
138
{
System.out.println("a is greater than b"); The syntax of if – if- if statement is:
}
if(b>a) if (this condition is true)
{ {
System.out.println("b is greater than a"); print this statement using the method
System.out.println( );
}
}
} if (this condition is true)
} {
The output on the screen: print this statement using the method
Enter any two Numbers: System.out.println( );
If you enter two numbers 2 and 3 }
if (this condition is true)
b is greater than a will be outputted on the screen. {
print this statement using the method
Note: System.out.println( );
Even if the statements }
System.out.println("a is greater than b");
System.out.println ("b is greater than a"); (a)
are not written within the braces {}
i.e., public class HelloWorld{
import java.util.Scanner; public static void main(String [] args){
public class HelloWorld{ int a, b, c;
public static void main(String [] args){ a=2;
int a, b; b =3;
Scanner scan = new Scanner(System.in); c=4;
System.out.println("Enter any two Numbers: "); if(a>b&&a>c)
a = scan.nextInt(); {
b = scan.nextInt(); System.out.println("a is greater than b and c");
if(a>b) }
System.out.println("a is greater than b"); if(b>a&&b>c)
if(b>a) {
System.out.println("b is greater than a"); System.out.println("b is greater than a and c");
} }
} if(c>b&&c>a)
There will no display of compilation error on the {
screen or there will be no change in the output System.out.println("c is greater than b and a");
displayed on the screen (i.e., b is greater than a will be }
outputted on the screen). }
}
Program 8.6 The output on the screen:
c is greater than b and a
Java program to find the greatest of three numbers symbol && imply and i.e., the condition
using
(a>b&&a>c) imply
(a) if - if - if statement
a is greater than b and a is greater than c
(b) if – else if – else statement
(b) if – else if – else if statement
139
(a>b&&a>c), (b>a&&b>c) and (c>b&&c>a) are the System.out.println("c is greater than b and a");
conditions and if the condition (a>b&&a>c) is true, }
then the statement }
{ }
System.out.println("a is greater than b and c"); The output on the screen:
} Enter any three Numbers:
make provision to print the output: If you enter three numbers 2, 3 and 4
a is greater than b and c c is greater than b and a will be outputted on the
and if the condition(a>b&&a>c) is not true and the screen.
condition (b>a&&b>c) is true, then the statement
{ The syntax of if – else if – else statement is:
System.out.println("b is greater than a and c");
} if (this condition is true)
make provision to print the output: {
b is greater than a and c print this statement using the method
System.out.println( );
and if the condition (b>a&&b>c) is not true and the }
condition (c>b&&c>a) is true, then the statement else if (this condition is true)
{
{
print this statement using the method
System.out.println("c is greater than b and a"); System.out.println( );
} }
make provision to print the output: else
c is greater than b and a {
print this statement using the method
System.out.println( );
If you want to supply the values for a, b and c through
}
the key board, then the above program should be
rewritten as:
(b)
import java.util.Scanner;
public class HelloWorld{
public class HelloWorld{
public static void main(String [] args){
public static void main(String [] args) {
int a, b, c;
int a, b, c;
a=2;
Scanner scan = new Scanner(System.in);
b =3;
System.out.println("Enter any three Numbers: ");
c=4;
a = scan.nextInt();
if(a>b&&a>c)
b = scan.nextInt();
{
c = scan.nextInt();
System.out.println("a is greater than b and c");
if(a>b&&a>c)
}
{
else if(b>a&&b>c)
System.out.println("a is greater than b and c");
{
}
System.out.println("b is greater than a and c");
if(b>a&&b>c)
}
{
else
System.out.println("b is greater than a and c");
{
}
System.out.println("c is greater than b and a");
if(c>b&&c>a)
}
{
140
}
} If the statements
The output on the screen: if(a>b&&a>c)
c is greater than b and a {
System.out.println("a is greater than b and c");
The syntax of if – else if – else if statement is: }
else if(b>a&&b>c)
if (this condition is true) {
{ System.out.println("b is greater than a and c");
print this statement using the method }
System.out.println( );
else if(c>b&&c>a)
}
else if (this condition is true) {
{ System.out.println("c is greater than b and a");
print this statement using the method }
System.out.println( );
} are replaced by the statements
else if (this condition is true)
{
print this statement using the method if(a>b&&a>c)
System.out.println( ); {
} System.out.println(a + "is greater than" + b + "and" +
c);
(c) }
else if(b>a&&b>c)
public class HelloWorld { {
public static void main(String [] args){ System.out.println(b + "is greater than" + a + "and" +
int a, b, c; c);
a=2; }
b =3; else if(c>b&&c>a)
c=4; {
if(a>b&&a>c) System.out.println(c + "is greater than" + b + "and" +
{ a);
System.out.println("a is greater than b and c"); }
} Then the output on the screen is:
else if(b>a&&b>c) 4 is greater than 3 and 2
{
System.out.println("b is greater than a and c"); Program 8.7
}
else if(c>b&&c>a) Java program to find the average of 10 numbers
{
System.out.println("c is greater than b and a"); import java.util.Scanner;
} public class HelloWorld{
} public static void main(String [] args) {
} int N1, N2, N3, N4, N5, N6, N7, N8, N9, N10, X;
The output on the screen: Scanner scan = new Scanner(System.in);
c is greater than b and a System.out.println("Enter any ten Numbers: ");
Note: N1 = scan.nextInt();
141
N2 = scan.nextInt(); If you want to supply the values for P, T and R
N3 = scan.nextInt(); through the key board, then the above program should
N4 = scan.nextInt(); take the form:
N5 = scan.nextInt();
N6 = scan.nextInt(); import java.util.Scanner;
N7 = scan.nextInt(); public class HelloWorld {
N8 = scan.nextInt(); public static void main(String [] args) {
N9 = scan.nextInt(); int P,T, R, SI;
N10 = scan.nextInt(); Scanner scan = new Scanner(System.in);
X = (N1 + N2 + N3 + N4 + N5 + N6 + N7 + N8 + N9 + System.out.println("Enter principal amount:");
N10) /10; P = scan.nextInt();
System.out.println("the average of 10 numbers = " + System.out.println("Enter time:");
X); T = scan.nextInt();
} System.out.println("Enter rate of interest:");
} R = scan.nextInt();
The output on the screen: SI = P*T*R/100;
Enter any ten Numbers: System.out.println("the simple interest = " + SI);
If you enter ten numbers 1, 2, 3, 4, 5, 6, 7, 8, 9 and 10 }
the average of 10 numbers = 5 will be outputted on the }
screen. The output on the screen:
Enter principal amount:
Note: The average of 10 numbers is 5.5, the output on If you enter the principal amount 1000
the screen is 5 because int is used instead of float. Enter time:
If you enter the time 2
“Time is so short, you can't make a debug...” Enter rate of interest:
If you enter the rate of interest 3
: SCOTT ADAMS the simple interest = 60 will be outputted on the
screen.
Program 8.8
Program 8.9
Java program to find the simple interest
Java program to find the senior citizen
public class HelloWorld{
public static void main(String [] args) { public class HelloWorld{
int P,T, R, SI; public static void main(String [] args){
P = 1000; int age;
T = 2; age=20;
R = 3; if(age> = 60)
SI = P*T*R/100; {
System.out.println("the simple interest = " + SI); System.out.println("senior citizen");
} }
} if(age<60)
The output on the screen: {
the simple interest = 60 System.out.println("not a senior citizen");
}
}
142
} public static void main(String [] args){
The output on the screen: int M1, M2,M3;
not a senior citizen M1 = 38;
(age> = 60) implies age greater than or equal to 60 M2= 45;
M3 = 67;
If you want to supply the value for age through the if(M1>= 35 && M2>= 35 && M3>= 35)
key board, then the above program should be rewritten {
as: System.out.println("candidate is passed");
}
import java.util.Scanner; else
public class HelloWorld{ {
public static void main(String [] args){ System.out.println("candidate is failed");
int age; }
Scanner scan = new Scanner(System.in); }
System.out.println("Enter the age: "); }
age = scan.nextInt(); The output on the screen:
if(age> = 60) candidate is passed
{ (M1>= 35 && M2>= 35 && M3>= 35) imply M1 is
System.out.println("senior citizen"); greater than or equal to 35 and M2 is greater than or
} equal to 35 and M3 is greater than or equal to 35.
if(age<60) >= imply greater than or equal to.
{ && imply and whereas & imply address.
System.out.println("not a senior citizen"); (M1>= 35 && M2>= 35 && M3>= 35) is the
} condition and if the condition (M1>= 35 && M2>= 35
} && M3>= 35) is true, then the statement
} {
The output on the screen: System.out.println("candidate is passed");
Enter the age: }
If you enter the age 60
senior citizen will be outputted on the screen. make provision to print the output:
Suppose if you enter the age 28 candidate is passed
not a senior citizen will be outputted on the screen. else the statement
{
Note: System.out.println("candidate is failed");
If the symbol >> is used instead of > and << is used }
instead of < make provision to print the output:
Then the compilation error will be displayed on the candidate is failed
screen.
If you want to supply the values for marks M1, M2 and
Program 9.0 M3 through the key board, then the above program
should be rewritten as:
Java program to get marks for 3 subjects and declare
the result import java.util.Scanner;
If the marks >= 35 in all the subjects the student public class HelloWorld{
passes else fails. public static void main(String [] args) {
int age;
public class HelloWorld{ Scanner scan = new Scanner(System.in);
143
System.out.println("Enter any three Numbers: "); if(SP>CP)
M1= scan.nextInt(); {
M2 = scan.nextInt(); System.out.println("profit= " + (SP-CP));
M3 = scan.nextInt(); }
if(M1>= 35 && M2>= 35 && M3>= 35) if(CP>SP)
{ {
System.out.println("candidate is passed"); System.out.println("loss =" +(CP-SP));
} }
else }
{ }
System.out.println("candidate is failed"); The output on the screen:
} Enter cost price:
} If you enter the cost price 25
} Enter selling price:
The output on the screen: If you enter the selling price 26
Enter any three Numbers: profit = 1 will be outputted on the screen.
If you enter three numbers 26, 28, 39
candidate is failed will be outputted on the screen. If the condition (SP>CP) is true, then the statement
{
“One of my most productive days was throwing away System.out.println("profit= " + (SP-CP));
1000 lines of code.” }
make provision to print the output:
: KEN THOMPSON profit = (SP-CP) (in this case profit = 26-25 =1)
Did you know that If the condition (CP>SP) is true, then the statement
{
In 1833, Charles Babbage developed the analytical System.out.println("loss =" + (CP-SP));
engine. This machine consisted of five functional units }
such as input unit, memory unit, arithmetic unit,
make provision to print the output:
control unit and output unit. The architecture of the
modern digital computer resembles the analytical loss = (CP-SP)
engine and hence Charles Babbage is called the father
of computers. Note: if the minus sign (‒) is used instead of (-) i.e.,
(CP‒ SP) is written instead of (CP- SP), the error will
Program 9.1 be displayed on the screen (because like C & C ++,
java is also a case sensitive language).
Java program to find profit or loss
If the statement
System.out.println("profit= " + SP-CP);
import java.util.Scanner;
is written instead of the statement
public class HelloWorld{
System.out.println("profit= " + (SP-CP));
public static void main(String [] args) {
i.e., SP-CP is written instead of (SP-CP)
int CP, SP, loss, profit;
Then the Compilation Error will be displayed on the
Scanner scan = new Scanner(System.in);
screen.
System.out.println("Enter cost price: ");
CP = scan.nextInt();
What is the mistake in the following program:
System.out.println("Enter selling price: ");
SP = scan.nextInt();
144
import java.util.Scanner; System.out.print("\n the decremented value of a = " +
public class HelloWorld{ e);
public static void main(String [] args){ System.out.print("\n the decremented value of b = " +
float I, C; f);
Scanner scan = new Scanner(System.in); i.e., if the above program is rewritten as:
System.out.println("Enter the length in inches: ");
I = scan.nextInt(); public class HelloWorld{
C = 2.54*I; public static void main(String [] args) {
System.out.print("length in centimeters = " + C); int a, b, c, d, e, f;
} a = 10;
} b=12;
c=a+1;
Program 9.2 d=b+1;
e=a-1;
Java program to find the incremented and f=b-1;
decremented values of two numbers System.out.print("\n the incremented value of a = " +
c);
public class HelloWorld{ System.out.print("\n the incremented value of b = " +
public static void main(String [] args){ d);
int a, b, c, d, e, f; System.out.print("\n the decremented value of a = " +
e);
a = 10;
System.out.print("\n the decremented value of b = " +
b=12;
f);
c=a+1;
}
d=b+1;
}
e=a-1;
Then the output on the screen is:
f=b-1;
the incremented value of a = 11
System.out.print("the incremented value of a = "+ c);
the incremented value of b = 13
System.out.print("the incremented value of b = "+ d);
the decremented value of a = 9
System.out.print("the decremented value of a = "+ e);
the decremented value of b = 11
System.out.print("the decremented value of b = "+ f);
}
i.e., \n make provision for the another result to print in
} the new line. If you want to supply the values for a
The output on the screen: and b through the key board, then the above program
the incremented value of a = 11 the incremented value should take the form:
of b = 13 the decremented value of a = 9 the
decremented value of b = 11 import java.util.Scanner;
public class HelloWorld{
If the statements public static void main(String [] args){
System.out.print("the incremented value of a = "+ c); int a, b, c, d, e, f;
System.out.print("the incremented value of b = " + d); Scanner scan = new Scanner(System.in);
System.out.print("the decremented value of a = " + e); System.out.println("Enter any Number: ");
System.out.print("the decremented value of b = " + f); a = scan.nextInt();
are replaced by the statements System.out.println("Enter any Number: ");
System.out.print("\n the incremented value of a = " + b = scan.nextInt();
c);
c=a+1;
System.out.print("\n the incremented value of b = " +
d=b+1;
d);
145
e=a-1; import java.util.Scanner;
f=b-1; public class HelloWorld{
System.out.print("\n the incremented value of a = " + public static void main(String [] args) {
c); int P;
System.out.print("\n the incremented value of b = " + Scanner scan = new Scanner(System.in);
d); System.out.println("Enter the percentage: ");
System.out.print("\n the decremented value of a = " + P = scan.nextInt();
e);
if(P >= 60)
System.out.print("\n the decremented value of b = " +
{
f);
System.out.println("first class");
}
}
}
if(P>=50&&P <60)
The output on the screen:
{
Enter any Number:
System.out.println("second class");
If you enter the value 2
}
Enter any Number:
if(P>=40&&P<=50 )
If you enter the value 3
{
the incremented value of a = 3
System.out.println("pass class");
the incremented value of b = 4
}
the decremented value of a = 1
if(P<40)
the decremented value of b = 2
{
will be outputted on the screen.
System.out.println("fail");
}
Note: b++ is same as b + 1 and b-- is same as b - 1 but
b++ or b-- should be used only in case of for loop or }
loop statements. Usage of b++ or b-- instead of b +1 }
or b-1 in the certain online compilers like coding Program 9.3
ground (tutorials point) yields error or displays the
wrong result. Java program to calculate the discounted price and the
total price after discount
What will be the output of the following programs: Given:
If purchase value is greater than 1000, 10% discount
import java.util.Scanner; If purchase value is greater than 5000, 20% discount
public class temperature{ If purchase value is greater than 10000, 30% discount
public static void main(String [] args) {
float T1, T2, A; (a) discounted price
Scanner scan = new Scanner(System.in);
System.out.println("Enter any Number: "); import java.util.Scanner;
T1 = scan.nextFloat(); public class HelloWorld{
System.out.println("Enter any Number: "); public static void main(String [] args) {
T2 = scan.nextFloat(); int PV, dis;
A = (T1 + T2) / 2; Scanner scan = new Scanner(System.in);
System.out.println("the average temperature of the System.out.println("Enter purchased value: ");
day = " + A); PV = scan.nextInt();
} if(PV<1000)
} {
System.out.println("dis = " + PV* 0.1);
146
} PV = scan.nextInt();
if(PV>5000) if(PV<1000)
{ {
System.out.println("dis = " + PV* 0.2); System.out.println("total= " + PV - PV* 0.1);
} }
if(PV<10000) if(PV>5000)
{ {
System.out.println("dis= " + PV* 0.3); System.out.println("total = " + PV- PV* 0.2);
} }
} if(PV<10000)
} {
The output on the screen: System.out.println("total= " + PV- PV* 0.3);
Enter purchased value: }
If you enter the purchased value 6500 }
dis = 1300 will be outputted on the screen. }
The output on the screen:
If the condition (PV<1000) is true i.e., purchased Enter purchased value:
value is less than 1000, then the statement If you enter the purchased value 650
{ total = 585 will be outputted on the screen.
System.out.println("dis = " + PV* 0.1);
} If the condition (PV<1000) is true i.e., purchased
make provision to print the output: value is less than 1000, then the statement
dis= PV* 10% = PV* 10 /100 = PV* 0.1 {
If the condition (PV< 5000) is true i.e., purchased System.out.println("total = " + PV - PV* 0.1);
value is less than 5000, then the statement }
{ make provision to print the output:
System.out.println("dis = " + PV* 0.2); total =PV- dis = PV- PV*10% = PV- PV* 10 /100 =
} PV - PV * 0.1
make provision to print the output:
dis= PV* 20% = PV* 20 /100 = PV* 0.2 If the condition (PV< 5000) is true i.e., purchased
If the condition (PV< 10000) is true i.e., purchased value is less than 5000, then the statement
value is less than 10000, then the statement {
{ System.out.println("total = " + PV - PV* 0.2);
System.out.println("dis = " + PV* 0.3); }
} make provision to print the output:
make provision to print the output: total =PV- dis = PV- PV*20% = PV- PV* 20 /100 =
dis= PV* 30% = PV* 30 /100 = PV* 0.3 PV - PV * 0.2
(b) total price If the condition (PV< 10000) is true i.e., purchased
value is less than 10000, then the statement
import java.util.Scanner; {
public class HelloWorld{ System.out.println("total = " + PV - PV* 0.3);
public static void main(String [] args) { }
int PV, total; make provision to print the output:
Scanner scan = new Scanner(System.in); total =PV- dis = PV- PV*30% = PV- PV* 30 /100 =
System.out.println("Enter purchased value: "); PV - PV * 0.3
147
Note: Combing both the programs (above), we can The output on the screen is:
write: value of i = 1 value of i = 2 value of i= 3 value of i=
4 value of i= 5 value of i= 6 value of i = 7 value of i=
import java.util.Scanner; 8 value of i = 9 value of i = 10
public class HelloWorld{
public static void main(String [] args){ for (i=1; i<=10; i++) denote the for loop statement and
int PV, dis, total; the syntax of the for loop statement is:
Scanner scan = new Scanner(System.in); for (initialization; condition; increment)
System.out.println("Enter purchased value: "); Here:
PV = scan.nextInt(); i=1 denote initialization (i.e., from where to start)
if(PV<1000) i<=10 denote the condition (i.e., stop when 10 is
reached)
{
i++ imply increment (which tells the value of i to
System.out.println("dis = " + PV* 0.1);
increase by 1 each time the loop is executed) and i++
System.out.println("total= " + total - dis); is the same as i+1.
} Since the initialization i.e., i=1
if(PV>5000) The statement System.out.println("value of i = " + i);
{ make provision to print the output:
System.out.println("dis = " + PV* 0.2); value of i = 1
System.out.println("total= " + total - dis); on the screen.
} After this, the following execution takes place:
if(PV<10000) value of i
{ i= 1
System.out.println("dis = " + PV* 0.3); Is the condition (i<=10) is true?
System.out.println("total= " + total - dis); Yes because i=1
} Do this
} i= 1+1 = 2
} The statement System.out.println("value of i = " + i);
The output on the screen: make provision to print the output:
Enter purchased value: value of i = 2
If you enter the purchased value 850 Now, the value of i is:
dis = 85 i= 2
total = 765 Is the condition (i<=10) is true?
will be outputted on the screen. Yes because i=2
Do this
Program 9.4 i= 2+1 = 3
The statement System.out.println("value of i = " + i);
Java program to print the first ten natural numbers make provision to print the output:
using for loop statement value of i = 3
Now, the value of i is:
public class HelloWorld{ i= 3
public static void main(String [] args){ Is the condition (i<=10) is true?
int i; Yes because i=3
for (i=1; i<=10; i++) Do this
System.out.println("value of i = " + i); i= 3+1 = 4
} The statement System.out.println("value of i = " + i);
} make provision to print the output:
148
value of i = 4 Now, the value of i is:
Now, the value of i is: i= 9
i= 4 Is the condition (i<=10) is true?
Is the condition (i<=10) is true? Yes because i=9
Yes because i=4 Do this
Do this i= 9+1 = 10
i= 4+1 = 5 The statement System.out.println("value of i = " + i);
The statement System.out.println("value of i = " + i); make provision to print the output:
make provision to print the output: value of i = 10
value of i = 5 stop because the condition i<=10 is achieved.
Now, the value of i is:
i= 5 If new line \n is introduced i.e., the statement
Is the condition (i<=10) is true? System.out.println("value of i = " + i); is replaced by
Yes because i=5 the statement System.out.println("\n value of i = " + i);
i.e.,
Do this
i= 5+1 = 6
public class HelloWorld{
The statement System.out.println("value of i = " + i);
make provision to print the output: public static void main(String [] args){
value of i = 6 int i;
Now, the value of i is: for (i=1; i<=10; i++)
i= 6 System.out.println("\n value of i = " + i);
Is the condition (i<=10) is true? }
Yes because i=6 }
Do this Then the output on the screen is:
i= 6+1 = 7 value of i = 1
The statement System.out.println("value of i = " + i); value of i = 2
make provision to print the output: value of i = 3
value of i = 7 value of i = 4
Now, the value of i is: value of i = 5
i= 7 value of i = 6
Is the condition (i<=10) is true? value of i = 7
Yes because i=7 value of i = 8
Do this value of i = 9
i= 7+1 = 8 value of i = 10
The statement System.out.println("value of i = " + i); If the for loop statement for (i=2; i<=10; i++) is
make provision to print the output: written instead of the statement for(i=1; i<=10; i++),
value of i = 8 then the output on the screen is:
Now, the value of i is: value of i = 2 value of i = 3 value of i= 4 value of i=
5 value of i= 6 value of i = 7 value of i= 8 value of i
i= 8
= 9 value of i= 10
Is the condition (i<=10) is true?
(because i=2 is initialized in the for loop statement the
Yes because i=8 printing started from value of i = 2 and ended at value
Do this of i= 10 because of the condition i<=10)
i= 8+1 = 9 If the for loop statement for(i=1; i<10; i++) is written
The statement System.out.println("value of i = " + i); instead of the statement for (i=1; i<=10; i++), then the
make provision to print the output: output on the screen is:
value of i = 9
149
value of i = 1 value of i = 2 value of i= 3 value of i= Answer:
4 value of i= 5 value of i= 6 value of i = 7 value of i= There is no mistake in the above program. Addition of
8 value of i = 9 the statement throws Exception does not make any
(Note: the condition i<=10 tells to print till value of i change in the output displayed on the screen or give
=10 but the condition i<10 tells to print till value of i rise to any compilation error on the screen.
=9)
If the statement for(i=1; i=10; i++) is written instead Program 9.5
of the statement for (i=1; i<=10; i++), then the output
on the screen is:
Java program to print the first ten natural numbers
value of i = 10 value of i = 10 value of i = 10 value using for while loop statement
of i = 10 value of i= 10 value of i= 10 value of i = 10
value of i= 10 value of i = 10 value of i = 10 value
of i = 10 value of i = 10 value of i = 10 value of i = The syntax of while loop statement is:
10 value of i = 10 ………. (continues).
while (this is the condition)
Note: {
If the statement System.out.println("value of i = " + i); execute this statement;
is replaced by the statement }
System.out.println(" \n " + i);
i.e., public class HelloWorld{
public class HelloWorld{ public static void main(String [] args) {
public static void main(String [] args){ int i = 1;
int i; while (i<=10)
for (i=1; i<=10; i++) {
System.out.println("\n " + i); System.out.println("\n " + i++);
} }
} }
The output on the screen is: }
1 The output on the screen is:
2 1
3 2
4 3
5 4
6 5
7 6
8 7
9 8
10 9
What is the mistake in the following program: 10
150
{ }
System.out.println("\n"+ a++);
} Then the output on the screen is:
i.e., 0
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
10 10
Similarly if the statement int i = 0; is replaced by the
Note: The statement int i = 1; imply that we are int i = 7;
creating an integer variable i and we are initializing i Then the output on the screen is:
=1. 7
8
If the statement int i=1; is replaced by the statement 9
int i; 10
i.e.,
public class HelloWorld{ Program 9.6
public static void main(String [] args) {
int i; Java program to print first 10 numbers using do while
while (i<=10) loop statement
{ The syntax of do while loop statement is:
System.out.println("\n " + i++);
} do
} {
} execute this statement;
}
Then the compilation error will be displayed on the while(this is the condition);
screen because initialization is not defined i.e., from
where to start is not declared.
public class HelloWorld{
public static void main(String [] args){
If the statement int i = 1; is replaced by the int i = 0;
int i = 1;
i.e.,
do
public class HelloWorld{
{
public static void main(String [] args) {
System.out.println(" \n i = " + i++);
int i = 0;
} while (i<=10);
while (i<=10)
}
{
}
System.out.println("\n " + i++);
The output on the screen is:
}
i= 1
}
i=2
151
i= 3 char a;
i= 4 for( a='A'; a<='Z'; a++)
i= 5 System.out.println("\n " + a);
i= 6 }
i=7 }
i= 8 The output on the screen:
i= 9 A
i= 10 B
C
The statements D
do E
{ F
System.out.println(" \n i = " + i++); G
}while (i<=10); H
imply print till i=10 using the statement I
do J
{ K
System.out.println(" \n i= " + i++); L
} M
while the condition (i<=10) is to print till i = 10 ( N
starting from i = 1 because of the statement int i=1;) O
P
Write a program to print Q
The Internet is not for sissies R
10 times using for loop statement. S
T
Answer: W
X
public class HelloWorld{ Y
public static void main(String [] args){ Z
int i;
for (i=1; i<=10; i++) char means the data type is character.
System.out.println("\n The Internet is not for sissies"); The statement
} char a; imply that we are creating the character a.
} If the statement for( a=A; a<=Z; a++) is written
instead of the statement for( a='A'; a<='Z'; a++)
Program 9.7 i.e., A is used instead of 'A' and Z is used instead of
'Z', then the compilation error will be displayed on the
Java program to print the characters from A to Z using console screen.
for loop, do while loop and while loop statement.
(b) Java program to print the characters from A to Z
(a) Java program to print the characters from A to Z using while loop statement:
using for loop statement:
public class HelloWorld{
public class HelloWorld{ public static void main(String [] args) {
public static void main(String [] args) { char a = 'A';
152
while (a<='Z') a = scan.nextInt();
{ if(a%2 = = 0)
System.out.println("\n " + a++); {
} System.out.println("the number is even");
} }
} else
{
Note: If the statement char a; is written instead of System.out.println("the number is odd");
char a = 'A'; }
i.e., }
public class alphabets{ }
public static void main(String [] args) { The output on the screen:
char a; Enter a number:
while (a<='Z') If you enter the number 4
{ the number is even will be outputted on the screen.
System.out.println("\n " + a++);
} (a%2 = = 0) is the condition and this condition imply:
} a divided by 2 yields reminder = 0.
} For example: if you enter the number 4
Then the compilation error will be displayed on the Then a = 4
screen. Then 4 divided by 2 yields the remainder = 0
Then the statement
(c) Java program to print the characters from A to Z {
using do while loop statement: System.out.println("the number is even");
}
public class HelloWorld{
make provision to print the output:
public static void main(String [] args) {
the number is even
char a = 'A';
(Note: in Java language also = = implies equal to)
do
if you enter the number 3
{
Then a = 3
System.out.println("\n " + a++);
Then 3 divided by 2 yields the remainder = 1
} while (a<='Z');
Then the statement
}
{
}
System.out.println("the number is odd");
}
Program 9.8
make provision to print the output:
the number is odd
Java program to print the given number is even or
odd.
Program 9.9
import java.util.Scanner;
Java program to print the remainder of two numbers
public class HelloWorld{
import java.util.Scanner;
public static void main(String [] args) {
public class HelloWorld{
int a;
public static void main(String [] args) {
Scanner scan = new Scanner(System.in);
int a, b, c;
System.out.println("Enter a number: ");
Scanner scan = new Scanner(System.in);
153
System.out.println("Enter a number: "); If you enter the number 2
a = scan.nextInt(); Enter a number:
System.out.println("Enter a number: "); If you enter the number 2
b = scan.nextInt(); the two numbers are equivalent will be outputted on
c = a%b; the screen.
System.out.println("the remainder of a and b = " + c);
} Since 2-2 is equal to 0 (i.e., x-y = = 0). Therefore: the
} statement
The output on the screen: {
Enter a number: System.out.println("the two numbers are equivalent");
If you enter the number 3 }
Enter a number: makes provision to print the output:
If you enter the number 2 two numbers are equivalent
the remainder of a and b = 1 will be outputted on the
screen. If you enter the integers 3 and 2
Since (a =3 and b =2). Therefore: The output on the screen is:
3 divided by 2 (i.e., a divided by b) yields the the two numbers are not equivalent
remainder equal to 1. Since 3-2 is not equal to 0 (i.e., x-y != 0). Therefore:
the statement
“There are two ways to write error-free programs; only {
the third one works. (Alan J. Perlis)” System.out.println("the two numbers are not
equivalent");
}
Program 10.0 makes provision to print the output:
two numbers are not equivalent
Java program to check equivalence of two numbers. (Note: Like in C & C++, in Java language also !=
implies not equal to)
import java.util.Scanner;
public class HelloWorld{ Program 10.1
public static void main(String [] args) {
int x, y; Java program to print the leap year or not
Scanner scan = new Scanner(System.in);
System.out.println("Enter a number: "); public class HelloWorld{
x = scan.nextInt(); public static void main(String [] args) {
System.out.println("Enter a number: "); int year;
y = scan.nextInt(); year =1996;
if(x-y==0) if(year%4==0)
{ {
System.out.println("the two numbers are equivalent"); System.out.println("leap year");
} }
else else
{ {
System.out.println("the number are not equivalent"); System.out.println("not a leap year");
} }
} }
The output on the screen: }
Enter a number:
154
int a =5;
The output on the screen: public static void main(String[] args){
leap year int a =2 ;
Since year =1996. Therefore: System.out.println(" value of a = " + ::a);
1996 divided by 4 (i.e., year divided by 4) yields the }
remainder equal to 0. }
The statement Then the compilation error will be displayed on the
{ screen because like C++ -- java does not hold /
System.out.println("leap year"); support the resolution operator.
}
makes provision to print the output: Program 10.1
leap year
If the year is = 1995. Then Java program to print whether the given number is
1995 divided by 4 (i.e., year divided by 4) yields the positive or negative
remainder not equal to 0.
The statement public class HelloWorld{
{ public static void main(String [] args){
System.out.println("not a leap year"); int a;
} a = -35;
makes provision to print the output: if(a>0)
not a leap year {
System.out.println("number is positive");
“Writing code has a place in the human hierarchy }
worth somewhere above grave robbing and beneath else
managing.” {
System.out.println(" number entered is negative");
: GERALD WEINBERG }
}
What will be the output on the screen: }
The output on the screen:
public class HelloWorld{ number entered is negative
int a =5; Since a = -35. Therefore:
public static void main(String[] args){ a is less than 0 i.e., a<0
int a =2 ; The statement
System.out.println(" value of a = " + a); {
} System.out.println("number is negative");
} }
makes provision to print the output:
Answer: number entered is negative
value of a = 2
Program 10.2
If the statement System.out.println(" value of a = " +
a); is replaced by the statement Java program to print the sum of the first 10 digits
System.out.println(" value of a = " + ::a); (where :: using for loop statement:
denote scope resolution operator)
i.e., public class HelloWorld{
public class HelloWorld{
155
public static void main(String [] args){ value of i
int i, sum = 0; i=7 (now the sum = 21)
for( i=1; i<=10; i++) Is i<=10 true?
sum = sum + i; Yes, do this
System.out.println("sum of the first 10 digits = " + sum = sum + i = 21 + 7 = 28
sum); value of i
} i=8 (now the sum = 28)
} Is i<=10 true?
The output on the screen: Yes, do this
sum of the first 10 digits = 55 sum = sum + i = 28 + 8 = 36
i.e., 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 = 55 value of i
i=9 (now the sum = 36)
How the sum of the first 10 digits = 55 is outputted Is i<=10 true?
on the screen through the for Loop statement Yes, do this
value of i sum = sum + i = 36 + 9 = 45
i=1 (sum = 0 because the sum is initialized to 0 in the value of i
statement int i, sum = 0;)
i=10 (now the sum = 45)
Is i<=10 true?
Is i<=10 true?
Yes, do this
Yes, do this
sum = sum + i = 0 +1 =1
sum = sum + i = 45 + 10 = 55
value of i
stops because the condition is i<=10
i=2 (now the sum = 1)
Is i<=10 true?
The statement System.out.println("sum of the first 10
Yes, do this digits = " + sum); make provision to display the
sum = sum + i = 1 +2 =3 output:
value of i sum of the first10 digits = 55
i=3 (now the sum = 3) on the screen.
Is i<=10 true?
Yes, do this If the statement int i, sum = 0; is replaced by int i, sum
sum = sum + i = 3 +3 = 6 = 1;
value of i Then
i=4 (now the sum = 6) value of i
Is i<=10 true? i=1 (sum = 1 because the sum is initialized to 1 in the
Yes, do this statement int i, sum = 1;)
sum = sum + i = 6 + 4= 10 Is i<=10 true?
value of i Yes, do this
i=5 (now the sum = 10) sum = sum + i = 1 +1 = 2
Is i<=10 true? value of i
Yes, do this i=2 (now the sum = 2)
sum = sum + i = 10 + 5= 15 Is i<=10 true?
value of i Yes, do this
i=6 (now the sum = 15) sum = sum + i = 2 + 2 = 4
Is i<=10 true? value of i
Yes, do this i=3 (now the sum = 4)
sum = sum + i = 15 + 6 = 21 Is i<=10 true?
Yes, do this
156
sum = sum + i = 4 +3 = 7 What will be the output if the for loop statement for(i
value of i =1; i<=10; i++) is replaced by the statement for(i =2;
i=4 (now the sum = 7) i<10; i++)?
Is i<=10 true?
Yes, do this Answer: sum of 10 digits = 44
sum = sum + i = 7 + 4= 11
value of i If the statement int i, sum, sum = 0; is written instead
of int i, sum = 0;
i=5 (now the sum = 11)
Then the compilation error message will be displayed
Is i<=10 true?
on the screen (stating that sum is twice declared).
Yes, do this
sum = sum + i = 11 + 5= 16
If the for loop is ended with a semicolon i.e.,
value of i
for( i=1; i<=10; i++);
i=6 (now the sum = 16)
then the compilation error will be displayed on the
Is i<=10 true? screen
Yes, do this
sum = sum + i = 16 + 6 = 22
Even though if i ++ is replaced by ++ i in the for loop
value of i statement i.e., if the for loop statement
i=7 (now the sum = 22) for (i=1; i<=10; i++)
Is i<=10 true? is replaced by the statement
Yes, do this for (i=1; i<=10; ++ i)
sum = sum + i = 22 + 7 = 29 There will be no change in the output on the screen (as
value of i observed while compiling in online compilers like
i=8 (now the sum = 29) Coding ground (Tutorials point)) and if the statement
Is i<=10 true? for( i=1; i<=10; i++); is written instead of the
statement
Yes, do this
for (i=1; i<=10; i++)
sum = sum + i = 29 + 8 = 37
Then the Error will be flagged on the screen because
value of i
for loop statement is ended by a semicolon (;).
i=9 (now the sum = 37)
Is i<=10 true?
Program 10.3
Yes, do this
sum = sum + i = 37 + 9 = 46
Java program to print the average of the first10
value of i numbers using for loop statement
i=10 (now the sum = 46)
Is i<=10 true? public class HelloWorld{
Yes, do this public static void main(String [] args){
sum = sum + i = 46 + 10 = 56 int i, avg, sum = 0;
stops because the condition is i<=10 for( i=1; i<=10; i++)
sum = sum + i;
The statement System.out.println("sum of the first 10 avg = sum/10;
digits = " + sum); make provision to display the
System.out.println("sum of the first 10 numbers = " +
output: sum);
sum of the first10 digits = 56 on the screen.
System.out.println("average of the first 10 numbers =
(wrong result because the sum of the first 10 digits is " + avg);
55) }
}
157
The output on the screen:
sum of the first 10 numbers = 55 value of i
average of the first 10 numbers = 5 i=1 (product = 1 because the product is initialized to 1
The average of the first 10 numbers = 55/10 = 5.5 not in the statement int i, product = 1;)
5. But the output on the screen is: Is i<=10 true?
average of the first 10 numbers = 5 Yes, do this
because int is used instead of float. product = product * i = 1 * 1 =1
value of i
If the data type float is used i.e., i=2 (now the product = 1)
Is i<=10 true?
public class HelloWorld{ Yes, do this
public static void main(String [] args) { product = product * i = 1 * 2 = 2
float i, avg, sum = 0; value of i
for( i=1; i<=10; i++) i=3 (now the product = 2)
sum = sum + i; Is i<=10 true?
avg = sum/10; Yes, do this
System.out.println("sum of the first 10 numbers = " + product = product * i = 2 * 3 = 6
sum); value of i
System.out.println("average of the first 10 numbers = i=4 (now the product = 6)
" + avg); Is i<=10 true?
} Yes, do this
} product = product * i = 6 * 4 = 24
The output on the screen: value of i
sum of the first 10 numbers = 55 i=5 (now the product =24)
average of the first 10 numbers = 5.5 Is i<=10 true?
Yes, do this
Program 10.4 product = product * i = 24 * 5 =120
value of i
Java program to print the product of the first10 digits i=6 (now the product =120)
using for loop statement
Is i<=10 true?
Yes, do this
public class HelloWorld{
product = product * i = 120 * 6 = 720
public static void main(String [] args) {
value of i
int i, product = 1;
i=7 (now the product =720)
for( i=1; i<=10; i++)
Is i<=10 true?
product = product * i;
Yes, do this
System.out.println("the product of the first10 digits =
product = product * i = 720 * 7 = 5040
" + product);
value of i
}
i=8 (now the product =5040)
}
Is i<=10 true?
The output on the screen:
Yes, do this
the product of the first 10 digits = 3628800
product = product * i = 5040 * 8 = 40320
i.e., 1 * 2 * 3 * 4 * 5 * 6 * 7 * 8 * 9 * 10 = 3628800
value of i
i=9 (now the product = 40320)
How the product of the first 10 digits = 3628800 is
outputted on the screen through the for Loop Is i<=10 true?
statement Yes, do this
158
product = product * i = 40320 * 9 = 362880 Yes, do this
value of i product = product * i = 0 * 6 = 0
i=10 (now the product = 362880) value of i
Is i<=10 true? i=7 (now the product = 0)
Yes, do this Is i<=10 true?
product = product * i = 362880 * 10 = 3628800 Yes, do this
stops because the condition is i<=10 product = product * i = 0 * 7 = 0
value of i
The statement System.out.println("the product of the i=8 (now the product = 0)
first10 digits = " + product); make provision to display Is i<=10 true?
the output: Yes, do this
the product of the first 10 digits = 3628800 product = product * i = 0 * 8 = 0
on the screen. value of i
i=9 (now the product = 0)
If the statement int i, product = 1; is replaced by int i, Is i<=10 true?
product = 0;
Yes, do this
Then
product = product * i = 0 * 9 = 0
value of i
value of i
i=1 (product = 0 because the product is initialized to 0
i=10 (now the product = 0)
in the statement int i, product = 0;)
Is i<=10 true?
Is i<=10 true?
Yes, do this
Yes, do this
product = product * i = 0 * 10 = 0
product = product * i = 0 * 1 = 0
stops because the condition is i<=10
value of i
The statement System.out.println("the product of the
i=2 (now the product = 0)
first10 digits = " + product); make provision to
Is i<=10 true? display the output:
Yes, do this the product of the first 10 digits = 0
product = product * i = 0 * 2 = 0 on the screen.
value of i (wrong result because the product of the first10 digits
i=3 (now the product = 0) is 3628800)
Is i<=10 true?
Yes, do this If the statement for(i=1; i<=10; i++) is replaced by
product = product * i = 0 * 3 = 0 for(i=5; i<=8; i++)
value of i Then
i=4 (now the product = 0) value of i
Is i<=10 true? i=5 (product = 1 because the product is initialized to 1
Yes, do this in the statement int i, product = 1;)
product = product * i = 0 * 4 = 0 Is i<=8 true?
value of i Yes, do this
i=5 (now the product = 0) product = product * i = 5 * 1 = 5
Is i<=10 true? value of i
Yes, do this i=6 (now the product = 5)
product = product * i = 0 * 5 = 0 Is i<=8 true?
value of i Yes, do this
i=6 (now the product = 0) product = product * i = 5 * 6 = 30
Is i<=10 true? value of i
159
i=7 (now the product = 30) will be outputted on the screen.
Is i<=8 true? How the execution takes its Way through the for
Yes, do this Loop statement
product = product * i = 30 * 7 = 210
value of i Since you entered the number 2, therefore: n=2.
i=8 (now the product = 210) value of i
Is i<=8 true? i=1
Yes, do this Is i<=5 true?
product = product * i = 210 * 8 = 1680 Yes, print this
stops because the condition i<=8 is achieved and the 2*1=2
statement using the statement System.out.println ( \n n + " * "
System.out.println("the product of the first10 digits = + i + " = " + n * i);
" + product);
make provision to display the output: value of i
the product of the first 10 digits = 1680 i=2
on the screen. Is i<=5 true?
Yes, print this
Note: If the statement 2*2=4
int i, product, product = 1; using the statement System.out.println ( \n n + " * "
is written instead of int i, product = 1; + i + " = " + n * i);
Then the compilation error message is flagged on the
screen (stating that product is twice declared). value of i
i=3
Program 10.5 Is i<=5 true?
Yes, print this
Java Program to print the table of a number using the 2*3=6
for loop statement using the statement System.out.println ( \n n + " * "
import java.util.Scanner; + i + " = " + n * i);
public class HelloWorld{
public static void main(String [] args){ value of i
int n, i; i=4
Scanner scan = new Scanner(System.in); Is i<=5 true?
System.out.println("Enter a number: "); Yes, print this
n = scan.nextInt(); 2*4=8
for( i=1; i<=5; i++) using the statement System.out.println ( \n n + " * "
System.out.println ( \n n + " * " + i + " = " + n * + i + " = " + n * i);
i);
} value of i
} i=5
Enter any number: Is i<=5 true?
If you enter the number 2 (i.e., n=2) Yes, print this
2*1=2 2 * 5 = 10
2*2=4 using the statement System.out.println ( \n n + " * "
2*3=6 + i + " = " + n * i);
2*4=8
2 * 5 = 10 stop Now because the condition i <=5 is achieved.
160
If the symbol * is replaced by + System.out.println(" \n number = " + i + " its square
i.e., = " + i*i);
import java.util.Scanner;
public class HelloWorld{ i.e., if the above program is rewritten as:
public static void main(String [] args){
int n, i; public class HelloWorld{
Scanner scan = new Scanner(System.in); public static void main(String[] args){
System.out.println("Enter a number: "); int i;
n = scan.nextInt(); for( i=1; i<=10; i++)
for( i=1; i<=5; i++) System.out.println(" \n number = " + i + " its square
System.out.println ( \n n + " + " + i + " = " + n + = " + i*i);
i); }
} }
}
The output on the screen: Then the output on the screen is:
Enter a number: number = 1 its square=1
If you enter the number 2 (i.e., n=2) number = 2 its square=4
2+1=3 number = 3 its square=9
2+2=4 number = 4 its square=16
2+3=5 number = 5 its square=25
2+4=6 number = 6 its square=36
2+5=7 number = 7 its square=49
will be outputted on the screen. number = 8 its square=64
number = 9 its square=81
Program 10.6 number= 10 its square=100
Java program to print the first 10 numbers starting If the statement System.out.println(" \n number = " +
from one together with their squares i + " its square = " + i*i); is replaced by the statement
System.out.println(" \n number = " + i + " \t its
public class HelloWorld{ square = " + i*i);
public static void main(String[] args){ i.e., if the above program is rewritten as:
int i;
for( i=1; i<=10; i++) public class HelloWorld{
System.out.println(" number = " + i + " its square = public static void main(String[] args){
" + i*i); int i;
} for( i=1; i<=10; i++)
} System.out.println(" \n number = " + i + " \t its
The output on the screen: square = " + i*i);
number = 1 its square=1number = 2 its }
square=4number = 3 its square=9number = 4 its }
square=16number = 5 its square=25number = 6 its
square=36number = 7 its square=49number = 8 its Then the output on the screen is:
square=64number = 9 its square=81number= 10 its
number=1 its square=1
square=100
number=2 its square=4
number=3 its square=9
If the statement System.out.println(" number = " + i +
" its square = " + i*i); is replaced by the statement number=4 its square=16
161
number=5 its square=25
number=6 its square=36 Write a program to print the first 10 numbers starting
number=7 its square=49 from one together with their squares and cubes:
number=8 its square=64
number=9 its square=81 Answer:
number=10 its square=100
public class HelloWorld{
tab /t is included because to leave space between public static void main(String[] args) throws
number =1 and its square=1 Exception{
int i;
If the statement System.out.println(" \n number = " + i for( i=1; i<=10; i++)
+ " \t its square = " + i*i); is replaced by the System.out.println(" \n number = " + i + " its square
statement = " + i*i + " its cube = " + i*i*i);
System.out.println(" \n number = " + i + " \n its }
square = " + i*i); }
i.e., if the above program is rewritten as: “When I am working on a problem I never think about
public class HelloWorld{ beauty. I think only how to solve the problem.
public static void main(String[] args){ But when I have finished, if the solution is not
int i; beautiful, I know it is wrong.”
for( i=1; i<=10; i++) --R. BUCKMINSTER FULLER
System.out.println(" \n number = " + i + " \n its
square = " + i*i); Program 10.7
}
} Java program to print the sum of two numbers using
method
Then the output on the screen is:
number = 1 public class HelloWorld{
its square=1 public static void main(String[] args){
number = 2 int a, b, c;
its square=4 a = 11;
number = 3 b = 6;
its square=9 c = add (a, b);
number = 4 System.out.println(" sum of two numbers = " + c);
its square=16 }
number = 5 public static int add (int a, int b) {
its square=25 return (a+b) ;
number = 6 }
its square=36 }
number = 7 The output on the screen:
its square=49 sum of two numbers = 17
number = 8
its square=64 public static void main(String[] args) imply main
method and
number = 9
{
its square=81
} imply the body of the main method with in which
number= 10
the program statements:
its square=100
int a, b, c;
162
a = 11; by the statements
b = 6; System.out.println("Enter any two numbers: ");
c = add (a, b); a = scan.nextInt();
System.out.println(" sum of two numbers = " + c); are b = scan.nextInt();
written. i.e., the above program should be rewritten as:
163
Enter any two numbers: System.out.println(" largest of three numbers = " +
If you enter the values 2 and 3 result);
product of two numbers = 6 will be outputted on the }
screen. public static int max (int a, int b, int c) {
if(a>b)
Java program to print the greatest of two numbers return a;
using method if(b>a)
return b;
import java.util.Scanner; if(c>a&&c>b)
public class HelloWorld{ return c;
public static void main(String[] args) { }
int a, b; }
Scanner scan = new Scanner(System.in); The output on the screen:
System.out.println("Enter any two numbers: "); Enter any three numbers:
a = scan.nextInt(); If you enter three numbers 3, 5 and 10
b = scan.nextInt(); largest of three numbers = 10 will be outputted on the
result = max (a, b); screen.
System.out.println(" largest of two numbers = " +
result); Java program to print the square of the number using
} method
public static int max (int a, int b) {
if(a>b) import java.util.Scanner;
return a; public class HelloWorld{
if(b>a) public static void main(String[] args) {
return b; int x;
} Scanner scan = new Scanner(System.in);
} System.out.println("Enter any number: ");
The output on the screen: x = scan.nextInt();
Enter any two numbers: System.out.println("square of the number = " + square
If you enter two numbers 3 and 5 (x));
largest of two numbers= 5 will be outputted on the }
screen. public static int square (int x){
return x*x;
Java program to print the greatest of three numbers }
using method }
The output on the screen is:
import java.util.Scanner; Enter any number:
public class HelloWorld{ If you enter the number 5
public static void main(String[] args) { square of the number = 25 will be outputted on the
int a, b, c; screen.
Scanner scan = new Scanner(System.in);
System.out.println("Enter any three numbers: "); Program 10.8
a = scan.nextInt();
b = scan.nextInt(); Switch (case) allows to make decision from the
c = scan.nextInt(); number of choices i.e., from the number of cases
result = max (a, b, c); For example:
164
public class HelloWorld{ Error
public static void main(String[] args)throws (Entered character K does not correspond to any of the
Exception{ cases
char ch; case 'R':
System.out.print("Enter a character:"); case 'W':
ch = (char)System.in.read(); case 'Y':
switch(ch) case 'G':
{ Therefore the statements
case 'R': default:
System.out.print("Red"); System.out.print("Error");
break; make provision to display the output
case 'W': Error
System.out.print("White"); on the screen).
break; If the statements
case 'Y': {
System.out.print("Yellow"); case 'R':
break; System.out.print("Red");
case 'G': break;
System.out.print("Green"); case 'W':
break; System.out.print("White");
default: break;
System.out.print("Error"); case 'Y':
break; System.out.print("Yellow");
} break;
} case 'G':
} System.out.print("Green");
The output on the screen is: break;
Enter a character: default:
If you enter a character R System.out.print("Error");
Red will be outputted on the screen. break;
} are replaced by the statements
switch(ch) allow to make decision from the number of {
choices i.e., from the number of cases case 'R':
case 'R': System.out.print("Red");
case 'W': case 'W':
case 'Y': System.out.print("White");
case 'G': case 'Y':
Since we have entered the character R (which System.out.print("Yellow");
corresponds to case 'R':) break;
The statement case 'G':
System.out.print("Red"); System.out.print("Green");
make provision to display the output break;
Red default:
on the screen. System.out.print("Error");
Suppose you enter a character K break;
The output on the screen is: }
165
i.e., if the statement break; is not written after the Ends because of the condition i<5.
statements
case 'R': Note:
System.out.print("Red"); Array declaration in C:
int num [5] = {16, 18, 20, 25, 36};
case 'W': or
System.out.print("White"); int num [] = {16, 18, 20, 25, 36};
Then the output on the screen is: Array declaration in C++:
Red int num [5] = {16, 18, 20, 25, 36};
White or
Yellow int num [] = {16, 18, 20, 25, 36};
i.e., the output is printed till yellow even though you But array declaration in java:
have entered the character R. int [] num = {16, 18, 20, 25, 36};
Note: C and C++ supports pointers and structures *If you write int [5] num = {16, 18, 20, 25, 36};
whereas Java does not i.e., Java do not support instead of int [] num = {16, 18, 20, 25, 36};
structures and pointers because JVM (Java virtual
Then the compilation error will be displayed on the
machine—a core component of java) do not support
screen.
structures and pointers.
The statement int [] num = {16, 18, 20, 25, 36}; imply
Program 10.9
that we are creating an integer array (and the name of
array is num) consisting of 5 values (i.e., 16, 18, 20,
Java program to print the output 25, 36) of the same data type int.
Element [0] = 16 With the declaration int [] num = {16, 18, 20, 25, 36};
Element [1] = 18 -- computer creates 5 memory cells (because there are
Element [2] = 20 5 elements within the braces {}) with name num[0],
Element [3] = 25 num[1], num[2], num[3], num[4]. And since
Element [4] = 36 int [ ] num = {16, 18, 20, 25, 36};
using arrays: the values 16, 18, 20, 25, 36 are stored in num[0],
num[1], num[2], num[3], num[4] respectively.
public class HelloWorld{
How the execution takes its way through the for
public static void main(String[] args){
loop statement
int i;
int [] num = {16, 18, 20, 25, 36};
value of i
for(i=0; i<5; i++)
i=0
System.out.println("Element [" + i + " ] = " +
Is i<5 true?
num[i]);
Yes, print this
}
Element [0] = 16
}
using the statement
System.out.println("Element [" + i + " ] = " +
The output on the screen:
num[i]);
Element [0] = 16
value of i
Element [1] = 18
i=1
Element [2] = 20
Is i<5 true?
Element [3] = 25
Yes, print this
Element [4] = 36
166
Element [1] = 18 If the statement int [] a = {16, 18, 20, 25, 36}; is
using the statement replaced by the statement
System.out.println("Element [" + i + " ] = " + int [5] a = {16, 18, 20, 25, 36};
num[i]); or by the statement
int num [i] = {16, 18, 20, 25, 36};
value of i Then the compilation error will be displayed on the
i=2 screen.
Is i<5 true?
Yes, print this Suppose the statement System.out.println("Element ["
Element [2] = 20 + i + " ] = " + a[i]); is replaced by the statement
using the statement System.out.println("Element [" + i + " ] = " + a[0]);
System.out.println("Element [" + i + " ] = " +
num[i]); Then the output on the screen is:
Element [0] = 16
value of i Element [1] = 16
i=3 Element [2] = 16
Is i<5 true? Element [3] = 16
Yes, print this Element [4] = 16
Element [3] = 25
using the statement Suppose the statement System.out.println("Element ["
System.out.println("Element [" + i + " ] = " + + i + " ] = " + a[i]); is replaced by the statement
num[i]); System.out.println("Element [" + i + " ] = " + a[1]);
167
Element [3] = 25 Is i<5 true?
Element [4] = 25 Yes, do this
sum = sum + num[i] = sum + num[2] = 34 +20 =54
Suppose the statement System.out.println("Element ["
+ i + " ] = " + a[i]); is replaced by the statement value of i
System.out.println("Element [" + i + " ] = " + a[4]); i=3 (now the sum = 54)
i.e., a[4] corresponds to the output: Is i<5 true?
Element [0] = 36 Yes, do this
Element [1] = 36 sum = sum + num[i] = sum + num[3] = 54 +25 =79
Element [2] = 36
Element [3] = 36
Element [4] = 36 value of i
i=5 (now the sum = 79)
(a) Java program to print the sum of the elements in Is i<5 true?
array. Yes, do this
sum = sum + num[i] = sum + num[5] = 79 + 36 =115
public class HelloWorld{
stops because the condition is i<5
public static void main(String[] args){
The statement System.out.println("Sum of the
int i, sum = 0; Elements in the array = " + sum); make provision to
int [] num = {16, 18, 20, 25, 36}; display the output:
for(i=0; i<5; i++) Sum of the Elements in the array = 115
sum = sum + num[i]; on the screen.
System.out.println("Sum of the Elements in the array
= " + sum); If the statement
} int i, sum = 0; is replaced by int i, sum = 1;
} Then The output on the screen:
The output on the screen: Sum of the Elements in the array = 116
Sum of the Elements in the array = 115 (wrong result because the sum of the elements in the
i.e., 16 + 18 + 20 + 25 + 36 = 115 array is 115).
How the Execution takes its way through the for (b) Java program to print the average of the elements
loop statement in the array
168
Sum of the Elements in the array = 115 Einstein [3] = 83
average of the elements in the array = 23 Einstein [4] = 84
Einstein [5] = 69
Write a program to print Einstein [6] = 73
Einstein [7] = 78
Einstein [0] = E
Einstein [1] = I public class HelloWorld{
Einstein [2] = N public static void main(String[] args) throws
Einstein [3] = S Exception{
Einstein [4] = T int i;
Einstein [5] = E char [] name = {' E' , ' I', ' N', ' S', ' T ', ' E', ' I', ' N'};
Einstein [6] = I for(i=0; i<8; i++)
Einstein [7] = N System.out.println("Einstein [" + i + " ] = " +
using arrays name[i]);
}
Answer: }
What will be the output of the following program? public class HelloWorld{
public static void main(String[] args) throws
public class HelloWorld{ Exception{
public static void main(String[] args) throws int i;
Exception{ char [] body = {'b', 'o', 'd', 'y'};
int i; for(i=0; i<4; i++)
int [] name = {' E' , ' I', ' N', ' S', ' T ', ' E', ' I', ' N'}; System.out.println("body [" + body [i] + " ] = " +
for(i=0; i<8; i++) body [i]);
System.out.println("Einstein [" + i + " ] = " + }
name[i]); }
}
} Answer:
body [b] = b
Answer: body [o] = o
body [d] = d
Einstein [0] = 69 body [y] = y
Einstein [1] = 73
Einstein [2] = 78
169
Examine the following program and write the System.out.println("\n masses of the individual
output: substances are 16 \t 18 \t 19 \t 20\t 21\t kilograms");
int j, sum = 0;
int[] num = {16, 18, 19, 20, 21};
public class HelloWorld { for(j=0; j<5;j++)
public static void main(String [] args) throws sum = sum + num [j];
Exception{ System.out.println("\n sum of the masses of the
System.out.println(" \n E=mc squared Einstein's individual substances = " + sum);
famous equation that gave birth to the atom bomb and System.out.println("\n sum of the energies of the
heralded a new world of atomic physics"); individual substances = " + sum * 300000000 *
System.out.println(" \n 300000000);
"); System.out.println("\n average energy = " + sum / 5);
System.out.println("\n E = energy m = mass c = speed System.out.println("\n
of light in vacuum"); ");
System.out.println("\n As we know c squared is huge System.out.println("\n
so if you convert a small amount of mass you'll get a ");
tremendous amount of energy"); int p, q, r;
System.out.println(" \n For example if you convert p= 6;
1kg of mass you'll get energy of ");
q= 3;
int E, m, c;
System.out.println("\n expected energy = " + p +
m=1; "multiplied by ten to the power of minus 16 joules
c=300000000; calculated using Einstein equation");
E=m*c*c; System.out.println("\n experimental energy = " + q +
System.out.println("\n " + E + " joules "); "multiplied by ten to the power of minus 16 joules
System.out.println(" \n Suppose c would have been calculated using Einstein equation");
3*10 to the power of -8 meter per second then For 1 r= q-p;
kg of mass E = 9 *10 to the power of -16 joules"); System.out.println("\n difference between
System.out.println(" \n hence thousands and thousands experimental energy and expected energy =" + r + "
of hydrogen atoms in the sun would have to burn up to multiplied by ten to the power of minus 16 joules");
release 4 * 10 to the power of 26 joules of energy per System.out.println("\n absolute value of the difference
second in the form of radiation"); between experimental energy and expected energy ="
int i; + Math.abs(r) + "multiplied by ten to the power of
for(i=0; i<5;i++) minus 16 joules");
System.out.println(" \n Therefore sun would have char k;
ceased "); char [ ] einstein={'e', 'm', 'c', 's', 'q', 'u', 'a', 'r', 'e', 'd'};
System.out.println("\n to form black hole even before for(k=0; k<10; k++)
an ooze of organic molecules would react and built System.out.println("\n Einstein[" + einstein [k] + "] =
earliest cells and then advance to a wide variety of one " + einstein [k]);
celled organisms and evolve through a highly int u;
sophisticated form of life to primitive mammals");
for(u=1; u<3; u++)
int v;
System.out.println("\n Hey! Einstein may not be
v=300000000; wrong please repeat the experiment");
c=300000000; System.out.println("\n * ");
if (v==c) System.out.println("\n ***** ");
System.out.println("\n rest mass of the photon is zero System.out.println("\n **Albert Einstein**
because light travels at the speed of light"); ");
else System.out.println("\n **e= mc squared**
System.out.println(" \n Albert Einstein's special theory ");
of relativity has to be rewritten"); System.out.println("\n *****");
170
double f, h, E1; }
f=2.5; }
h= Math.pow(6.625, -34);
E1 = h*f; Note:
System.out.println("\n energy calculated using the
Planck equation = " + E1); import java.util.Scanner;
if (E==E1) public class HelloWorld {
System.out.println("\n hf cannot be equivalent to mc public static void main(String [] args) {
squared"); int x, y;
if(E>E1) Scanner scan = new Scanner(System.in);
System.out.println("\n hf can be equivalent to mc System.out.print("Enter any Number: ");
squared");
x = scan.nextFloat();
if (E<E1)
System.out.print("Enter any Number: ");
System.out.println("\n Einstein and Planck equation
y = scan.nextInt();
cannot be equalized");
System.out.println(" square root of x = " +
System.out.println("\n ");
Math.sqrt(x));
System.out.println("\n
System.out.println(" square root of y = " +
");
Math.sqrt(y));
System.out.println("\n for more details please refer the
}
book ");
}
System.out.println("\n Einsteinian Physics");
The output on the screen:
System.out.println("***************************
******************\n"); Enter any Number:
System.out.println("*************************** If you enter the number 9
*****************\n"); square root of x = 3 will be outputted on the screen.
System.out.println("According to the Albert Einstein's Enter any Number:
law of variation of mass with velocity: \n"); If you enter the number 4
System.out.println("M = m0 / sqrt ((1- (u/c) squared) square root of y = 2 will be outputted on the screen.
\n ");
System.out.println("M = mass of the moving body \t If
m0 = rest mass of the body \t u= velocity of the body /*
\t c= speed of light in vacuum\n ");
{
*/
double M, m0;
int g, b;
is introduced i.e., if the above program is rewritten as:
m0 = 0.999;
import java.util.Scanner;
g = 200000000;
public class HelloWorld {
b = g/c * g /c;
public static void main(String [] args) {
M = m0 / Math.sqrt (1 - b);
int x, y;
System.out.println(" \n Mass of the moving body = "
Scanner scan = new Scanner(System.in);
+ M);
if (M==m0 || M<m0) System.out.print("Enter any Number: ");
x = scan.nextInt();
System.out.println("\n body is at rest or the body is
moving with nonrelativistic speed"); /*
else System.out.print("Enter any Number: ");
System.out.println("\n body is moving with relativistic y = scan.nextInt();
speed"); */
}
171
System.out.println(" square root of x = " + C++ uses cin as input function to read the
Math.sqrt(x)); character or integer entered through the keyboard
/* and cout as output function to print the output on
System.out.println(" square root of y = " + the screen.
Math.sqrt(y)); But Java uses scan.nextInt() or scan.nextFloat() as
input method to read the variable entered through
*/
the keyboard and System.out.println as output
} method to print the output on the screen.
} Functions are in C & C++ whereas methods are in
Then the output on the screen is: Java.
Enter any Number: C & C++ are platform dependent whereas Java is
If you enter the number 9 platform independent (Code written in Java can
be taken from one computer to the other without
square root of x = 3 will be outputted on the screen.
having to worry about system configuration
details).
What is the mistake in the following program: In C & C++, program instruction codes are
written and executed within the body of main
public class HelloWorld { function main() where as in Java -- program
public static void main(String [] args) { instruction codes are written and executed within
long float x; the body of main method public static void
main(String[] args).
Scanner scan = new Scanner(System.in);
data types like int float, char are same in C, C++
System.out.print("Enter any Number: "); & Java.
x = scan.nextFloat(); C is structured language whereas C++ & Java is
System.out.println(" square root of x = " + object oriented language (i.e., C++ & Java has the
Math.cbrt(x)); extensive power and immense extensibility to
} write large scale complex programs).
Operators such as %d, %f & %c are used in C
whereas no operators are used in C++ & Java.
Answer:
A program written in Java usually requires more
long float x; should not be used -- only float x should
memory space than the same program written in
be used because Java do not support the data type such C &C++.
as long int, long float etc.
Java provides both high speed and high
performance and reliability, flexibility and
A difference engine is an automatic mechanical seamless integration with other frameworks and
calculator designed to tabulate polynomial functions. technologies -- compared to C & C++.
Java supports multithreading (a process of
executing several codes concurrently) while C &
Comparison of C, C++ and Java C++ do not.
172
C program to test whether the entered character is
If you want to enter the character through the upper case letter or not
keyboard, then the above program should take the #include<stdio.h>
form: main()
#include<stdio.h> {
main() char ch = 'a';
{ if(isupper(ch))
char ch; printf("you have entered the upper case letter");
printf("Enter any character:"); else
scanf("%c", &ch); printf("you have entered the lower case letter");
char b = tolower(ch); }
printf("upper case letter %c is converted to lower case Output on the screen:
letter %c", ch, b); you have entered the lower case letter
} If the statement char ch = 'a'; is replaced by the
Output on the screen: statement char ch = 'A';
Enter any character: i.e., if the above program is rewritten as:
If you enter the character C #include<stdio.h>
upper case letter C is converted to lower case letter c main()
will be outputted on the screen. {
char ch = 'A';
Program 1.2 if(isupper(ch))
C program to convert the lower case letter to upper printf("you have entered the upper case letter");
case letter else
#include<stdio.h> printf("you have entered the lower case letter");
main() }
{ Then the output on the screen is:
char ch = 'a'; you have entered the upper case letter
char b = toupper(ch);
printf("lower case letter %c is converted to upper case Program 1.3
letter %c", ch, b); C program to test whether the entered character is
} lower case letter or not
Output on the screen: #include<stdio.h>
lower case letter a is converted to upper case letter A main()
If you want to enter the character through the {
keyboard, then the above program should take the char ch = 'a';
form: if(islower(ch))
#include<stdio.h> printf("you have entered the lower case letter");
main() else
{ printf("you have entered the upper case letter");
char ch; }
printf("Enter any character:"); Output on the screen:
scanf("%c", &ch); you have entered the lower case letter
char b = toupper(ch);
printf("lower case letter %c is converted to upper case Program 1.4
letter %c", ch, b); C program to print the value of tan inverse x (i.e., the
} value of tan-1x)
Output on the screen: #include<stdio.h>
Enter any character: #include<math.h>
If you enter the character h main()
lower case letter h is converted to upper case letter H {
will be outputted on the screen. int x = 20;
printf("the value of tan inverse x = %f", atan(x));
Program 1.3 }
Output on the screen:
173
the value of tan inverse x = 1.520838 x = 205;
y= -(~x);
Program 1.5 printf("the value of y is:%d", y);
C program to print the value of tan inverse x/y (i.e., }
the value of tan-1x/y) Then the output on the screen is:
#include<stdio.h> the value of y is:206
#include<math.h>
main() Program 1.7
{ C program to print the ASCII (American Standard
int x,y; Code for Information Interchange) value of the
x = 20; entered character
y =20; #include<stdio.h>
printf("the value of tan inverse x/y = %f", atan2(x,y)); main()
} {
Output on the screen: char ch ='A';
the value of tan inverse x/y = 0.785398 printf("the ASCII value of ch is: %d", ch);
“Linux is evolution, not intelligent design.” }
— Linus Torvalds Output on the screen:
the ASCII value of ch is: 65
Program 1.6 If the statement printf("the ASCII value of ch is: %d",
C program to print the value of fmod(x, y) ch); is replaced by the statement
#include<stdio.h> printf("the ASCII value of ch is: %c", ch);
#include<math.h> i.e., if the above program is rewritten as:
main() #include<stdio.h>
{ main()
float x = 20.500000; {
float y =20.799999; char ch ='A';
printf("the remainder of %f divided by %f is %f", x, y, printf("the ASCII value of ch is: %c", ch);
fmod(x,y)); }
} Then the output on the screen is:
Output on the screen: the ASCII value of ch is: A
the remainder of 20.500000 divided by 20.799999 is
20.500000 What will be the output of the following programs:
(a)
Program 1.6 #include<stdio.h>
C program to print the value of ~x main()
#include<stdio.h> {
main() int i;
{ int num [5] ={16,18,19,20,21};
int x, y; for(i=0;i<5;i++)
x = 205; printf("\n Element = %d", num[i] +1);
y=~x; }
printf("the value of y is:%d", y); Answer:
} Element = 17
Output on the screen: Element = 19
the value of y is:-206 Element = 20
If the statement y=~x; is replaced by the statement y= Element = 21
-(~x); Element = 22
i.e., if the above program is rewritten as: (b)
#include<stdio.h> #include<stdio.h>
main() main()
{ {
int x, y;
174
int i = 54; The length of the string = 4 will be displayed on the
int y = i<<1; console screen because there are four letters in the
printf("The value of y = %d", y); word tech.
}
Answer: Program 1.9
The value of y = 108 C program to print the factorial of the entered number
If the statement i<<1 is replaced by the statement i<<2 #include<stdio.h>
Then the output on the screen is: main()
The value of y = 216 {
i.e., int i, n, fact=1 ;
i<<1 implies 54 * 2 = 108 printf("Enter any number:");
i<<2 implies 54 * 4 = 216 scanf("%d", &n);
i<<3 implies 54 * 6 = 324 for(i=1; i<=n; i++)
i<<4 implies 54 * 8 = 432 fact = fact *i;
printf("\n Entered number is: %d", n);
(c) printf("\n The factorial of the entered number %d is:
#include<stdio.h> %d", n, fact);
main() }
{ Output on the screen:
int i = 54; Enter any number:
int y = i>>1; If you enter the number 2
printf("The value of y = %d", y); Entered number is: 2
} The factorial of the entered number 2 is: 2 will be
Answer: displayed on the screen.
The value of y = 27 Suppose if you enter the number 4
If the statement i>>1 is replaced by the statement i>>2 Entered number is: 4
Then the output on the screen is: The factorial of the entered number 4 is: 24 (4 × 3 × 2
The value of y = 13 × 1) will be displayed on the screen.
i.e.,
i>>1 implies 54 / 2 = 27 C ++
i>>2 implies 54 / 4 = 13 Program 2.0
i>>3 implies 54 / 6 = 9 C++ program to convert the upper case letter to lower
i>>4 implies 54 / 8 = 6 case letter
Note: << implies left shift operator and >> implies #include<iostream>
right shift operator using namespace std;
Program 1.8 main()
C program to print the length of the entered character {
(i.e., to print the length of the string) char ch = 'A';
#include<stdio.h> char b = tolower(ch);
#include<string.h> cout<<"upper case letter" << ch << "is converted to
main() lower case letter"<< b;
{ }
char ch[4]; Output on the screen:
printf("Enter any word: "); upper case letter A is converted to lower case letter a
scanf("%c", &ch); If you want to supply the value of ch through the
printf("The length of the string = %d", strlen(ch)); keyboard, then the above take the form:
} #include<iostream>
Output on the screen: using namespace std;
Enter any word: main()
If you enter the word dog {
The length of the string = 3 will be displayed on the char ch;
console screen because there are three letters in the cout<<"Enter any character:"<<endl;
word dog. cin>>ch;
Suppose if you enter the word tech char b = toupper(ch);
175
cout<<"lower case letter"<< ch << "is converted to you have entered the upper case letter
upper case letter"<< b;
} Program 2.3
Output on the screen: C++ program to test whether the entered character is
Enter any character: lower case letter or not
If you enter the character C #include<iostream>
upper case letter C is converted to lower case letter c using namespace std;
will be outputted on the screen. main()
{
Program 2.1 char ch = 'a';
C ++ program to convert the lower case letter to upper if(islower(ch))
case letter cout<<"you have entered the lower case letter";
#include<iostream> else
using namespace std; cout<<"you have entered the upper case letter";
main() }
{ Output on the screen:
char ch = 'a'; you have entered the lower case letter
char b = toupper(ch); Program 2.4
cout<<"lower case letter"<< ch << "is converted to C++ program to print the value of tan inverse x (i.e.,
upper case letter"<< b; the value of tan-1x)
} #include<iostream>
Output on the screen: #include<cmath>
lower case letter a is converted to upper case letter A using namespace std;
main()
{
Program 2.2 int x = 20;
C++ program to test whether the entered character is cout<<"the value of tan inverse x = "<< atan(x);
upper case letter or not }
#include<iostream> Output on the screen:
using namespace std; the value of tan inverse x = 1.520838
main()
{ Program 2.5
char ch = 'a'; C++ program to print the value of tan inverse x/y (i.e.,
if(isupper(ch)) the value of tan-1x/y)
cout<<"you have entered the upper case letter"; #include<iostream>
else #include<cmath>
cout<<"you have entered the lower case letter"; using namespace std;
} main()
Output on the screen: {
you have entered the lower case letter int x,y;
If the statement char ch = 'a'; is replaced by the x = 20;
statement char ch = 'A'; y =20;
i.e., if the above program is rewritten as: cout<<"the value of tan inverse x/y = " << atan2(x,y);
#include<iostream> }
using namespace std; Output on the screen:
main() the value of tan inverse x/y = 0.785398
{ Program 2.6
char ch = 'A'; C++ program to print the value of fmod(x, y)
if(isupper(ch)) #include<iostream>
cout<<"you have entered the upper case letter"; #include<cmath>
else using namespace std;
cout<<"you have entered the lower case letter"; main()
} {
Then the output on the screen is: float x = 20.500000;
176
float y =20.799999; the ASCII value of ch is: A
cout<<"the remainder of"<< x<< "divided by" << y<<
" is: " << fmod(x,y); What will be the output of the following programs:
}
Output on the screen: (a)
the remainder of 20.500000 divided by 20.799999 is #include<iostream>
20.500000 using namespace std;
main()
Program 2.7 {
C++ program to print the value of ~x int i;
#include<iostream> int num [5] ={16,18,19,20,21};
using namespace std; for(i=0;i<5;i++)
main() cout<< "\n Element = " << num[i] +1;
{ }
int x, y; Answer:
x = 205; Element = 17
y=~x; Element = 19
cout<< "the value of y is: " << y; Element = 20
} Element = 21
Output on the screen: Element = 22
the value of y is:-206
If the statement y=~x; is replaced by the statement y= (b)
-(~x); #include<iostream>
i.e., if the above program is rewritten as: using namespace std;
#include<iostream> main()
using namespace std; {
main() int i = 54;
{ int y = i<<1;
int x, y; cout<< "The value of y = " << y;
x = 205; }
y= -(~x); Answer:
cout<< "the value of y is: " << y; The value of y = 108
} If the statement i<<1 is replaced by the statement i<<2
Then the output on the screen is: Then the output on the screen is:
the value of y is:206 The value of y = 216
i.e.,
Program 2.8 i<<1 implies 54 * 2 = 108
C++ program to print the ASCII (American Standard i<<2 implies 54 * 4 = 216
Code for Information Interchange) value of the i<<3 implies 54 * 6 = 324
entered character i<<4 implies 54 * 8 = 432
#include<iostream>
using namespace std; (c)
main() #include<iostream>
{ using namespace std;
char ch ='A'; main()
cout<<"the ASCII value of ch is: "<< ( int) ch; {
} int i = 54;
Output on the screen: int y = i>>1;
the ASCII value of ch is: 65 cout<< "The value of y = "<< y;
If the statement cout<<"the ASCII value of ch is: "<< }
( int) ch; is replaced by the statement Answer:
cout<<"the ASCII value of ch is: "<< ( char) ch; The value of y = 27
Then the output on the screen is: If the statement i>>1 is replaced by the statement i>>2
Then the output on the screen is:
177
The value of y = 13 The factorial of the entered number 2 is: 2 will be
i.e., displayed on the screen.
i>>1 implies 54 / 2 = 27 Suppose if you enter the number 4
i>>2 implies 54 / 4 = 13 Entered number is: 4
i>>3 implies 54 / 6 = 9 The factorial of the entered number 4 is: 24 (4 × 3 × 2
i>>4 implies 54 / 8 = 6 × 1) will be displayed on the screen.
Note: << implies left shift operator and >> implies
right shift operator Java
178
replaced by the statement }
if(Character.isDigit(5)) }
Then the output on the screen is: Output on the screen:
the entered character is not a digit the entered character is a letter
179
Note: if the statement public class HelloWorld{
System.out.println("\n Element = " + num[i] +1); public static void main (String [] args){
is written instead of the statement int x, y;
System.out.println(“\n Element = “ + (num[i] +1)); x = 205;
Then the output on the screen is: y=~x;
Element = 161 System.out.println("the value of y is: " + y);
Element = 181 }
Element = 191 }
Element = 201 Output on the screen:
Element = 211 the value of y is:-206
If the statement y=~x; is replaced by the statement y=
What will be the output of the following programs: - (~x);
i.e., if the above program is rewritten as:
(a) public class HelloWorld{
public class HelloWorld{ public static void main (String [] args){
public static void main (String []args){ int x, y;
int i = 54; x = 205;
int y = i >>1; y= -(~x);
System.out.println("value of y = " + y); System.out.println("the value of y is: " + y);
} }
} }
Then the output on the screen is:
(b) the value of y is:206
public class HelloWorld{
public static void main (String []args){
int i = 54; Program 3.7
int y = i <<1; Java program to print the length of the entered
System.out.println("value of y = " + y); character (i.e., to print the length of the string)
} A)
} public class HelloWorld{
public static void main (String [] args){
Program 3.6 String m = new String ("computer");
Java program to print the ASCII (American Standard System.out.println("length of string = " + m.length());
Code for Information Interchange) value of the }
entered character }
public class HelloWorld{ Output on the screen:
public static void main (String []args){ length of string = 8
char ch ='A';
System.out.println("the ASCII value of ch is: " + ( int) B)
ch); import java.util.Scanner;
} public class HelloWorld {
} public static void main(String [] args) {
Output on the screen: String m;
the ASCII value of ch is: 65 Scanner in = new Scanner(System.in);
If the statement System.out.println("the ASCII value System.out.print("Enter the word: ");
of ch is: " + ( int) ch); is replaced by the statement m = in.nextLine();
System.out.println("the ASCII value of ch is: " + ( System.out.println(" the word you entered = " + m);
char) ch); System.out.println("length of string = " + m.length());
Then the output on the screen is: }
the ASCII value of ch is: A }
Enter the word: file
the word you entered = file
Program 3.7 length of string = 4
Java program to print the value of ~x
180
Program 3.8 }
Java program to display the date }
import java.util.Date; Output on the screen:
public class HelloWorld { length of string = 8
public static void main(String args[]) { the word you entered = computer
Date date = new Date(); reverse of the entered word: retupmoc
System.out.println(date.toString()); If you want to enter the word through the keyboard,
} then the above program should take the form:
} import java.util.Scanner;
Output on the screen: public class HelloWorld {
Mon Feb 15 10:49:33 EST 2016 public static void main(String [] args) {
String m;
What will be the output of the following program: Scanner in = new Scanner(System.in);
System.out.print("Enter the word: ");
import java.util.Scanner; m = in.nextLine();
public class HelloWorld { System.out.println(" the word you entered = " + m);
public static void main(String args[]) { String l = new StringBuffer(m).reverse().toString();
int i, n, fact=1 ; System.out.println("reverse of the entered word:" + l);
Scanner scan = new Scanner(System.in); }
System.out.println("Enter any number: " ); }
n= scan.nextInt(); Output on the screen:
for(i=1; i<=n; i++) Enter the word:
fact = fact *i; If you enter the word computer
System.out.println("\n Entered number is: " + n); the word you entered = computer
System.out.println("\n The factorial of the entered reverse of the entered word: retupmoc
number" + n + " is:" + fact); will be displayed on the screen.
} Program 4.0
} Java program to insert the word
public class HelloWorld{
Program 3.8 public static void main (String [] args){
Java program to check whether the two numbers are String m = new String ("computer");
equivalent or not using equals() method System.out.println(" the word you entered = " + m);
public class HelloWorld { String l = new StringBuffer(m).insert(3, "bill
public static void main(String [] args) { gates").toString();
Integer x =5; System.out.println("the word computer after addition
Integer y= 6; of another word bill gates appear as :" + l);
if(x.equals(y)) }
System.out.println("x equals y "); }
else Output on the screen:
System.out.println("x does not equals y "); the word you entered = computer
} the word computer after addition of another word bill
} gates appear as : combill gatesputer
Output on the screen: If you want to enter the word through the keyboard,
x does not equals y then the above program should take the form:
import java.util.Scanner;
Program 3.9 public class HelloWorld{
Java program to print the reverse of the entered word public static void main (String [] args){
public class HelloWorld{ String m;
public static void main (String [] args){ Scanner in = new Scanner(System.in);
String m = new String ("computer"); System.out.print("Enter the word: ");
System.out.println("length of string = " + m.length()); m = in.nextLine();
System.out.println(" the word you entered = " + m); System.out.println(" the word you entered = " + m);
String l = new StringBuffer(m).reverse().toString(); String l = new StringBuffer(m).insert(3, "bill
System.out.println("reverse of the entered word:" + l); gates").toString();
181
System.out.println("the entered word after addition of System.out.println("the entered word after addition of
another word bill gates appear as :" + l); another word bill gates appear as :" + l);
} }
} }
Output on the screen: Output on the screen:
Enter the word: Enter the word:
If you enter the word steve jobs If you enter the word steve jobs
the word you entered = steve jobs the word you entered = steve jobs
the entered word after addition of another word bill the entered word after addition of another word bill
gates appear as :stebill gatesve jobs gates appear as :stebill gatesve jobs
will be outputted on the screen. will be outputted on the screen.
Note:
(a) Note 1:
The statement public static void main(String args[])
import java.util.Scanner; can also be written as:
public class HelloWorld{ static public void main(String [] args)
public static void main (String [] args){
String m; Note 2:
Scanner scan = new Scanner(System.in);
System.out.print("Enter the word: ");
m = scan.nextLine();
System.out.println(" the word you entered = " + m);
String l = new StringBuffer(m).insert(3, "bill
gates").toString();
System.out.println("the entered word after addition of
another word bill gates appear as :" + l);
}
}
(b)
“I think right now it's a battle for the mindshare of developers and for the mindshare of customers, and right
now iPhone and Android are winning that battle.”
: Steve Jobs
ANDROID
Linux based operating system currently developed by Google, based on the Linux kernel and designed primarily
for touchscreen mobile devices such as smartphones and tablets -- which empowers millions of mobile devices such
as smartphones and tablet computers across the world ‒ first developed by Android Inc. (a Palo Alto-based startup
182
company, founded in 2003) and later subsequently acquired by and further advanced by a coalition of hardware,
software and telecommunications companies i.e., open hand set alliance (a group of 84 technology and mobile
companies including Dell, Motorola, Samsung Electronics, Sony, Intel, LG Electronics, Qualcomm, Broadcom,
HTC, Sprint, Texas Instruments and Japanese wireless carriers KDDI and NTT DoCoMo etc.) ‒ led by Google Inc.
and was initially released in September 23, 2008 under the Apache v2 open source license.
Android Architecture
LINUS KERNEL
Core part / heart of the android operating system ‒ developed by Linus Torvalds in 1991 ‒ which consists of drivers
(i.e., a well-defined set of instructions ‒ what we call programs or software written in C language that is installed
into mobile phones and stored in the form of files in the phone) ‒ that tells your mobile phone how to communicate
with its hardware components such as camera, display etc. ‒ without which keypad, Bluetooth, Audio, Wi-Fi,
Camera won’t work properly and it is responsible for Inter Process Communication (IPC: a mechanism which
allows applications running in different processes to share data and communicate with each other i.e., a mechanism
which allows an application running in a process to send requests and receive responses from an application running
in another process), Power management (conserves power in the expense of performance and holds the device not to
get to sleep state) and Memory management (make the best or most effective use of memory).
LIBRARIES
A collection of prewritten non-volatile data (written in C/ C++ language) and precompiled programming codes ‒
which support the well-functioning of android operating system.
Libraries include:
Surface Manager/ Screen manager (support the display screen)
OpenGL (Open Graphics Library) ‒ support 3Dimemsional graphics
183
SGL (Scalable Graphics Library) ‒ support 2Dimensional graphics
Media Framework ‒ support recording and playback of audio and video and image formats (MP3, JPG,
JPEG, PNG, GIF etc.)
Free Type ‒ responsible for font support (i.e., font size, color etc.)
SSL (Secured Sockets layer) / TLS (Transport Layer Security) ‒ responsible for internet security and
support network applications
WebKit ‒ support the display of web pages (i.e., support inbuilt browser)
SQLite ‒ responsible for storage of user data
Bionic ‒ standard C library WHICH supports embedded Linux based devices in mobile phones
Note 1:
Java source code is compiled into Java bytecode which is stored within .class file and the Java bytecode is read,
verified and executed by Java Virtual Machine (JVM). But in the case of Google’s Android operating system, DVM
(Dalvik Virtual Machine) is used instead of JVM because JVM is designed for desktops and it is too heavy for
mobile devices and moreover JVM takes more memory, runs and loads slower compared to DVM.
A software frame work (written in Java language) that supports the features of android applications
Application Frame Work includes:
Content Provider
Notifications Manager
184
Activity Manager
Window Manager
Location Manager
View manager
Package manager
Telephony manager
XMPP (Extensible Messaging and Presence Protocol)
Resource manager:
Content Provider
Data of applications (App 1, App 2 & App 3) are stored in database (which may be SQLite or Files etc.). If
application App 1 requests content provider for the data of the application App 2, then the content provider fetches
the data of the application App 2 and sends to App 1. Thus the data of App 2 is shared by App 1 THROUGH
Content provider.
Notifications Manager
Notifications Manager – display alerts and notifications (like low battery, you have got 2 messages, you have 2
missed calls etc.) to the user.
Activity Manager
If you open your mailbox application, you see number of activities such as inbox, sent, draft etc.
185
If you click on inbox, then another activity showing the list of inbox mails is opened.
And if you click on one of the inbox mail, then another activity showing the content of inbox mail is opened.
The activity manager manages and keeps the record of these activities.
Window Manager
Window Manager organizes the display screen for the application
the display screen for the video player application organized by Window Manager
Location Manager
Location Manager provides the periodic updates of the geographical location of the mobile device using GPS
(Global Positioning System which is a satellite-based navigation system) or cell tower.
View manager
Package manager
Package manager provide information about the list of installed apps in Android mobile device.
Telephony manager
Telephony manager provide information about the Telephony services (such as phone network, sim serial number,
IMEI number etc.).
186
XMPP
XMPP (Extensible Messaging and Presence Protocol) supports online chat application (like yahoo messenger etc.).
Resource manager
Where you can store all the non-code resources like images, graphics, videos, audios, animations, pictures that your
application might use as backgrounds etc. ‒ and you can upload these resources to your app.
Applications
Facebook Instagram
187
Answer:
Output on the screen:
a
System.out.println("m.charAt(8)");
Then the output on the screen is:
m.charAt(8)
If you want to enter the sentence through the keyboard, then the above program should take the form:
import java.util.Scanner;
public class HelloWorld {
public static void main(String [] args) {
String m;
Scanner in = new Scanner(System.in);
System.out.print("Enter the sentence: ");
m = in.nextLine();
System.out.println(m.charAt(8));
}
}
Output on the screen:
Enter the sentence:
If you enter the sentence: strings are immutable
Then
a
will be displayed on the screen.
Activities
If you open your phone application, you see number of activities such as received calls, dialed calls, missed calls etc.
If you click on received calls, then another activity (i.e., screen showing the list of received calls) is opened.
And if you click on one of the received call, then another activity showing the information about the received call
(such as the phone number of received call, the time at which it was received etc.) is opened. And if you want to
make a call, another activity showing the number keypad is opened.
Services
188
If you want the music to play in the background or if you want some video to be downloaded while you are
browsing over the internet ‒ services provide feasibility for the music to play in the background or video to be
downloaded while you are browsing over internet.
Broadcast Receivers
pop up notifications such as low battery, charging, Power got connected to the mobile device, Power got
disconnected from the mobile device, A headset was plugged in, A headset was plugged out.
Content Providers
If you type a request for the meaning of a word in the search engine of user dictionary application
User dictionary application sends the request to content resolver and the content resolver sends the request to the
content provider and the content provider fetches the information from the database and directs it to the content
provider and then from content provider to content resolver and finally from content resolver to user application.
Intent
When you press view photo, intent (message) is sent to the android operating system to open another
activity (i.e., activity 2) which display the photo
189
the application on a physical Android based mobile device) you need Android Virtual Device (AVD) to test whether
the application is compatible with a particular android mobile device configuration before installation of the app into
that mobile device.
XML
EXtensible (extendable) Markup (symbols and notations like <, >, / etc.) Language (which is both human and
machine understandable language) is a simple and very flexible text format designed to store and transport data
through internet.
HTML (Hyper Text Markup Language) = A text format designed to display data
Answer:
<note>
<to> people </to>
<from> steve jobs </from>
<message> Design is not just what it looks like and feels like. Design is how it works. </message>
</note>
Note:
If the statement
<message> Design is not just what it looks like and feels like. Design is how it works. </message>
is replaced by the statement
<Message> Design is not just what it looks like and feels like. Design is how it works. </message>
Then there will be no display of the output on the console screen.
<note>
…………………………………
………………………………….
…………………….
</note> is termed parent element
And
<to> people </to>
<from> steve jobs </from>
<message> Design is not just what it looks like and feels like. Design is how it works. </message> are termed child
elements
Book
Name of the book: Harry Potter
Author: J K. Rowling
190
Price: 255$
Pages: 296
Year: 2002
Edition: 8
Answer:
<Book>
<Name>:Harry Potter </Name>
<Author>: J K. Rowling </Author>
<Price>: 255$ </Price>
<Pages>: 296 </Pages>
<Year>: 2002</Year>
<Edition>: 8 </Edition>
</Book>
Note:
<Book>
<Name>: Harry Potter </Name>
<Author> J K. Rowling </Author>
<Price> 255$ </Price>
<rowling> <Pages> 296 </Pages></rowling>
<Year> 2002</Year>
<Edition> 8 </Edition>
</Book>
Note 1:
<rowling> <Pages> 296 </Pages></rowling> is termed child element and <Pages> 296 </Pages> is termed sub child
element.
“Well, Mr. Frankel, who started this program, began to suffer from the computer disease that anybody who works
with computers now knows about. It's a very serious disease and it interferes completely with the work. The trouble
with computers is you *play* with them. They are so wonderful. You have these switches - if it's an even number
you do this, if it's an odd number you do that - and pretty soon you can do more and more elaborate things if you are
clever enough, on one machine.
After a while the whole system broke down. Frankel wasn't paying any attention; he wasn't supervising anybody.
The system was going very, very slowly - while he was sitting in a room figuring out how to make one tabulator
automatically print arc-tangent X, and then it would start and it would print columns and then bitsi, bitsi, bitsi, and
calculate the arc-tangent automatically by integrating as it went along and make a whole table in one operation.
Absolutely useless. We *had* tables of arc-tangents. But if you've ever worked with computers, you understand the
disease - the *delight* in being able to see how much you can do. But he got the disease for the first time, the poor
fellow who invented the thing.”
― Richard Feynman, Surely You're Joking, Mr. Feynman!: Adventures of a Curious Character
There is one major step for getting started with Android operation:
You need to download java development kit i.e., JDK (jdk-8u91-windows-x64.exe) from the website
191
http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
And after downloading and installing it into your computer,
You need to download android studio (1.5.1 or 2.0) from the website
http://developer.android.com/sdk/index.html
And after downloading and installing it into your computer, if you try to open the studio – you will observe a popup
message stating that your JDK does not point to valid installation and your studio will be forcibly closed. For that
you need to follow the following steps:
Open control panel → then open System and Security→ then open System → then open Advanced system settings
→ click on Environment variables then a window
And restart the system → now open your studio → and follow the option
File → New → New project
And Create New Project window is opened and in create new project window you will see a list of things:
Application name:
Company domain:
192
Package name:
Project location:
Company domain: domain name which you prefer to be associated with your app to preserve its unique identity in
Google play store —without which you cannot generate a package name and without the package name you cannot
distribute your app in the official app store for Android smartphones and tablets or in the online android market like
Google play store.
In this case we just name the
Company domain as manju.example.com
Package name:
Since Company domain is manju.example.com and application name is Hello Android
Package name is:
com. example. manju. Helloandroid (which is autogenerated)
Project location: a file or folder on your hard drive where the newly created application will be stored.
In this case the above project will be stored in the C drive and the path of the project will be as follows:
C:\Users\Manju\AndroidStudioProjects\HelloAndroid
Once you have set the application name, company domain and project location, click on the "Next" button in the
lower right corner of the Create New Project window.
And then a window
Target Android devices
193
Will be opened
Because normally apps are installed into phones and smart phone tablets we select Phones and Tablets (instead of
TV, Glass , Android Auto and Wear). And under Phones and Tablets – we select minimum SDK (SDK means
software development kit): API 10: Android 2.3.3 (GingerBread) because we wish our app to run on approximately
100.00% of the devices that are active on the Android market. Selection of minimum SDK is very important
because
If you select minimum SDK:
API 15: Android 4.0.3 (IceCreamSandwich)
Then your app will run on only approximately 96.2% of the mobile devices that are active on the Google play store.
Suppose if you select minimum SDK:
API16: Android 4.1 (Jelly Bean)
Then your app will run on approximately 94.8% of the mobile devices that are active on the Google play store.
After selecting the minimum SDK --click on the "Next" button in the lower right corner of the Target Android
devices window.
And then a window -- add an activity to mobile -- will be opened
194
And you need to select an activity and click on the "Next" button in the lower right corner of the Add an activity to
mobile window.
In this case, we select blank activity
And then a window
Customize the activity
Will be opened
If you click on finish button -- a new window displaying .java and xml file will be opened displaying the text Hello
Android!
195
If you click on text button then 2 files
Main Activity.java
activity_main.xml
will be displayed on the screen.
And in activity_main.xml file
You see
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello Android!" />
196
If you replace the statement
android: textAppearance ="?android:attr/textAppearanceSmall"
by the statement
android: textAppearance ="?android:attr/textAppearanceMedium"
Then the font size of Hello Android! will be medium.
If you replace the statement
android: textAppearance ="?android:attr/textAppearanceSmall"
by the statement
android: textAppearance ="?android:attr/textAppearanceLarge"
Then the font size of Hello Android! will be large.
197
If you replace the statement
android:textStyle="bold"
by the statement
android:textStyle="italic"
Then the text
Hello Android!
will be in italic format
i.e.,
Hello Android!
Suppose if you replace the statement
android:textStyle="bold"
by the statement
android:textStyle="bold|italic"
Then the text
Hello Android!
Will appear as:
Hello Android!
198
If you replace
#33b5e5
by #33b565
i.e., if you replace the statement
android:textColor=”#33b5e5”
by the statement
android:textColor="#33b565"
Then the output on the screen is:
199
Suppose if you add the statement
android:layout_centerHorizontal="true"
after the statement
android:layout_height="wrap_content"
i.e.,
<TextView
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="Hello Android!"
android: textAppearance ="?android:attr/textAppearanceSmall"
android:textStyle="bold"
android:textColor="#33b5e5"
android:textSize="50sp"/>
Then the output on the screen is:
200
If you replace the statement
android:layout_centerHorizontal="true"
by the statement
android:layout_leftHorizontal="true"
Then the output on the screen is:
201
android:textColor="#33b5e5"
android:textSize="50sp"
/>
Then the output on the screen is:
<TextView
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="30dp”
android:text="Hello Android!"
android: textAppearance ="?android:attr/textAppearanceSmall"
android:textStyle="bold"
android:textColor="#33b5e5"
android:textSize="50sp"
/>
<TextView
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="60dp”
android:text="Hello!"
android: textAppearance ="?android:attr/textAppearanceLarge"
android:textStyle="bold|italic"
android:textColor="#33b575"
android:textSize="90sp"/>
Answer:
202
What is the difference between SQL and SQLite?
SQL (Structured Query Language) — a standard interactive and programming language for getting information
from a database
SQLite – database
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft ="true"
android:layout_marginTop="30dp"
android:text="Hello Android!"
android:textAppearance ="?android:attr/textAppearanceSmall"
android:textStyle="bold"
android:textColor="#33b5e5"
android:textSize="25sp"/>
is written instead of
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="30dp"
android:text="Hello Android!"
android:textAppearance ="?android:attr/textAppearanceSmall"
android:textStyle="bold"
android:textColor="#33b5e5"
android:textSize="25sp"/>
203
Note:
If you replace the statement
android:layout_centerHorizontal="true"
by the statement
android:layout_alignParentBottom ="true"
Then the text
Hello Android! on the screen will become invisible on the screen.
*********************************************************************************************
First you need to create a raw folder and for that you need to follow the following steps:
Open Android studio and you will see the following screen:
After clicking on ok button, a new folder named raw will be created and you can see it as shown in the figure below:
Now you copy the image (i.e., image_name.jpg) from the desktop and paste in the newly created folder (i.e., in raw
folder) and open .xml file and paste the following code:
205
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="@raw/image_name" />
If you want to drag the image downwards, then you have to add the statement
android:layout_marginTop="100dp"
after the statement
android:layout_height="wrap_content"
i.e.,
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="100dp"
android:src="@raw/image_name" />
206
Suppose if you have copied the image (i.e., image_name.jpg) from the desktop and pasted it in the drawable folder,
then you need to replace the statement
android:src="@raw/image_name"
by the statement
android:src="@drawable/image_name"
otherwise no image will be displayed on the screen (because you have saved the image in drawable folder not in the
raw folder).
Note:
Suppose if you copy the image from the desktop and paste it in the layout folder, then you have to replace the
statement
android:src="@raw/image_name"
by the statement
android:src="@layout/image_name"
image will be displayed on the screen but when you try to build / generate the .apk file (i.e., .Android application
package file), error will be displayed on the screen stating that
Build failed
The file must end with.xml
So please avoid saving the image in layout folder.
i.e.,
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginTop="100dp"
android:src="@raw/image_name" />
To drag the image to the center you need to add the following code:
android:layout_centerHorizontal="true"
i.e.,
207
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_centerHorizontal="true"
android:layout_marginTop="100dp"
android:src="@raw/image_name" />
*********************************************************************************************
<VideoView
android:id="@+id/videoView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:background="@android:color/transparent" />
</RelativeLayout>
and after replacing the above codes in activity_main .xml file, you need to replace the existing codes below package
name (i.e., com. example. manju. Helloandroid) in MainActivity.java by the following codes:
import android.graphics.PixelFormat;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.MediaController;
import android.widget.VideoView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button buttonPlayVideo2 = (Button) findViewById(R.id.button1);
getWindow().setFormat(PixelFormat.UNKNOWN);
208
//displays a video file
VideoView mVideoView2 = (VideoView) findViewById(R.id.videoView1);
String uriPath2 = "android.resource://com.example.manju.Helloandroid/" + R.raw.bvideo;
Uri uri2 = Uri.parse(uriPath2);
mVideoView2.setVideoURI(uri2);
mVideoView2.requestFocus();
mVideoView2.start();
buttonPlayVideo2.setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(View v) {
VideoView mVideoView2 = (VideoView) findViewById(R.id.videoView1);
// VideoView mVideoView = new VideoView(this);
String uriPath = "android.resource://com.example.manju.Helloandroid/" +
R.raw.video;
Uri uri2 = Uri.parse(uriPath);
mVideoView2.setVideoURI(uri2);
mVideoView2.requestFocus();
mVideoView2.start();
}
});
}
}
Then if you run the application -- video will be played on the emulator as shown in the figure below.
android:layout_width="wrap_content"
android:layout_height="wrap_content"
by the statements
android:layout_width="500px"
android:layout_height="500px"
209
Note:
If you replace the file video.mp4 in the raw folder by the file music.mp3, then you should rewrite the above codes
after the package name in .java file as follows:
import android.graphics.PixelFormat;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.MediaController;
import android.widget.VideoView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button buttonPlayVideo2 = (Button) findViewById(R.id.button1);
getWindow().setFormat(PixelFormat.UNKNOWN);
//displays a video file
VideoView mVideoView2 = (VideoView) findViewById(R.id.videoView1);
String uriPath2 = "android.resource://com.example.manju.helloandroid/" + R.raw.music;
Uri uri2 = Uri.parse(uriPath2);
mVideoView2.setVideoURI(uri2);
mVideoView2.requestFocus();
mVideoView2.start();
buttonPlayVideo2.setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(View v) {
VideoView mVideoView2 = (VideoView) findViewById(R.id.videoView1);
// VideoView mVideoView = new VideoView(this);
String uriPath = "android.resource://com.example.manju.helloandroid/" +
R.raw.music;
Uri uri2 = Uri.parse(uriPath);
mVideoView2.setVideoURI(uri2);
mVideoView2.requestFocus();
mVideoView2.start();
}
});
210
}
}
Note:
If you add the following code in .xml file:
<
ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="100dp"
android:src="@raw/image_name" />
Then the output on the screen is:
*********************************************************************************************
211
How to Create a second activity
First you need to replace the existing codes after the package name in Mainactivity.java file by the following codes:
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.content.Intent;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
{
Intent i = new Intent(MainActivity.this, Display.class);
startActivity(i);
}
}
}
And you need to replace the existing codes in activity_main. xml by the following codes:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.manju.Helloandroid.MainActivity">
<Button
android:layout_width="wrap_content"
212
android:layout_height="wrap_content"
android:text="Button1"
android:id="@+id/Bdisplay"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="177dp"
android:onClick="onButtonClick" />
</RelativeLayout>
And Go to packages and under packages select Main activity → right click on it → select New → and select Java
class
Then
And go to Layout and under layout select activity_main. xml and right click on it → select New → and select →
XmL → and select Layout xml file.
213
And you should place the following codes in Display.java file:
import android. app. Activity;
import android.os.Bundle;
/**
* Created by Manju on 3/17/2016.
*/
public class Display extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.display);
}
}
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Our new activity has started"
android:id="@+id/textView" />
</LinearLayout>
And you should add the following code in android manifest.xml file:
<activity android:name = ".Display"></activity>
i.e.,
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</manifest>
*****************************************************************************
214
Go to packages and under packages select Display.java → right click on it → select New → and select Java class
Then
And go to Layout and under layout select display. xml and right click on it → select New → and select → XmL →
and select Layout xml file.
/**
* Created by Manju on 3/21/2016.
215
*/
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Our new activity is running"
android:id="@+id/textView" />
</LinearLayout>
And you should add the following codes in android manifest.xml file:
i.e.,
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</manifest>
And you should open the Display.java file and rewrite the existing codes by the following codes:
216
/**
* Created by Manju on 3/17/2016.
*/
public class Display extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.display);
{
Intent i = new Intent(Display.this, File.class);
startActivity(i);
}
And you should open the display.xml file and rewrite the existing codes by the following codes:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button2"
android:id="@+id/Bfile"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="177dp"
android:onClick="onButtonClick" />
</LinearLayout>
217
Code that must be written in Mainactivity.java file
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.content.Intent;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
{
Intent i = new Intent(MainActivity.this, Display.class);
startActivity(i);
}
if (v.getId() == R.id.Bmanju)
{
Intent i = new Intent(MainActivity.this, Manju.class);
startActivity(i);
}
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="button 1"
android:id="@+id/Bdisplay"
android:onClick="onButtonClick"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="button 2"
android:id="@+id/Bmanju"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="177dp"
android:onClick="onButtonClick" />
218
</RelativeLayout>
And go to Mainactivity.java → right click on it → select New → and select Java class
Then
And again go to Mainactivity.java → right click on it → select New → and select Java class
Then
And go to Layout and under layout select main_activity. xml and right click on it → select New → and select →
XmL → and select Layout xml file.
219
And again go to Layout and under layout select main_activity. xml and right click on it → select New → and select
→ XmL → and select Layout xml file.
/**
* Created by Manju on 3/17/2016.
*/
public class Display extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.display);
}
}
</LinearLayout>
And in android manifest file you have to add the following codes:
<activity android:name = “.Display”></activity>
<activity android:name = “.Manju”></activity>
i.e.,
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
221
</application>
*****************************************************************************
Note:
In order to sell your app on Google play -- you need to generate signed apk file for that:
Then go to build → select generate signed apk→ then you will see
222
Then you see New key store window → then fill the details – for example
Note: always select Validity (years) > 25 years because in order to publish your app in Google play you need to
select minimum years of 25.
After filling the details you press OK → then you will see GENERATE SIGNED APK window will be opened →
press next → then you need to fill the master password (note: you need to remember master password because it is
only the evidence the Google play will verify whether you are going to publish your app or not) → after filling the
master password , then click on finish → after few minutes of Gradle building → you see the apk file in show
folder.
*****************************************************************************************
223
First you need to open the manifest file and add the statement
and you need to replace the existing codes in . xml file by the following codes:
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Browser"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="177dp"
android:onClick="browser1" />
</LinearLayout>
And you should modify the codes below the package name in MainActivity.java as follows:
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
224
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void browser1(View view){
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://google.com.kh"));
startActivity(browserIntent);
}
}
Suppose you want to add two buttons (i.e., if you click on button 1, Google website
should be opened and if you click on button 2, facebook website should be opened)
Then
import android.content.Intent;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void browser1(View view){
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://google.com.kh"));
startActivity(browserIntent);
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Browser"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="177dp"
android:onClick="browser1" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Browser2"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="130dp"
android:onClick="browser2" />
</LinearLayout>
*************************************************************************************************
and you need to replace the existing codes in activity_main. xml file by the following codes:
<Button
android:id="@+id/buttonCall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Call1"
android:layout_alignParentBottom="true"
android:layout_marginBottom="200dp"
android:onClick="call" />
<Button
android:id="@+id/buttonCall1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Call2"
android:layout_alignParentBottom="true"
android:layout_marginBottom="150dp"
android:onClick="call" />
</LinearLayout>
226
And you should modify the codes below the package name in MainActivity.java file as follows:
import android.content.Intent;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android. view. View.OnClickListener;
227
*******************************************************************************************
<Button
android:id="@+id/buttonSMS"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="sms"
android:layout_alignParentBottom="true"
android:layout_marginBottom="200dp"
android:onClick="SMS" />
And you should modify the codes below the package name in MainActivity.java file as follows:
import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android. view. View.OnClickListener;
}
}
Suppose you want to add two buttons (i.e., if you click on button 1, sms should be
sent to one number and if you click on button 2, sms should be sent to another number)
Then
228
Your .java file should take the form:
import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android. view. View.OnClickListener;
<Button
android:id="@+id/buttonSMS"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="sms"
android:layout_alignParentBottom="true"
android:layout_marginBottom="200dp"
android:onClick="SMS" />
<Button
android:id="@+id/buttonSMS1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="sms1"
android:layout_alignParentBottom="true"
android:layout_marginBottom="150dp"
android:onClick="SMS" />
229
**************************************************************************************
<Button
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_weight="1"
android:text="-"
android:textSize="8pt"
android:id="@+id/btnSub">
</Button>
<Button
android:layout_height="wrap_content"
android:layout_width="match_parent"
230
android:layout_weight="1"
android:text="*"
android:textSize="8pt"
android:id="@+id/btnMult">
</Button>
<Button
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_weight="1"
android:text="/"
android:textSize="8pt"
android:id="@+id/btnDiv">
</Button>
</LinearLayout>
<TextView
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_marginLeft="5pt"
android:layout_marginRight="5pt"
android:textSize="12pt"
android:layout_marginTop="3pt"
android:id="@+id/tvResult"
android:gravity="center_horizontal">
</TextView>
</LinearLayout>
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.os.Bundle;
import android.app.Activity;
import android.text.TextUtils;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
EditText etNum1;
EditText etNum2;
Button btnAdd;
Button btnSub;
Button btnMult;
Button btnDiv;
TextView tvResult;
// set a listener
btnAdd.setOnClickListener((OnClickListener) this);
btnSub.setOnClickListener(this);
btnMult.setOnClickListener(this);
btnDiv.setOnClickListener(this);
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
float num1 = 0;
float num2 = 0;
float result = 0;
// defines the button that has been clicked and performs the corresponding operation
// write operation into oper, we will use it later for output
switch (v.getId()) {
case R.id.btnAdd:
oper = "+";
result = num1 + num2;
break;
case R.id.btnSub:
oper = "-";
result = num1 - num2;
break;
case R.id.btnMult:
oper = "*";
result = num1 * num2;
break;
case R.id.btnDiv:
oper = "/";
result = num1 / num2;
break;
default:
break;
}
232
*********************************************************************************************
How to get location (latitude and longitude values) and city name?
Code in the MainActivity.java file:
import android.os.Bundle;
import android.app.Activity;
import java.io.IOException;
import java.util.List;
import java.util.Locale;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.ContentResolver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.location.Address;
import android.location.Geocoder;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.provider.Settings;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.Toast;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
233
.SCREEN_ORIENTATION_PORTRAIT);
pb = (ProgressBar) findViewById(R.id.progressBar1);
pb.setVisibility(View.INVISIBLE);
locationMangaer = (LocationManager)
getSystemService(Context.LOCATION_SERVICE);
@Override
public void onClick(View v) {
flag = displayGpsStatus();
if (flag) {
Log.v(TAG, "onClick");
pb.setVisibility(View.VISIBLE);
locationListener = new MyLocationListener();
locationMangaer.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 5000,
10,locationListener);
} else {
alertbox("Gps Status!!", "Your NETWORK is: OFF");
}
} else {
return false;
}
}
234
.setPositiveButton("network On",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// finish the current activity
// AlertBoxAdvance.this.finish();
Intent myIntent = new Intent(
Settings.ACTION_SECURITY_SETTINGS);
startActivity(myIntent);
dialog.cancel();
}
})
.setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// cancel the dialog box
dialog.cancel();
}
});
AlertDialog alert = builder.create();
alert.show();
}
editLocation.setText("");
pb.setVisibility(View.INVISIBLE);
Toast.makeText(getBaseContext(),"Location changed : Lat: " +
loc.getLatitude()+ " Lng: " + loc.getLongitude(),
Toast.LENGTH_SHORT).show();
String longitude = "Longitude: " +loc.getLongitude();
Log.v(TAG, longitude);
String latitude = "Latitude: " +loc.getLatitude();
Log.v(TAG, latitude);
String s = longitude+"\n"+latitude +
"\n\nCity name is: "+cityName;
editLocation.setText(s);
}
@Override
235
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onStatusChanged(String provider,
int status, Bundle extras) {
// TODO Auto-generated method stub
}
}
}
236
android:layout_height="wrap_content"
android:layout_weight="0.20"
android:layout_width="fill_parent"
android:gravity="center">
<ProgressBar
android:layout_width="wrap_content"
android:id="@+id/progressBar1"
android:layout_height="wrap_content"></ProgressBar>
</LinearLayout>
</LinearLayout>
Note:
Suppose if you want to add the clock and text time to your app then your .xml file should take the form:
<TextClock
android:layout_width="82dp"
android:layout_height="43dp"
android:id="@+id/textClock"
android:layout_gravity="center_horizontal" />
<AnalogClock
android:layout_width="100dp"
android:layout_height="100dp"
android:id="@+id/analogClock"
android:layout_gravity="center_horizontal"
android:layout_weight="0.20" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.33"
android:id="@+id/editTextLocation"
android:editable="false">
<requestFocus></requestFocus>
</EditText>
<LinearLayout
android:id="@+id/layButtonH"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:gravity="center"
android:layout_weight="0.15">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Get Location"
android:id="@+id/btnLocation"></Button>
</LinearLayout>
<LinearLayout
237
android:id="@+id/layloadingH"
android:layout_height="wrap_content"
android:layout_weight="0.20"
android:layout_width="fill_parent"
android:gravity="center">
<ProgressBar
android:layout_width="wrap_content"
android:id="@+id/progressBar1"
android:layout_height="wrap_content"></ProgressBar>
</LinearLayout>
</LinearLayout>
“As Android, iPhone and other mobile platforms grow, we are moving away from the page-based Internet. The new
Internet is app centric and often message-centric: Keith Teare”
How to get location and address line, country name, postal code etc.?
Code in MainActivity .java file
import android.os.Bundle;
import android.app.Activity;
import java.io.IOException;
import java.util.List;
import java.util.Locale;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.ContentResolver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.location.Address;
import android.location.Geocoder;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.provider.Settings;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.Toast;
@Override
public void onCreate(Bundle savedInstanceState) {
238
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
pb = (ProgressBar) findViewById(R.id.progressBar1);
pb.setVisibility(View.INVISIBLE);
locationMangaer = (LocationManager)
getSystemService(Context.LOCATION_SERVICE);
@Override
public void onClick(View v) {
flag = displayGpsStatus();
if (flag) {
Log.v(TAG, "onClick");
pb.setVisibility(View.VISIBLE);
locationListener = new MyLocationListener();
locationMangaer.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 5000,
10,locationListener);
} else {
alertbox("Gps Status!!", "Your NETWORK is: OFF");
}
} else {
return false;
}
}
239
public void onClick(DialogInterface dialog, int id) {
// finish the current activity
// AlertBoxAdvance.this.finish();
Intent myIntent = new Intent(
Settings.ACTION_SECURITY_SETTINGS);
startActivity(myIntent);
dialog.cancel();
}
})
.setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// cancel the dialog box
dialog.cancel();
}
});
AlertDialog alert = builder.create();
alert.show();
}
editLocation.setText("");
pb.setVisibility(View.INVISIBLE);
Toast.makeText(getBaseContext(),"Location changed : Lat: " +
loc.getLatitude()+ " Lng: " + loc.getLongitude(),
Toast.LENGTH_SHORT).show();
String longitude = "Longitude: " +loc.getLongitude();
Log.v(TAG, longitude);
String latitude = "Latitude: " +loc.getLatitude();
Log.v(TAG, latitude);
String s = longitude+"\n"+latitude +
"\n\n "+ L + "\n\n " + M + "\n\n " + N +"\n\n " + O + "\n\n "+ P +
"\n\n " + Q + "\n\n "+ A;
240
editLocation.setText(s);
}
@Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onStatusChanged(String provider,
int status, Bundle extras) {
// TODO Auto-generated method stub
}
}
}
*********************************************************************************************
import java.util.Calendar;
import java.util.Date;
import android.app.Activity;
import android.os.Bundle;
import android.text.InputType;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
Button btnCTime;
TextView txtCTime;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnCTime=(Button)findViewById(R.id.btnGenCurTime);
txtCTime=(TextView)findViewById(R.id.txtShowCurTime);
txtCTime.setInputType(InputType.TYPE_NULL);
btnCTime.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View vw) {
txtCTime.setText(new Date().toString());
}
});
}
}
241
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/txtShowCurTime"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<requestFocus />
</TextView>
<Button
android:id="@+id/btnGenCurTime"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="date" />
</LinearLayout>
*********************************************************************************************
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
242
Note: you have to download whatsapp application from the website: www.whatsapp.com and install it into your
phone – then the output on the screen is:
*********************************************************************************************
android:weightSum="1">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="whatsapp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="177dp"
android:onClick="browser1" />
</LinearLayout>
*********************************************************************************************
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.os.Bundle;
import android.app.Activity;
import android.text.TextUtils;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
EditText etNum1;
Button btnsqrt;
Button btncbrt;
Button btnln;
Button btnlog;
Button btnexp;
Button btnsin;
Button btncos;
Button btntan;
Button btnreci;
Button btncosec;
Button btnsec;
Button btncot;
Button btnsquare;
Button btncube;
Button btnfacto;
TextView tvResult;
244
tvResult = (TextView) findViewById(R.id.tvResult);
// set a listener
btnsqrt.setOnClickListener((OnClickListener) this);
btncbrt.setOnClickListener(this);
btnln.setOnClickListener(this);
btnlog.setOnClickListener(this);
btnexp.setOnClickListener(this);
btnsin.setOnClickListener(this);
btncos.setOnClickListener(this);
btntan.setOnClickListener(this);
btnreci.setOnClickListener(this);
btncosec.setOnClickListener(this);
btnsec.setOnClickListener(this);
btncot.setOnClickListener(this);
btnsquare.setOnClickListener(this);
btncube.setOnClickListener(this);
btnfacto.setOnClickListener(this);
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
double num1 = 0;
double result = 0;
// defines the button that has been clicked and performs the corresponding operation
// write operation into oper, we will use it later for output
switch (v.getId()) {
case R.id.btnsqrt:
oper = "sqrt";
result = Math.sqrt(num1) ;
break;
case R.id.btncbrt:
oper = "cbrt";
result = Math.cbrt(num1);
break;
case R.id.btnln:
oper = "ln";
result = Math.log(num1);
break;
case R.id.btnlog:
oper = "log";
result = Math.log10(num1);
break;
case R.id.btnexp:
oper = "exp";
result = Math.exp(num1);
break;
case R.id.btnsin:
oper = "sin";
result = Math.sin(num1);
break;
case R.id.btncos:
oper = "cos";
245
result = Math.cos(num1);
break;
case R.id.btntan:
oper = "tan";
result = Math.tan(num1);
break;
case R.id.btnreci:
oper = "1/x";
result = 1/num1;
break;
case R.id.btncosec:
oper = "cosec";
result = 1/Math.sin(num1);
break;
case R.id.btnsec:
oper = "sec";
result = 1/ Math.cos(num1);
break;
case R.id.btncot:
oper = "cot";
result = 1/Math.tan(num1);
break;
case R.id.btnsquare:
oper = "square";
result = num1 * num1;
break;
case R.id.btncube:
oper = "cube";
result = num1 * num1 * num1;
break;
case R.id.btnfacto:
oper = "fact";
int i, fact =1;
for(i=1;i<=num1;i++)
fact = fact *i;
result = fact;
break;
default:
break;
}
<Button
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_weight="1"
android:text="sqrt"
android:textSize="8pt"
android:id="@+id/btnsqrt">
</Button>
<Button
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_weight="1"
android:text="cbrt"
android:textSize="8pt"
android:id="@+id/btncbrt">
</Button>
<Button
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_weight="1"
android:text="ln"
android:textSize="8pt"
android:id="@+id/btnln">
</Button>
<Button
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_weight="1"
android:text="log"
android:textSize="8pt"
android:id="@+id/btnlog">
</Button>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/linearLayout2"
android:layout_marginTop="3pt"
android:layout_marginLeft="5pt"
android:layout_marginRight="5pt">
<Button
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_weight="1"
android:text="exp"
android:textSize="8pt"
android:id="@+id/btnexp">
247
</Button>
<Button
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_weight="1"
android:text="sin"
android:textSize="8pt"
android:id="@+id/btnsin">
</Button>
<Button
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_weight="1"
android:text="cos"
android:textSize="8pt"
android:id="@+id/btncos">
</Button>
<Button
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_weight="1"
android:text="tan"
android:textSize="8pt"
android:id="@+id/btntan">
</Button>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/linearLayout2"
android:layout_marginTop="3pt"
android:layout_marginLeft="5pt"
android:layout_marginRight="5pt">
<Button
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_weight="1"
android:text="1/x"
android:textSize="8pt"
android:id="@+id/btnreci">
</Button>
<Button
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_weight="1"
android:text="cosec"
android:textSize="8pt"
android:id="@+id/btncosec">
</Button>
<Button
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_weight="1"
android:text="sec"
android:textSize="8pt"
android:id="@+id/btnsec">
</Button>
<Button
248
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_weight="1"
android:text="cot"
android:textSize="8pt"
android:id="@+id/btncot">
</Button>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/linearLayout2"
android:layout_marginTop="3pt"
android:layout_marginLeft="5pt"
android:layout_marginRight="5pt">
<Button
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_weight="1"
android:text="square"
android:textSize="8pt"
android:id="@+id/btnsquare">
</Button>
<Button
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_weight="1"
android:text="cube"
android:textSize="8pt"
android:id="@+id/btncube">
</Button>
<Button
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_weight="1"
android:text="factorial"
android:textSize="8pt"
android:id="@+id/btnfacto">
</Button>
</LinearLayout>
*********************************************************************************************
How to get Information about model number, API level, android version etc.
Code in MainActivity.java file:
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.Html;
import android.widget.TextView;
TextView text;
249
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ModelNumber = android.os.Build.MODEL;
Board = android.os.Build.BOARD;
Brand = android.os.Build.BRAND;
Display = android.os.Build.DISPLAY;
FingerPrint = android.os.Build.FINGERPRINT;
ID = android.os.Build.ID;
TAGS = android.os.Build.TAGS;
Type = android.os.Build.TYPE;
AndroidVersion = android.os.Build.VERSION.RELEASE;
APILevel = android.os.Build.VERSION.SDK;
CodeName = android.os.Build.VERSION.CODENAME;
INCREMENTAL = android.os.Build.VERSION.INCREMENTAL;
text.setText(Html.fromHtml("Phone Type" +
"<br/><br/><font color = 'red';>Model Number : </font></font>" + ModelNumber
+ "<br/><font color = 'red';>Board : </font>" + Board
+ "<br/><font color = 'red';>Brand : </font>" + Brand
+ "<br/><font color = 'red';>Display : </font>" + Display
+ "<br/><font color = 'red';>FingerPrint : </font>" + FingerPrint
+ "<br/><font color = 'red';>ID : </font>" + ID
+ "<br/><font color = 'red';>TAGS : </font>" + TAGS
+ "<br/><font color = 'red';>Type : </font>" + Type
+ "<br/>"
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/textView2"
android:textColor="#4169E1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10sp"
android:layout_marginTop="20sp" />
</RelativeLayout>
*********************************************************************************************
How to take a photo and save it in gallery / SD card / image file in android
phone ?
250
Code in MainActivity.java file:
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imgView = (ImageView) findViewById(R.id.imageView1);
btnCamera = (Button) findViewById(R.id.btn_camera);
btnCamera.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
// ******** code for take image
intent.putExtra(MediaStore.EXTRA_OUTPUT,
MediaStore.Images.Media.EXTERNAL_CONTENT_URI.toString());
try {
intent.putExtra("return-data", true);
startActivityForResult(intent, CAMERA_REQUEST);
} catch (ActivityNotFoundException e) {
// Do nothing for now
}
}
});
}
}
251
Code in activity_main.XML file:
<Button
android:id="@+id/btn_camera"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Take image" />
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
</LinearLayout>
*********************************************************************************************
IEMI number
Code in MainActivity.java file:
import android.content.Context;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.telephony.TelephonyManager;
import android.widget.TextView;
TelephonyManager tel;
TextView imei;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
252
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="50dp"
android:textColor="#4169E1"
android:textSize="18sp"
android:text="IMEI Number" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:textSize="15sp"
android:text="IMEI" />
</RelativeLayout>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
******************************************************************************************
Gallery Creation
Code in MainActivity.java file:
import android.content.Context;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.animation.AnimationUtils;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageSwitcher;
import android.widget.ImageView;
import android.widget.ViewSwitcher.ViewFactory;
int imgs[] =
{
R.drawable.image_name,
R.drawable.image_name1,
};
ImageSwitcher imgSwitcher;
253
imgSwitcher.setInAnimation(AnimationUtils.loadAnimation(this,
android.R.anim.fade_in));
imgSwitcher.setOutAnimation(AnimationUtils.loadAnimation(this,
android.R.anim.fade_out));
gallery.setOnItemClickListener(new OnItemClickListener() {
public ImageAdapter(Context c) {
ctx = c;
}
return imgs.length;
}
return arg0;
}
return arg0;
}
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
254
<Gallery
android:id="@+id/gallery1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true" />
<ImageSwitcher
android:id="@+id/imageSwitcher1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@+id/gallery1"
android:layout_centerHorizontal="true"
android:layout_marginTop="5dp" >
</ImageSwitcher>
</RelativeLayout>
*********************************************************************************************
import android.graphics.Typeface;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.Html;
import android.widget.TextView;
Typeface weatherFont;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getSupportActionBar().hide();
setContentView(R.layout.activity_main);
weatherFont = Typeface.createFromAsset(getApplicationContext().getAssets(),
"fonts/weathericons-regular-webfont.ttf");
cityField = (TextView)findViewById(R.id.city_field);
updatedField = (TextView)findViewById(R.id.updated_field);
detailsField = (TextView)findViewById(R.id.details_field);
currentTemperatureField = (TextView)findViewById(R.id.current_temperature_field);
humidity_field = (TextView)findViewById(R.id.humidity_field);
pressure_field = (TextView)findViewById(R.id.pressure_field);
weatherIcon = (TextView)findViewById(R.id.weather_icon);
weatherIcon.setTypeface(weatherFont);
cityField.setText(weather_city);
updatedField.setText(weather_updatedOn);
255
detailsField.setText(weather_description);
currentTemperatureField.setText(weather_temperature);
humidity_field.setText("Humidity: "+weather_humidity);
pressure_field.setText("Pressure: "+weather_pressure);
weatherIcon.setText(Html.fromHtml(weather_iconText));
}
});
asyncTask.execute(
"25.223666 ", "-12.3669858"); // asyncTask.execute("Latitude", "Longitude")
import android.app.Activity;
import android.os.AsyncTask;
import android.util.Log;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.text.DateFormat;
import java.util.Date;
import java.util.Locale;
256
break;
case 6 : icon = "";
break;
case 5 : icon = "";
break;
}
}
return icon;
}
void processFinish(String output1, String output2, String output3, String output4, String
output5, String output6, String output7, String output8);
}
@Override
protected JSONObject doInBackground(String... params) {
return jsonWeather;
}
@Override
protected void onPostExecute(JSONObject json) {
try {
if(json != null){
JSONObject details = json.getJSONArray("weather").getJSONObject(0);
JSONObject main = json.getJSONObject("main");
DateFormat df = DateFormat.getDateTimeInstance();
String city = json.getString("name").toUpperCase(Locale.US) + ", " +
json.getJSONObject("sys").getString("country");
String description = details.getString("description").toUpperCase(Locale.US);
String temperature = String.format("%.2f", main.getDouble("temp"))+ "°";
String humidity = main.getString("humidity") + "%";
String pressure = main.getString("pressure") + " hPa";
String updatedOn = df.format(new Date(json.getLong("dt")*1000));
String iconText = setWeatherIcon(details.getInt("id"),
json.getJSONObject("sys").getLong("sunrise") * 1000,
json.getJSONObject("sys").getLong("sunset") * 1000);
}
} catch (JSONException e) {
//Log.e(LOG_TAG, "Cannot process JSON results", e);
}
257
}
}
connection.addRequestProperty("x-api-key", OPEN_WEATHER_MAP_API);
return data;
}catch(Exception e){
return null;
}
}
<?xml version="1.0"?>
<RelativeLayout
android:padding="20dp"
android:background="#3F51B5"
android:layout_height="match_parent"
android:layout_width="match_parent"
xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android">
<TextView android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#FFFFFF"
android:layout_centerHorizontal="true"
android:layout_alignParentTop="true"
android:id="@+id/city_field"/>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#FFFFFF"
258
android:layout_centerHorizontal="true"
android:id="@+id/updated_field"
android:textSize="13sp"
android:layout_below="@+id/city_field"/>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#FFFFFF"
android:layout_centerHorizontal="true"
android:id="@+id/weather_icon"
android:textSize="90sp"
android:layout_centerVertical="true"/>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#FFFFFF"
android:layout_centerHorizontal="true"
android:id="@+id/current_temperature_field"
android:textSize="50sp"
android:layout_alignParentBottom="true"/>
<TextView android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#FFFFFF"
android:layout_centerHorizontal="true"
android:id="@+id/details_field"
android:layout_below="@+id/weather_icon"/>
<TextView android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#FFFFFF"
android:layout_centerHorizontal="true"
android:id="@+id/humidity_field"
android:layout_below="@+id/details_field"/>
<TextView android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#FFFFFF"
android:layout_centerHorizontal="true"
android:id="@+id/pressure_field"
android:layout_below="@+id/humidity_field"/>
</RelativeLayout>
<uses-permission android:name="android.permission.INTERNET"/>
<application android:theme="@style/AppTheme"
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:allowBackup="true">
<activity
android:name=".MainActivity"
android:label="@string/app_name">
259
<intent-filter>
<action
android:name="android.intent.action.MAIN"/>
<category
android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
*********************************************************************************************
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
Button b1,b2;
EditText ed1,ed2;
TextView tx1;
int counter = 3;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b1=(Button)findViewById(R.id.button);
ed1=(EditText)findViewById(R.id.editText);
ed2=(EditText)findViewById(R.id.editText2);
b2=(Button)findViewById(R.id.button2);
tx1=(TextView)findViewById(R.id.textView3);
tx1.setVisibility(View.GONE);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(ed1.getText().toString().equals("admin") &&
260
ed2.getText().toString().equals("admin")) {
Toast.makeText(getApplicationContext(),
"Redirecting...",Toast.LENGTH_SHORT).show();
else{
Toast.makeText(getApplicationContext(), "Wrong
Credentials",Toast.LENGTH_SHORT).show();
tx1.setVisibility(View.VISIBLE);
tx1.setBackgroundColor(Color.RED);
counter--;
tx1.setText(Integer.toString(counter));
if (counter == 0) {
b1.setEnabled(false);
}
}
}
});
b2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
Display.java:
activity_main.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tutorials point"
android:id="@+id/textView"
android:layout_below="@+id/textview"
android:layout_centerHorizontal="true"
android:textColor="#ff7aff24"
android:textSize="35dp" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/editText"
android:hint="Enter Name"
android:focusable="true"
android:textColorHighlight="#ff7eff15"
android:textColorHint="#ffff25e6"
android:layout_marginTop="46dp"
android:layout_below="@+id/imageView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView"
android:src="@drawable/ic_launcher"
android:layout_below="@+id/textView"
android:layout_centerHorizontal="true" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:ems="10"
android:id="@+id/editText2"
android:layout_below="@+id/editText"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignRight="@+id/editText"
262
android:layout_alignEnd="@+id/editText"
android:textColorHint="#ffff299f"
android:hint="Password" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Attempts Left:"
android:id="@+id/textView2"
android:layout_below="@+id/editText2"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textSize="25dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Text"
android:id="@+id/textView3"
android:layout_alignTop="@+id/textView2"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignBottom="@+id/textView2"
android:layout_toEndOf="@+id/textview"
android:textSize="25dp"
android:layout_toRightOf="@+id/textview" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="login"
android:id="@+id/button"
android:layout_alignParentBottom="true"
android:layout_toLeftOf="@+id/textview"
android:layout_toStartOf="@+id/textview"
android:onClick="onClick"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cancel"
android:id="@+id/button2"
android:layout_alignParentBottom="true"
android:layout_toRightOf="@+id/textview"
android:layout_toEndOf="@+id/textview" />
</RelativeLayout>
display.xml:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Our new activity has started"
263
android:id="@+id/textView" />
</LinearLayout>
String.xml file:
<resources>
<string name="action_settings">Settings</string>
<string name="hello_world">Hello world!</string>
</resources>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</application>
</manifest>
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
@Override
protected void onCreate(Bundle savedInstanceState) {
264
super.onCreate(savedInstanceState);
setContentView(R.layout.display);
}
public void logout(View view){
Intent i = new Intent(Display.this, MainActivity.class);
startActivity(i);
}
display.xml:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".Display" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="146dp"
android:onClick="logout"
android:text="logout" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/button1"
android:layout_alignParentTop="true"
android:layout_marginTop="64dp"
android:text="welcome"
android:textAppearance="?android:attr/textAppearanceLarge" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/button1"
android:layout_centerHorizontal="true"
android:layout_marginTop="43dp"
android:onClick="exit"
android:text="exit" />
</RelativeLayout>
*********************************************************************************************
265
MainActivity.java:
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setTitle("Current Weather");
cityNameSearch.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
cityNameProgress.setVisibility(View.VISIBLE);
String cityNameQuery = cityName.getText().toString();
if(cityNameQuery.length() > 0) {
WeatherDownloader downloader = new WeatherDownloader(MainActivity.this,
WeatherDownloader.Mode.CITYNAME);
downloader.getCurrentWeatherData(getResources().getString(R.string.weather_api_key),
cityNameQuery);
}
}
});
cityIdSearch.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
266
cityIdProgress.setVisibility(View.VISIBLE);
String cityIdQuery = cityId.getText().toString();
if(cityIdQuery.length() > 0) {
WeatherDownloader downloader = new WeatherDownloader(MainActivity.this,
WeatherDownloader.Mode.CITYID);
downloader.getCurrentWeatherData(getResources().getString(R.string.weather_api_key),
cityIdQuery);
}
}
});
coordinatesSearch.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
coordinatesProgress.setVisibility(View.VISIBLE);
String coordinatesQuery = coordinates.getText().toString();
if(coordinatesQuery.length() > 0) {
WeatherDownloader downloader = new WeatherDownloader(MainActivity.this,
WeatherDownloader.Mode.COORDINATES);
downloader.getCurrentWeatherData(getResources().getString(R.string.weather_api_key),
coordinatesQuery);
}
}
});
zipCodeSearch.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
zipCodeProgress.setVisibility(View.VISIBLE);
String zipCodeQuery = zipCode.getText().toString();
if(zipCodeQuery.length() > 0) {
WeatherDownloader downloader = new WeatherDownloader(MainActivity.this,
WeatherDownloader.Mode.ZIPCODE);
downloader.getCurrentWeatherData(getResources().getString(R.string.weather_api_key),
zipCodeQuery);
}
}
});
@Override
public void onWeatherDownloadComplete(WeatherData data, WeatherDownloader.Mode mode) {
if (mode == WeatherDownloader.Mode.CITYNAME) {
cityNameProgress.setVisibility(View.GONE);
cityNameResult.setText(String.format("%.2f",
WeatherUnits.convertToCelsius(data.getMain().getTemp())));
} else if (mode == WeatherDownloader.Mode.CITYID) {
cityIdProgress.setVisibility(View.GONE);
cityIdResult.setText(String.format("%.2f",
WeatherUnits.convertToFahrenheit(data.getMain().getTemp())));
} else if (mode == WeatherDownloader.Mode.COORDINATES) {
coordinatesProgress.setVisibility(View.GONE);
coordinatesResult.setText(data.getMain().getTemp());
} else if (mode == WeatherDownloader.Mode.ZIPCODE) {
zipCodeProgress.setVisibility(View.GONE);
zipCodeResult.setText(String.format("%.2f",
WeatherUnits.convertToFahrenheit(data.getMain().getTemp())));
}
}
@Override
267
public void onWeatherDownloadFailed(Exception e) {
Toast.makeText(MainActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show();
}
}
Clouds.java:
@Override
public String toString() {
return "Clouds[all = "+all+"]";
}
}
Coord.java:
@Override
public String toString() {
return "Coord [lon = "+lon+", lat = "+lat+"]";
}
}
JsonUtil.java:
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
268
public class JsonUtil {
public static Coord getCoordObjectFromJson(String json) throws JSONException {
JSONObject jsonObject = new JSONObject(json);
JSONObject coordJson = jsonObject.getJSONObject("coord");
if(coordJson != null) {
Coord coord = new Coord();
coord.setLon(coordJson.getString("lon"));
coord.setLat(coordJson.getString("lat"));
return coord;
} else {
return null;
}
}
269
}
Main.java:
270
}
@Override
public String toString() {
return "Main [humidity = "+humidity+", pressure = "+pressure+", temp_max = "+temp_max+",
temp_min = "+temp_min+", temp = "+temp+"]";
}
}
Rain.java:
Sys.java:
271
public String getSunset () {
return sunset;
}
@Override
public String toString() {
return "Sys [message = "+message+", id = "+id+", sunset = "+sunset+", sunrise =
"+sunrise+", type = "+type+", country = "+country+"]";
}
}
Weather.java:
@Override
public String toString() {
return "Weather [id = "+id+", icon = "+icon+", description = "+description+", main =
"+main+"]";
}
}
WeatherData.java:
import java.util.Arrays;
274
return base;
}
@Override
public String toString() {
return "WeatherData [id = "+id+", dt = "+dt+", clouds = "+clouds+", coord = "+coord+",
wind = "+wind+", cod = "+cod+", visibility = "+visibility+", sys = "+sys+", name = "+name+", base
= "+base+", weather = "+ Arrays.toString(weather) +", main = "+main+"]";
}
}
WeatherDataBuilder.java:
import android.util.Log;
import org.json.JSONException;
import org.json.JSONObject;
275
weatherData.setClouds(cloudsData);
} catch (JSONException e) {
Log.e(LOG_TAG, e.getMessage());
weatherData.setClouds(cloudsData);
}
try {
weatherData.setBase(jsonObject.getString("base"));
} catch (JSONException e) {
Log.e(LOG_TAG, e.getMessage());
weatherData.setBase(null);
}
try {
weatherData.setVisibility(jsonObject.getString("visibility"));
} catch (JSONException e) {
Log.e(LOG_TAG, e.getMessage());
weatherData.setVisibility(null);
}
276
try {
weatherData.setDt(jsonObject.getString("dt"));
} catch (JSONException e) {
Log.e(LOG_TAG, e.getMessage());
weatherData.setDt(null);
}
try {
weatherData.setId(jsonObject.getString("id"));
} catch (JSONException e) {
Log.e(LOG_TAG, e.getMessage());
weatherData.setId(null);
}
try {
weatherData.setName(jsonObject.getString("name"));
} catch (JSONException e) {
Log.e(LOG_TAG, e.getMessage());
weatherData.setName(null);
}
try {
weatherData.setCod(jsonObject.getString("cod"));
} catch (JSONException e) {
Log.e(LOG_TAG, e.getMessage());
weatherData.setCod(null);
}
return weatherData;
}
}
WeatherDownloader.java:
import android.net.Uri;
import android.os.AsyncTask;
import android.util.Log;
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
277
String url = buildUrl(apiKey, mode, query);
new DownloadCurrentData().execute(url);
} catch (Exception e) {
Log.e(LOG_TAG, e.getMessage());
}
} else {
Log.e(LOG_TAG, "ApiKey cannot be null");
}
}
278
}
} catch (IOException e) {
Log.e(LOG_TAG, e.getMessage());
}
}
return null;
}
@Override
protected void onPostExecute(String response) {
if(response == null){
Log.e(LOG_TAG, "Response is null");
downloadListener.onWeatherDownloadComplete(null, mode);
} else {
try {
downloadListener.onWeatherDownloadComplete(WeatherDataBuilder.buildWeatherData(response), mode);
} catch (Exception e) {
Log.e(LOG_TAG, "Invalid data");
downloadListener.onWeatherDownloadFailed(e);
}
}
}
WeatherUnits.java:
279
}
return (inKelvin - 273.15)* 1.8000 + 32.00;
}
}
Wind.java:
@Override
public String toString() {
return "Wind [speed = "+speed+", deg = "+deg+"]";
}
}
activity_main.xml:
<LinearLayout tools:context=".MainActivity"
android:orientation="vertical"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
android:layout_height="match_parent"
android:layout_width="match_parent"
xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android">
<TextView android:layout_height="wrap_content"
android:layout_width="0dp"
android:text="Search by name"
android:layout_weight="1"/>
<EditText android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="1"
280
android:inputType="textAutoCorrect"
android:hint="city name"
android:id="@+id/city_name"/>
</LinearLayout>
<TextView android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="1"
android:id="@+id/city_result"/>
<ProgressBar android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/city_progress"
android:indeterminate="true"
android:visibility="gone"/>
<Button android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Get Current Weather"
android:id="@+id/city_search"/>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Celsius" />
<TextView android:layout_height="wrap_content"
android:layout_width="0dp"
android:text="Search by zip code"
android:layout_weight="1"/>
<EditText android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="1"
android:inputType="number"
android:hint="zip code"
android:id="@+id/zip_code"/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_height="wrap_content"
android:layout_width="match_parent">
<TextView android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="1"
android:id="@+id/zip_code_result"/>
281
android:indeterminate="true"
android:visibility="gone"/>
<Button android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Get Current Weather"
android:id="@+id/zip_code_search"
android:layout_gravity="end"/>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Fahrenheit" />
<TextView android:layout_height="wrap_content"
android:layout_width="0dp"
android:text="Search by coordinates"
android:layout_weight="1"/>
<EditText android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="1"
android:inputType="text"
android:hint="lat:lon"
android:id="@+id/coordinates"/>
</LinearLayout>
<TextView android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="1"
android:id="@+id/coordinates_result"/>
<Button android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Get Current Weather"
android:id="@+id/coordinates_search"
android:layout_gravity="end"/>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Kelvin" />
282
<TextView android:layout_height="wrap_content"
android:layout_width="0dp"
android:text="Search by City ID"
android:layout_weight="1"/>
<EditText android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="1"
android:inputType="text"
android:hint="city id"
android:id="@+id/city_id"/>
</LinearLayout>
<TextView android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="1"
android:id="@+id/city_id_result"/>
<Button android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Get Current Weather"
android:id="@+id/city_id_search"
android:layout_gravity="end"/>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Fahrenheit" />
</LinearLayout>
<string name="weather_api_key">16f28aecfde1858cd9bda7e9444e54e8</string>
</resources>
<uses-permission android:name="android.permission.INTERNET"/>
283
******************************************************************************************
import android.content.Context;
import android.hardware.GeomagneticField;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.location.Location;
import android.location.LocationManager;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.WindowManager;
import android.widget.TextView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textDirection = (TextView) findViewById(R.id.text);
compassView = (CompassView) findViewById(R.id.compass);
// keep screen light on (wake lock light)
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}
@Override
protected void onStart() {
super.onStart();
sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
sensorGravity = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
284
sensorMagnetic = sensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
@Override
public void onSensorChanged(SensorEvent event) {
boolean accelOrMagnetic = false;
if (accelOrMagnetic) {
compassView.postInvalidate();
}
285
if (range == 15 || range == 0)
dirTxt = "N";
if (range == 1 || range == 2)
dirTxt = "NE";
if (range == 3 || range == 4)
dirTxt = "E";
if (range == 5 || range == 6)
dirTxt = "SE";
if (range == 7 || range == 8)
dirTxt = "S";
if (range == 9 || range == 10)
dirTxt = "SW";
if (range == 11 || range == 12)
dirTxt = "W";
if (range == 13 || range == 14)
dirTxt = "NW";
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
if (sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD
&& accuracy == SensorManager.SENSOR_STATUS_UNRELIABLE) {
// manage fact that compass data are unreliable ...
// toast ? display on screen ?
}
}
}
CompassView.java:
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;
286
bitmap = BitmapFactory.decodeResource(getResources(),
R.drawable.compass_icon);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
width = MeasureSpec.getSize(widthMeasureSpec);
height = MeasureSpec.getSize(heightMeasureSpec);
setMeasuredDimension(width, height);
}
@Override
protected void onDraw(Canvas canvas) {
int bitmapWidth = bitmap.getWidth();
int bitmapHeight = bitmap.getHeight();
int canvasWidth = canvas.getWidth();
int canvasHeight = canvas.getHeight();
// center
int bitmapX = bitmap.getWidth() / 2;
int bitmapY = bitmap.getHeight() / 2;
int parentX = width / 2;
int parentY = height / 2;
int centerX = parentX - bitmapX;
int centerY = parentY - bitmapY;
// reset matrix
matrix.reset();
matrix.setRotate(rotation, bitmapX, bitmapY);
// center bitmap on canvas
matrix.postTranslate(centerX, centerY);
// draw bitmap
canvas.drawBitmap(bitmap, matrix, paint);
}
LowPassFilter.java:
287
}
return output;
activity_main.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="manju.example.com.myapplicationcompass.MainActivity" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp" >
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:textSize="@dimen/dirSize" />
</RelativeLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dp"
android:orientation="horizontal" >
</LinearLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<manju.example.com.myapplicationcompass.CompassView
android:id="@+id/compass"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerInParent="true" />
</RelativeLayout>
</LinearLayout>
288
<uses-feature
android:name ="android.hardware.sensor.accelerometer"
android:required ="true"/>
<uses-feature
android:name ="android.hardware.sensor.compass"
android:required ="true"/>
<dimen name="dirSize">32dp</dimen>
******************************************************************************************
import android.app.DownloadManager;
import android.app.DownloadManager.Query;
import android.app.DownloadManager.Request;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
289
registerReceiver(receiver, new IntentFilter(
DownloadManager.ACTION_DOWNLOAD_COMPLETE));
}
<uses-permission android:name="android.permission.INTERNET"/>
activity_main.xml:
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Next"
android:id="@+id/button"
android:layout_gravity="center_horizontal" />
</LinearLayout>
*********************************************************************************************
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
290
import android.view.Menu;
import android.view.View;
import android.widget.ImageView;
activity_main.xml:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="98dp"
android:layout_marginTop="139dp"
android:onClick="open"
android:src="@drawable/ic_launcher" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="48dp"
android:text="@string/tap"
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>
String.xml:
291
<resources>
<string name="hello_world">Hello world!</string>
<string name="tap">Tap the button to share something</string>
</resources>
<uses-permission android:name="android.permission.INTERNET"/>
*****************************************************************************************
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.View;
import java.io.File;
import java.io.IOException;
import android.media.MediaPlayer;
import android.media.MediaRecorder;
import android.os.Bundle;
import android.os.Environment;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
292
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace(); }
start.setEnabled(false);
stop.setEnabled(true);
Toast.makeText(getApplicationContext(),
"Recording started", Toast.LENGTH_LONG).show();
}
public void stop(View view){
myAudioRecorder.stop();
myAudioRecorder.release();
myAudioRecorder = null;
stop.setEnabled(false);
play.setEnabled(true);
Toast.makeText(getApplicationContext(),
"Audio recorded successfully",
Toast.LENGTH_LONG).show(); }
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true; }
public void play(View view) throws IllegalArgumentException,
SecurityException, IllegalStateException, IOException{
MediaPlayer m = new MediaPlayer();
m.setDataSource(outputFile);
m.prepare();
m.start();
Toast.makeText(getApplicationContext(), "Playing audio", Toast.LENGTH_LONG).show();
}
}
activity_main.xml:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginTop="32dp"
android:text="@string/Recording"
android:textAppearance="?android:attr/textAppearanceMedium" />
<ImageView
android:id="@+id/imageView1"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_below="@+id/textView1"
android:layout_centerHorizontal="true"
android:layout_marginTop="37dp"
293
android:scaleType="fitXY"
android:src="@android:drawable/presence_audio_online" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/imageView1"
android:layout_marginTop="67dp"
android:layout_toLeftOf="@+id/imageView1"
android:onClick="start"
android:text="@string/start" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/button1"
android:layout_alignBottom="@+id/button1"
android:layout_alignRight="@+id/textView1"
android:layout_marginRight="40dp"
android:onClick="stop"
android:text="@string/stop" />
<Button
android:id="@+id/button3"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/button2"
android:layout_centerHorizontal="true"
android:onClick="play"
android:text="@string/play" />
</RelativeLayout>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.RECORD_AUDIO" />
String.xml:
<resources>
<string name="Recording">Android Audio Recording Application</string>
<string name="start">start</string>
<string name="stop">stop</string>
<string name="play">play</string>
</resources>
********************************************************************************************
Google Map
First you need to update Google play services
294
After Gradle build, open Google_maps_api.xml in layout folder and note Finger print and package name i.e.,
Google_maps_api.xml
<!--
TODO: Before you run your application, you need a Google Maps API key.
To get one, follow this link, follow the directions and press "Create" at the end:
https://console.developers.google.com/flows/enableapi?apiid=maps_android_backend&keyTy
pe=CLIENT_SIDE_ANDROID&r=A0:4D:F6:41:65:95:F3:59:F7:E1:03:24:44:56:26:87:C8:ED:37:6C%3
Bcom.example.manju.myapplication
You can also add your credentials to an existing key, using this line:
A0:4D:F6:41:65:95:F3:59:F7:E1:03:24:44:56:26:87:C8:ED:37:6C;com.example.manju.myapplic
ation
Once you have your key (it starts with "AIza"), replace the "google_maps_key"
string in this file.
-->
https://code.google.com/apis/console/?pli=1
Then go to CREATE PROJECT → New Project (enter project name) → create → Under API Manager → go to
Credentials → APIs Credentials → API key → Android key → Add package name and finger print → fill package
name and finger print → create → Note down your API key
295
After noting down the API key—you need to enter it in the Manifest.xml file as follows:
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="AIzaSyDWOTqYHHYlrziUPoF4IshFKNxKxlo91PM" />
And you need to add the following permissions to your manifest file:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
******************************************************************************************
SCROLL VIEW
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"
<Button
android:id="@+id/button2"
296
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"
android:text="Button 2"
/>
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"
android:text="Button 3"
/>
<Button
android:id="@+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"
android:text="Button 4"
/>
<Button
android:id="@+id/button5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
297
android:layout_marginLeft="20dp"
android:text="Button 5"
/>
<Button
android:id="@+id/button6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"
android:text="Button 6"
/>
<Button
android:id="@+id/button7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"
android:text="Button 7"
/>
<Button
android:id="@+id/button8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"
android:text="Button 8"
/>
298
<Button
android:id="@+id/button9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"
android:text="Button 9"
/>
<Button
android:id="@+id/button10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"
android:text="Button 10"
/>
</LinearLayout>
</ScrollView>
******************************************************************************************
WEB VIEW
Code in MainActivity.java:
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.webkit.WebSettings;
import android.webkit.WebView;
@Override
protected void onCreate(Bundle savedInstanceState) {
299
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mWebView = (WebView) findViewById(R.id.activity_main_webview);
// Enable Javascript
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
mWebView.loadUrl("http://google.com/");
}
}
activity_main.xml:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
tools:ignore="MergeRootFrame">
<WebView
android:id="@+id/activity_main_webview"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
*******************************************************************************************
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
300
}
startActivity(i);
startActivity(i);
startActivity(i);
System.exit(0);
Game.java:
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
301
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Align;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import android.view.Display;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.Window;
import android.view.WindowManager;
MediaPlayer mp1,jump,takecoin;
gameloop gameLoopThread;
super.onCreate(savedInstanceState);
//phone state
TelephonyMgr.listen(new TeleListener(),PhoneStateListener.LISTEN_CALL_STATE);
//for no title
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
302
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(new GameView(this));
Bitmap bmp,pause;
Bitmap background,kinfe,note1,powerimg,note2;
Bitmap run1;
Bitmap run2;
Bitmap run3;
Bitmap coin;
Bitmap exit;
int show=0,sx,sy;
int cspeed=0,kspeed=0,gameover=0;
int score=0,health=100,reset=0;
int pausecount=0,volume,power=0,powerrun=0,shieldrun=0;
@SuppressWarnings("deprecation")
@SuppressLint("NewApi")
super(context);
holder = getHolder();
303
holder.addCallback(new SurfaceHolder.Callback() {
@SuppressWarnings("deprecation")
@Override
gameLoopThread.setRunning(false);
gameLoopThread.getThreadGroup().interrupt();
@SuppressLint("WrongCall")
@Override
gameLoopThread.setRunning(true);
gameLoopThread.start();
@Override
});
sx = display.getWidth();
304
sy = display.getHeight();;
cspeed=sx/2;
kspeed=sx/2;
powerrun=(3*sx/4);
shieldrun=sx/8;
run1=BitmapFactory.decodeResource(getResources(), R.drawable.run1);
run2=BitmapFactory.decodeResource(getResources(), R.drawable.run2);
run3=BitmapFactory.decodeResource(getResources(), R.drawable.run3);
coin=BitmapFactory.decodeResource(getResources(), R.drawable.coin);
exit=BitmapFactory.decodeResource(getResources(), R.drawable.exit);
kinfe=BitmapFactory.decodeResource(getResources(), R.drawable.kinfe);
note1=BitmapFactory.decodeResource(getResources(), R.drawable.note1);
pause=BitmapFactory.decodeResource(getResources(), R.drawable.pause);
powerimg=BitmapFactory.decodeResource(getResources(), R.drawable.power);
note2=BitmapFactory.decodeResource(getResources(), R.drawable.note2);
//health dec
mp1=MediaPlayer.create(Game.this,R.raw.game);
305
jump=MediaPlayer.create(Game.this,R.raw.jump);
takecoin=MediaPlayer.create(Game.this,R.raw.cointake);
// on touch method
@Override
if(event.getAction()==MotionEvent.ACTION_DOWN)
show=1;
getx=(int) event.getX();
gety=(int) event.getY();
//exit
if(getx<25&&gety<25)
//high score
SharedPreferences pref =
getApplicationContext().getSharedPreferences("higher", MODE_PRIVATE);
editor.putInt("score", score);
editor.commit();
System.exit(0);
// restart game
if(getx>91&&gety<25)
306
if(health<=0)
gameLoopThread.setPause(0);
health=100;
score=0;
//pause game
if((getx>(sx-25)&&gety<25&&pausecount==0))
gameLoopThread.setPause(1);
mp1.stop();
pausecount=1;
else if(getx>(sx-25)&&gety<25&&pausecount==1)
gameLoopThread.setPause(0);
mp1.start();
pausecount=0;
return true;
@SuppressLint("WrongCall")
@Override
307
protected void onDraw(Canvas canvas)
//volume
volume=pref.getInt("vloume", 0);
if(volume==0)
sound=0;
canvas.drawColor(Color.BLACK);
//background moving
z=z-10;
if(z==-sx)
z=0;
canvas.drawBitmap(background, z, 0, null);
else
canvas.drawBitmap(background, z, 0, null);
//running player
308
x+=5;
if(x==20)
x=5;
if(show==0)
if(x%2==0)
else
//kinfe hit
if(kspeed==20)
kspeed=sx;
health-=25;
canvas.drawBitmap(note1, 0, 0, null);
//power take
if(powerrun==30)
309
{
powerrun=3*sx;
health+=25;
canvas.drawBitmap(note2, 0, 0, null);
//power
powerrun=powerrun-10;
if(powerrun<0)
powerrun=3*sx/4;
//kinfe
kspeed=kspeed-20;
if(kspeed<0)
kspeed=sx;
// for jump
if(show==1)
if(sound==1)
jump.start();
310
canvas.drawBitmap(run2, sx/16, 3*sy/4, null);
//score
if(cspeed<=sx/8&&cspeed>=sx/16)
if(sound==1)
takecoin.start();
cspeed=sx/2;
score+=10;
// jump-hold
delay+=1;
if(delay==3)
show=0;
delay=0;
//for coins
cspeed=cspeed-5;
if(cspeed==-sx/2)
311
cspeed=sx/2;
else
//score
paint.setColor(Color.BLUE);
paint.setAntiAlias(true);
paint.setFakeBoldText(true);
paint.setTextSize(15);
paint.setTextAlign(Align.LEFT);
//exit
canvas.drawBitmap(exit, 0, 0, null);
if(sound==1)
mp1.start();
mp1.setLooping(true);
else
mp1.stop();
//health
312
myPaint.setColor(Color.RED);
myPaint.setStrokeWidth(10);
myPaint.setAntiAlias(true);
myPaint.setFakeBoldText(true);
//game over
if(health<=0)
gameover=1;
mp1.stop();
//high score
editor.putInt("score", score);
editor.commit();
gameLoopThread.setPause(1);
// restart
if(reset==1)
gameLoopThread.setPause(0);
health=100;
score=0;
313
}
//phone state
if(state==TelephonyManager.CALL_STATE_RINGING)
mp1.stop();
System.exit(0);
gameloop.java:
import android.annotation.SuppressLint;
import android.graphics.Canvas;
314
static final long FPS = 10;
boolean isPaused;
this.view = view;
running = run;
synchronized (view.getHolder())
if(i==0)
isPaused=false;
if(i==1)
isPaused = true;
315
@SuppressLint("WrongCall")
@Override
long startTime = 0;
long sleepTime;
while (running) {
if (isPaused)
try
this.sleep(50);
catch (InterruptedException e)
e.printStackTrace();
else
Canvas c = null;
startTime = System.currentTimeMillis();
try {
c = view.getHolder().lockCanvas();
316
synchronized (view.getHolder())
view.onDraw(c);
finally
if (c != null)
view.getHolder().unlockCanvasAndPost(c);
try {
if (sleepTime > 0)
sleep(sleepTime);
else
sleep(10);
catch (Exception e) {}
317
Highscore.java:
import android.R.string;
import android.os.Bundle;
import android.app.Activity;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.view.Menu;
import android.widget.TextView;
TextView t1;
int score,hscore;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_highscore);
score=pref.getInt("score", 0);
hscore=pref.getInt("hscore", 0);
if(score>hscore)
editor.putInt("hscore", score);
editor.commit();
hscore=pref.getInt("hscore", 0);
318
t1=(TextView) findViewById(R.id.textView1);
t1.setText("Highscore :"+hscore);
Setting.java:
import android.os.Bundle;
import android.app.Activity;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.view.Menu;
import android.view.View;
import android.widget.CheckBox;
import android.widget.Toast;
CheckBox ch1;
int volume;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_setting);
ch1=(CheckBox) findViewById(R.id.checkBox1);
volume=pref.getInt("vloume", 0);
if(volume==1)
319
{
ch1.setChecked(true);
ch1 = (CheckBox)v;
if(ch1.isChecked())
editor.putInt("vloume", 1);
editor.commit();
else
editor.putInt("vloume", 0);
editor.commit();
@Override
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.setting, menu);
return true;
320
LAYOUT FILES:
activity_main.xml:
<?xml version="1.0"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin" tools:context=".MainActivity"
android:background="@drawable/back"><Button android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="@+id/button2"
android:layout_below="@+id/button4" android:layout_centerHorizontal="true"
android:layout_marginTop="23dp" android:onClick="setting" android:text="@string/set"/><Button
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:id="@+id/button3" android:layout_below="@+id/button2"
android:layout_centerHorizontal="true" android:layout_marginTop="16dp" android:onClick="exit"
android:text="@string/ex"/><Button android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="@+id/button4"
android:layout_below="@+id/button1" android:layout_centerHorizontal="true"
android:layout_marginTop="19dp" android:onClick="highscore" android:text="@string/score"/><Button
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:id="@+id/button1" android:layout_marginTop="43dp" android:onClick="play"
android:text="@string/play" android:layout_alignLeft="@+id/button4"
android:layout_alignParentTop="true"/></RelativeLayout>
activity_game.xml:
<?xml version="1.0"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin" tools:context=".Game"> </RelativeLayout>
activity_highscore.xml:
<?xml version="1.0"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin" tools:context=".Highscore"
android:background="@drawable/back"><TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="@+id/textView1"
android:layout_alignParentLeft="true" android:layout_alignParentTop="true"
android:layout_marginLeft="20dp" android:layout_marginTop="55dp" android:text="@string/hs"
android:textAppearance="?android:attr/textAppearanceLarge"/></RelativeLayout>
activity_setting.xml:
321
<?xml version="1.0"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin" tools:context=".Setting"
android:background="@drawable/back"><CheckBox android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="@+id/checkBox1"
android:layout_alignParentLeft="true" android:layout_alignParentTop="true"
android:layout_marginTop="45dp" android:text="@string/vol"
android:onClick="volume"/></RelativeLayout>
Menu
drawable folder
raw folder:
322
strings.xml:
*********************************************************************************************
After installing android studio into your system (say computer or laptop) —and after installation, when you
open the android studio to create some project / application – you usually observe an error stating that: junit
cannot be resolved. In order to solve this error, you need to go to C drive → and under C drive – you need to go to
users → and under users – you need to go to manju folder → and under manju folder – you need to go to
AndroidStudioProjects→ and under AndroidStudioProjects → you need to open Application folder → and you need
to go to app folder → and under app folder → you need to open libs folder → and in libs folder – you need to place
junit (executable jar file
junit.jar
– which can be downloaded on internet). And you need to open android studio → and you need to go to file →
project structure → app → dependencies (if you click on it) – a window :
323
Choose library dependency will be opened and in that window you need to choose m junit:junit:4.12 and press ok
and that window will be disappeared. But you will notice
Battery temperature
.JAVA FILES:
324
MainActivity.java
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.content.IntentFilter;
import android.os.Bundle;
import android.widget.TextView;
TemperatureReceiver.java
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
LAYOUT FILES
activity_main.xml
<?xml version="1.0"?>
<RelativeLayout tools:context=".MainActivity"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingBottom="@dimen/activity_vertical_margin" android:layout_height="match_parent"
android:layout_width="match_parent" xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android">
325
android:text="Temperature " android:layout_alignParentLeft="true" android:id="@+id/textView1"/>
</RelativeLayout>
********************************************************************************************************************
MainActivity.java
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.app.SearchManager;
import android.content.Intent;
import android.view.View.OnClickListener;
import android.widget.EditText;
LAYOUT FILE
activity_main.xml
<requestFocus/>
</EditText>
</LinearLayout>
Drawable folder
button_background.xml
Android manifest.xml
<uses-permission android:name="android.permission.INTERNET"/>
*********************************************************************************************
Android manifest.xml
<uses-permission android:name="android.permission.INTERNET"/>
*********************************************************************************************
MainActivity.java
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
327
import android.view.View;
import android.content.Intent;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
{
Intent i = new Intent(MainActivity.this, Sendmsg.class);
startActivity(i);
}
}
}
Sendmsg.java
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.telephony.TelephonyManager;
import android.widget.TextView;
import android.widget.Toast;
SharedPreferences sp=null;
SharedPreferences.Editor edit;
TelephonyManager telemananger=null;
TelephonyManager telemanager2=null;
String anothervar=null;
String var=null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.sendms);
telemananger = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
anothervar = telemananger.getSimSerialNumber();
sp=getSharedPreferences("share1",Activity.MODE_APPEND);
edit=sp.edit();
var=sp.getString("sim_no",null);
if(var==null)
{
sp.edit().putString("sim_no",anothervar).commit();
var=sp.getString("sim_no",null);
TextView tv=(TextView)findViewById(R.id.textView2);
tv.setText(String.valueOf(anothervar));
}
else
Toast.makeText(this, "hi..", Toast.LENGTH_LONG).show();
TextView tv=(TextView)findViewById(R.id.textView4);
tv.setText(String.valueOf("this is the value of shared prefernces....... ="+var));
328
}
Comp.java
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
LAYOUT FILES
activity_main.xml
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button1"
android:id="@+id/Bdisplay"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="177dp"
android:onClick="onButtonClick" />
</RelativeLayout>
sendms.xml
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
329
android:layout_height="wrap_content"
android:text="Sim Number:" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Sim Number:"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" />
</LinearLayout>
Android manifest.xml
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<activity android:name=".Sendmsg"/>
<receiver android:name=".Comp"/>
*********************************************************************************************
Popup window
JAVA FILES
MainActivity.java
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.PopupWindow;
330
Button btnClosePopup;
Button btnCreatePopup;
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
initiatePopupWindow();
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
}
};
LAYOUT FILE
activity_main.xml
331
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
</LinearLayout>
screen_popup.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/popup_element"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#444444"
android:orientation="vertical"
android:padding="10sp" >
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"></TableLayout>
<Button
android:layout_marginTop="50dp"
android:id="@+id/btn_close_popup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Close" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button1"
android:id="@+id/Bdisplay"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="177dp"
android:onClick="onButtonClick"
android:layout_gravity="center_horizontal" />
</LinearLayout>
*********************************************************************************************
LIST VIEW
JAVA FILE
MainActivity.java
332
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ListView list = (ListView) findViewById(R.id.list1);
String[] days = { "Sunday", "Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday","Sunday", "Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday"
};
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, days);
list.setAdapter(adapter);
}
}
LAYOUT FILE
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ListView
android:id="@+id/list1"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</ListView>
</RelativeLayout>
*************************************************************************************
AGE CALCULATOR
JAVA FILES
MainActivity.java
import java.util.Calendar;
import java.util.Timer;
import android.os.Bundle;
import android.app.Activity;
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.TextView;
333
import android.widget.Toast;
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case DATE_START_DIALOG_ID:
return new DatePickerDialog(this,
mDateSetListener,
startYear, startMonth, startDay);
}
return null;
}
default:
break;
}
}
private void calculateAge()
{
age.calcualteYear();
age.calcualteMonth();
age.calcualteDay();
334
Toast.makeText(getBaseContext(), "click the resulted button"+age.getResult() ,
Toast.LENGTH_SHORT).show();
result.setText("AGE (DD/MM/YY) :"+age.getResult());
}
}
AgeCalculation.java
import java.util.Calendar;
import java.util.Date;
}
public void calcualteYear()
{
resYear=endYear-startYear;
}
public void calcualteDay()
{
if(endDay>=startDay)
{
335
resDay= endDay-startDay;
}
else
{
resDay=endDay-startDay;
resDay=30+resDay;
if(resMonth==0)
{
resMonth=11;
resYear--;
}
else
{
resMonth--;
}
}
}
LAYOUT FILE
activity_main.xml
<?xml version="1.0"?>
336
android:text="Result" android:layout_alignParentLeft="true" android:id="@+id/textView3"
android:layout_marginTop="16dp" android:layout_below="@+id/textView2"/>
</RelativeLayout>
*********************************************************************************************
Send sms
JAVA FILE
MainActivity.java
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.app.Activity;
import android.os.Bundle;
import android.telephony.gsm.SmsManager;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import android.view.View;
import android.view.Menu;
Button btnSend;
EditText txtPhoneNo;
EditText txtSMS;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.content_main);
btnSend=(Button) findViewById(R.id.buttonSend);
txtPhoneNo=(EditText) findViewById(R.id.editTextPhoneNo);
txtSMS=(EditText) findViewById(R.id.editTextSMS);
btnSend.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
String phoneNo=txtPhoneNo.getText().toString();
String SMS=txtSMS.getText().toString();
try {
SmsManager smsManager=SmsManager.getDefault();
smsManager.sendTextMessage(phoneNo, null, SMS, null, null);
Toast.makeText(getApplicationContext(),"SMS
Sent!...",Toast.LENGTH_LONG).show();
} catch (Exception e) {
Toast.makeText(getApplicationContext(), "SMS faild, please try again
later!",Toast.LENGTH_LONG).show();
e.printStackTrace();
337
}
}
});
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
LAYOUT FILE
activity_main.xml
<LinearLayout
android:orientation="vertical"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:id="@+id/linearLayout1" xmlns:android="http://schemas.android.com/apk/res/android">
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/textViewPhoneNo" android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Enter Phone Number : "/>
<EditText android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:id="@+id/editTextPhoneNo"
android:phoneNumber="true"> </EditText>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/textViewSMS" android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Enter SMS Message : "/>
<EditText
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:id="@+id/editTextSMS"
android:gravity="top"
android:lines="5"
android:inputType="textMultiLine"/>
<Button
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:id="@+id/buttonSend"
android:text="Send"/>
</LinearLayout>
338
<uses-permission android:name="android.permission.SEND_SMS"/>
************************************************************************************
MainActivity.java
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.pm.PackageManager;
import android.hardware.Camera;
import android.hardware.Camera.Parameters;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.ImageButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.content_main);
/*
* First check if device is supporting flashlight or not
*/
hasFlash = getApplicationContext().getPackageManager()
.hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH);
if (!hasFlash) {
// device doesn't support flash
// Show alert message and close the application
AlertDialog alert = new AlertDialog.Builder(MainActivity.this)
.create();
alert.setTitle("Error");
alert.setMessage("Sorry, your device doesn't support flash light!");
alert.setButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// closing the application
finish();
}
});
alert.show();
339
return;
}
/*
* Switch button click event to toggle flash on/off
*/
btnSwitch.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (isFlashOn) {
// turn off flash
turnOffFlash();
} else {
// turn on flash
turnOnFlash();
}
}
});
}
/*
* Get the camera
*/
private void getCamera() {
if (camera == null) {
try {
camera = Camera.open();
params = camera.getParameters();
} catch (RuntimeException e) {
Log.e("Camera Error. Failed to Open. Error: ", e.getMessage());
}
}
}
/*
* Turning On flash
*/
private void turnOnFlash() {
if (!isFlashOn) {
if (camera == null || params == null) {
return;
}
// play sound
playSound();
params = camera.getParameters();
params.setFlashMode(Parameters.FLASH_MODE_TORCH);
camera.setParameters(params);
camera.startPreview();
isFlashOn = true;
/*
* Turning Off flash
340
*/
private void turnOffFlash() {
if (isFlashOn) {
if (camera == null || params == null) {
return;
}
// play sound
playSound();
params = camera.getParameters();
params.setFlashMode(Parameters.FLASH_MODE_OFF);
camera.setParameters(params);
camera.stopPreview();
isFlashOn = false;
/*
* Playing sound will play button toggle sound on flash on / off
*/
private void playSound() {
if (isFlashOn) {
mp = MediaPlayer.create(MainActivity.this, R.raw.light_switch_off);
} else {
mp = MediaPlayer.create(MainActivity.this, R.raw.light_switch_on);
}
mp.setOnCompletionListener(new OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
// TODO Auto-generated method stub
mp.release();
}
});
mp.start();
}
/*
* Toggle switch button images changing image states to on / off
*/
private void toggleButtonImage() {
if (isFlashOn) {
btnSwitch.setImageResource(R.drawable.btn_switch_on);
} else {
btnSwitch.setImageResource(R.drawable.btn_switch_off);
}
}
@Override
protected void onDestroy() {
super.onDestroy();
}
@Override
protected void onPause() {
super.onPause();
@Override
protected void onRestart() {
341
super.onRestart();
}
@Override
protected void onResume() {
super.onResume();
@Override
protected void onStart() {
super.onStart();
@Override
protected void onStop() {
super.onStop();
LAYOUT FILE
activity_main.xml
<?xml version="1.0"?>
</LinearLayout>
Android manifest.xml
<uses-permission android:name="android.permission.CAMERA"/>
<uses-feature android:name="android.hardware.camera"/>
Drawable folder
342
Raw folder
light_switch_on.mp3 light_switch_off.mp3
*********************************************************************************************
Bluetooth activation
JAVA FILE
MainActivity.java
import android.os.Bundle;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;
import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
BluetoothAdapter bt = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//initialize bluetooth adapter object
bt = BluetoothAdapter.getDefaultAdapter();
}
343
//Pop-up dialog box to confirm to enable bluetooth
/*Intent i=new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivity(i); */
//Display blutooth device value on Toast
Toast.makeText(this, "bluetooth found.." + bt, Toast.LENGTH_LONG).show();
} else {
//disable bluetooth
bt.disable();
}
}
}
}
Layout file
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#024" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:onClick="action"
android:text="Enable and disable bluetooth"
android:textSize="18sp" />
</RelativeLayout>
Android manifest.xml
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
*********************************************************************************************
Wifi activation
JAVA FILE
MainActivity.java
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.support.v7.app.AppCompatActivity;
WifiManager wm;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
344
setContentView(R.layout.activity_main);
}
//this method will call on button click
public void wwf(View v)
{
Button b1=(Button)findViewById(R.id.button1);
//get Wifi service
wm=(WifiManager)getSystemService(WIFI_SERVICE);
//Check Wifi is on or off
if(wm.isWifiEnabled())
{
b1.setText("Wifi OFF");
//enable or disable Wifi
//for enable pass true value
//for disable pass false value
wm.setWifiEnabled(false);
}
else
{
b1.setText("Wifi ON");
wm.setWifiEnabled(true);
}
}
Layout file
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#b21"
>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:onClick="wwf"
android:text="Wifi OFF"
android:textSize="30sp" />
</RelativeLayout>
Android manifest.xml
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
*********************************************************************************************
345
Main activity.java
import android.os.Bundle;
import android.view.View;
import android.app.Activity;
import android.content.Intent;
Intent i=null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
Login.java
import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.text.InputType;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;
346
tv1=(EditText)findViewById(R.id.phone2);
tv4=(EditText)findViewById(R.id.password2);
db=openOrCreateDatabase("mydb", MODE_PRIVATE, null);
// db.execSQL("create table if not exists login(name varchar,mobile_no varchar,email_id
varchar,password varchar,flag varchar)");
im.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
if(flag==false)
{
im.setImageResource(R.drawable.hide);
tv4.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD);
flag=true;
}
else
{
im.setImageResource(R.drawable.show);
tv4.setInputType(129);
flag=false;
}
}
});
}
}
break;
347
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
overridePendingTransition(R.anim.slide_in_left, R.anim.slide_out_right);
}
Signin.java
import android.app.Activity;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.text.InputType;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;
im.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
if(flag==false)
{
im.setImageResource(R.drawable.hide);
tv4.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD);
flag=true;
}
else
{
im.setImageResource(R.drawable.show);
tv4.setInputType(129);
flag=false;
}
}
});
348
}
Welcome.java
import android.app.Activity;
import android.os.Bundle;
LAYOUT FILES:
activity_main.xml
<?xml version="1.0"?>
<RelativeLayout android:background="#999999"
android:layout_height="fill_parent"
android:layout_width="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_alignParentBottom="true">
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:onClick="login_sigin"
android:text="Sign In"
android:textSize="20sp"
android:layout_weight="1"
android:id="@+id/sign_in"/>
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:onClick="login_sigin"
android:text="Log In"
android:textSize="20sp"
android:layout_weight="1"
android:id="@+id/log_in"/>
</LinearLayout>
<TextView android:background="#CCCCCC"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text=" Welcome "
android:textSize="25sp"
android:id="@+id/text"
android:textColor="#333333"
android:textAppearance="?android:attr/textAppearanceLarge"
android:gravity="center"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentLeft="true"/>
</RelativeLayout>
login.xml
350
<?xml version="1.0"?>
<RelativeLayout
android:background="@android:drawable/edit_text"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:gravity="center_vertical"
android:baselineAligned="false"
android:addStatesFromChildren="true"
android:layout_centerVertical="true"
android:layout_alignRight="@+id/phone2"
android:layout_alignLeft="@+id/phone2"
android:id="@+id/rl">
<ImageView
android:background="@drawable/show"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/show_hide2"
android:layout_marginTop="4dp"
android:layout_alignParentTop="true"
android:layout_alignBottom="@+id/rl"
android:layout_alignParentRight="true"
style="@android:style/Widget.Button.Inset"/>
<EditText
android:background="@null"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/password2"
android:layout_alignParentTop="true"
android:layout_alignBottom="@+id/rl"
android:singleLine="true"
android:maxLines="1"
android:inputType="textPassword"
android:hint="Password"
android:focusableInTouchMode="true"
android:focusable="true"
android:maxLength="40"
android:ems="10"
android:layout_toLeftOf="@+id/show_hide2"
android:layout_alignParentLeft="true"/>
</RelativeLayout>
<EditText android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/phone2"
android:inputType="phone"
android:hint="Mobile No."
android:maxLength="10"
android:ems="10"
android:layout_centerHorizontal="true"
android:layout_above="@+id/rl">
<requestFocus/>
</EditText>
<Button
android:layout_height="wrap_content"
351
android:layout_width="wrap_content" android:id="@+id/signin2"
android:layout_alignParentTop="true" android:layout_alignParentRight="true"
android:layout_alignParentLeft="true" android:textSize="20sp" android:onClick="action"
android:text="Sign in"/>
</RelativeLayout>
signin.xml
<?xml version="1.0"?>
<requestFocus/>
</EditText>
<RelativeLayout android:background="@android:drawable/edit_text"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:layout_alignLeft="@+id/email_id" android:id="@+id/rl" android:gravity="center_vertical"
android:baselineAligned="false" android:addStatesFromChildren="true"
android:layout_below="@+id/email_id" android:layout_alignRight="@+id/email_id">
</RelativeLayout>
352
<Button android:layout_height="wrap_content" android:layout_width="wrap_content"
android:layout_alignLeft="@+id/rl" android:id="@+id/signin" android:layout_below="@+id/rl"
android:layout_alignRight="@+id/rl" android:layout_marginTop="10dp" android:textSize="20sp"
android:onClick="action" android:text="Continue.."/>
</RelativeLayout>
Welcome.xml
<?xml version="1.0"?>
</RelativeLayout>
Drawable FOLDER
anim FOLDER
Android manifest.xml
353
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<activity android:name="com.example.manju.myapplication.Login"/>
<activity android:name="com.example.manju.myapplication.Signin"/>
<activity android:name="com.example.manju.myapplication.Welcome"/>
</application>
</manifest>
MainActivity.java
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import org.json.JSONObject;
import android.graphics.Color;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.util.Log;
import android.view.Menu;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.Toast;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.GoogleMap.OnMapClickListener;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
354
import com.google.android.gms.maps.model.PolylineOptions;
GoogleMap map;
RadioButton rbDriving;
RadioButton rbBiCycling;
RadioButton rbWalking;
RadioGroup rgModes;
ArrayList<LatLng> markerPoints;
int mMode=0;
final int MODE_DRIVING=0;
final int MODE_BICYCLING=1;
final int MODE_WALKING=2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
rgModes.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
// Initializing
markerPoints = new ArrayList<LatLng>();
355
// Setting onclick event listener for the map
map.setOnMapClickListener(new OnMapClickListener() {
@Override
public void onMapClick(LatLng point) {
for(int i=0;i<markerPoints.size();i++){
// Creating MarkerOptions
MarkerOptions options = new MarkerOptions();
/**
* For the start location, the color of marker is GREEN and
* for the end location, the color of marker is RED.
*/
if(i==0){
options.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN));
}else if(i==1){
options.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED));
}
// Origin of route
String str_origin = "origin="+origin.latitude+","+origin.longitude;
356
// Destination of route
String str_dest = "destination="+dest.latitude+","+dest.longitude;
// Sensor enabled
String sensor = "sensor=false";
// Travelling Mode
String mode = "mode=driving";
if(rbDriving.isChecked()){
mode = "mode=driving";
mMode = 0 ;
}else if(rbBiCycling.isChecked()){
mode = "mode=bicycling";
mMode = 1;
}else if(rbWalking.isChecked()){
mode = "mode=walking";
mMode = 2;
}
// Output format
String output = "json";
return url;
}
// Connecting to url
urlConnection.connect();
data = sb.toString();
br.close();
}catch(Exception e){
Log.d("Exception while downloading url", e.toString());
}finally{
357
iStream.close();
urlConnection.disconnect();
}
return data;
}
try{
// Fetching the data from web service
data = downloadUrl(url[0]);
}catch(Exception e){
Log.d("Background Task",e.toString());
}
return data;
}
JSONObject jObject;
List<List<HashMap<String, String>>> routes = null;
try{
jObject = new JSONObject(jsonData[0]);
DirectionsJSONParser parser = new DirectionsJSONParser();
358
MarkerOptions markerOptions = new MarkerOptions();
points.add(position);
}
if(result.size()<1){
Toast.makeText(getBaseContext(), "No Points", Toast.LENGTH_SHORT).show();
return;
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
}
DirectionsJSONParser.java
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import com.google.android.gms.maps.model.LatLng;
359
public class DirectionsJSONParser {
/** Receives a JSONObject and returns a list of lists containing latitude and longitude */
public List<List<HashMap<String,String>>> parse(JSONObject jObject){
try {
jRoutes = jObject.getJSONArray("routes");
/**
* Method to decode polyline points
* Courtesy : jeffreysambells.com/2010/05/27/decoding-polylines-from-google-maps-direction-
api-with-java
* */
private List<LatLng> decodePoly(String encoded) {
360
shift += 5;
} while (b >= 0x20);
int dlat = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1));
lat += dlat;
shift = 0;
result = 0;
do {
b = encoded.charAt(index++) - 63;
result |= (b & 0x1f) << shift;
shift += 5;
} while (b >= 0x20);
int dlng = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1));
lng += dlng;
LAYOUT FILE:
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<RadioGroup
android:id="@+id/rg_modes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal" >
<RadioButton android:id="@+id/rb_driving"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/str_rb_driving"
android:checked="true" />
<RadioButton android:id="@+id/rb_bicycling"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/str_rb_bicycling" />
<RadioButton android:id="@+id/rb_walking"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/str_rb_walking" />
</RadioGroup>
<fragment
android:id="@+id/map"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@id/rg_modes"
361
class="com.google.android.gms.maps.SupportMapFragment" />
</RelativeLayout>
Android Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.manju.myapplication">
<permission
android:name="com.example.manju.myapplication.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyChFgoCG01fzZeXxxEvL-f7yElcekl3vwA"/>
</application>
</manifest>
String.xml
<string name="hello_world">Hello world!</string>
<string name="str_rb_driving">Driving</string>
<string name="str_rb_bicycling">BiCycling</string>
<string name="str_rb_walking">Walking</string>
*********************************************************************************************
362
MainActivity.java
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.content.Intent;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
{
Intent i = new Intent(MainActivity.this, ListBatchesActivity.class);
startActivity(i);
}
}
}
ListView listBatches;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.listbatches);
}
@Override
public void onStart() {
super.onStart();
listBatches = (ListView) this.findViewById(R.id.listBatches);
BatchesAdapter adapter = new BatchesAdapter(this);
listBatches.setAdapter(adapter);
}
363
AddBatchActivity
import java.util.Calendar;
import android.app.Activity;
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.app.TimePickerDialog;
import android.os.Bundle;
import android.view.View;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.TimePicker;
import android.widget.Toast;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.addbatch);
setDateToSysdate();
updateDateDisplay();
if ( done )
Toast.makeText(this,"Added batch successfully!", Toast.LENGTH_LONG).show();
364
else
Toast.makeText(this,"Sorry! Could not add batch!", Toast.LENGTH_LONG).show();
}
@Override
protected Dialog onCreateDialog(int id) {
super.onCreateDialog(id);
switch (id) {
case DATE_DIALOG:
return new DatePickerDialog(this, dateSetListener, year, month, day);
case TIME_DIALOG:
return new TimePickerDialog(this, timeSetListener, hours,mins, false);
}
return null;
}
public void onDateSet(DatePicker view, int pYear, int pMonth, int pDay) {
year = pYear;
month = pMonth;
day = pDay;
updateDateDisplay();
}
};
@Override
public void onTimeSet(TimePicker arg0, int pHours, int pMins) {
hours = pHours;
mins = pMins;
updateTimeDisplay();
}
};
365
AddClassActivity
import java.util.Calendar;
import android.app.Activity;
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.app.TimePickerDialog;
import android.os.Bundle;
import android.view.View;
import android.widget.CheckBox;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.TimePicker;
import android.widget.Toast;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.addclass);
textBatchCode.setText( getIntent().getStringExtra("batchcode"));
setDateToSysdate();
updateDateDisplay();
}
if ( done )
Toast.makeText(this,"Added Class Successfully!", Toast.LENGTH_LONG).show();
else
Toast.makeText(this,"Sorry! Could not add class!", Toast.LENGTH_LONG).show();
366
}
@Override
protected Dialog onCreateDialog(int id) {
super.onCreateDialog(id);
switch (id) {
case DATE_DIALOG:
return new DatePickerDialog(this, dateSetListener, year, month, day);
case TIME_DIALOG:
return new TimePickerDialog(this, timeSetListener, hours,mins, false);
}
return null;
}
public void onDateSet(DatePicker view, int pYear, int pMonth, int pDay) {
year = pYear;
month = pMonth;
day = pDay;
updateDateDisplay();
}
};
@Override
public void onTimeSet(TimePicker arg0, int pHours, int pMins) {
hours = pHours;
mins = pMins;
updateTimeDisplay();
}
};
Batch
367
public class Batch {
368
public void setClassesperweek(String classesperweek) {
this.classesperweek = classesperweek;
}
BatchesAdapter
import java.util.ArrayList;
import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.TextView;
@Override
public int getCount() {
return batches.size();
}
@Override
public Object getItem(int pos) {
return batches.get(pos);
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = inflater.inflate(R.layout.batch, null);
Button btnClasses = (Button) convertView.findViewById(R.id.btnClasses);
Button btnUpdate = (Button) convertView.findViewById(R.id.btnUpdate);
Button btnAddClass = (Button) convertView.findViewById(R.id.btnAddClass);
369
TextView textCode = (TextView) convertView.findViewById(R.id.textCode);
textCode.setText( batch.getCode());
btnClasses.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
Context context = view.getContext();
Intent intent = new Intent(context, ListClassesActivity.class);
intent.putExtra("batchcode",batch.getCode());
context.startActivity(intent);
}
});
btnAddClass.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
Context context = view.getContext();
Intent intent = new Intent(context, AddClassActivity.class);
intent.putExtra("batchcode",batch.getCode());
context.startActivity(intent);
}
});
btnUpdate.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
Class
public class Class {
private String classno, classId, classDate, classTime, period, topics, remarks, batchCode;
370
public String getClassId() {
return classId;
}
ClassSchedulerActivity
import android.app.Activity;
import android.database.sqlite.SQLiteDatabase;
371
import android.os.Bundle;
}
}
Database
import java.util.ArrayList;
import java.util.Calendar;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;
372
.getColumnIndex(Database.BATCHES_PERIOD)));
batch.setRemarks(batches.getString(batches
.getColumnIndex(Database.BATCHES_REMARKS)));
return batch;
}
public static boolean addClass(Context context, String batchCode, String classDate, String
classTime, String period, String topics, String remarks, boolean adjust) {
DBHelper dbhelper = null;
SQLiteDatabase db = null;
try {
dbhelper = new DBHelper(context);
db = dbhelper.getWritableDatabase();
db.beginTransaction();
if ( adjust ) {
// delete last class for the batch
boolean deleted = deleteLastClass(db,batchCode);
if ( !deleted) {
db.endTransaction();
return false;
}
}
if ( rowid >=0 ) {
db.setTransactionSuccessful();
db.endTransaction();
return true;
}
else {
db.endTransaction();
return false;
}
}
catch(Exception ex) {
Log.d("CS", "Error in addClass -->" + ex.getMessage());
return false;
}
373
finally {
if (db != null && db.isOpen()) {
db.close();
}
}
}
if ( lastClass.moveToFirst() ) {
classid = lastClass.getString( lastClass.getColumnIndex(
Database.CLASSES_CLASSES_ID));
int rows = db.delete(Database.CLASSES_TABLE_NAME,Database.CLASSES_CLASSES_ID + "
= ?",
new String[] { classid} );
done = rows == 1;
}
lastClass.close();
return done;
}
catch (Exception ex) {
Log.d("Account", "Error in deleteLastClass-->" + ex.getMessage());
return false;
}
} // deleteLastClass
db.endTransaction();
374
return false;
}
catch (Exception ex) {
Log.d("CS", "Error in cancelClass-->" + ex.getMessage());
return false;
}
finally {
if (db != null && db.isOpen()) {
db.close();
}
}
lastClass.close();
ContentValues values = new ContentValues();
values.put(Database.CLASSES_BATCHCODE, batch.getCode());
values.put(Database.CLASSES_CLASSDATE, calendarToString(c));
values.put(Database.CLASSES_CLASSTIME, batch.getStarttime());
values.put(Database.CLASSES_CLASSPERIOD, batch.getPeriod());
values.put(Database.CLASSES_REMARKS,"");
values.put(Database.CLASSES_TOPICS,"");
375
return false;
}
} // deleteLastClass
db.setTransactionSuccessful();
db.endTransaction();
return true;
} catch (Exception ex) {
Log.d("Account", "Error in addTransaction -->" + ex.getMessage());
return false;
} finally {
if (db != null && db.isOpen()) {
db.close();
}
376
}
} // addBatch
db.endTransaction();
return true;
} catch (Exception ex) {
Log.d("Account", "Error in updateBatch-->" + ex.getMessage());
return false;
} finally {
if (db != null && db.isOpen()) {
db.close();
}
}
} // updateBatch
377
return false;
} finally {
if (db != null && db.isOpen()) {
db.close();
}
}
} // updateBatch
db.endTransaction();
return true;
} catch (Exception ex) {
Log.d("Account", "Error in deleteBatch-->" + ex.getMessage());
return false;
} finally {
if (db != null && db.isOpen()) {
db.close();
}
}
} // deleteBatch
if (dow == 1)
return 7;
else
return dow - 1;
}
378
Calendar c = Calendar.getInstance();
c.set(year, month, day);
int classnumber = 1;
do {
int dow = c.get(Calendar.DAY_OF_WEEK);
} // addClasses
while (batches.moveToNext()) {
Batch batch = Database.cursorToBatch(batches);
String enddate = getEndDate(db, batch.getCode());
batch.setEnddate(enddate);
list.add(batch);
}
batches.close();
db.close();
dbhelper.close();
return list;
} // getBatches
while (classes.moveToNext()) {
Class cls = Database.cursorToClass(classes);
list.add(cls);
379
}
classes.close();
db.close();
dbhelper.close();
return list;
} // getBatches
} // getBatch
classes.close();
db.close();
380
dbhelper.close();
return clas;
} // getBatch
DBHelper
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
@Override
public void onCreate(SQLiteDatabase db) {
createTables(db);
}
@Override
public void onUpgrade(SQLiteDatabase arg0, int arg1, int arg2) {
try {
database.execSQL(batches_table_sql);
database.execSQL("insert into batches (batchcode,course,
startdate,starttime,classes,period,classesperweek,remarks)"
+ "values ('HB2404','Hibernate','2012-04-24','19:00',6,90,6,'Short
course')");
381
database.execSQL(classes_table_sql);
Log.d("CS","Tables created!");
}
catch(Exception ex) {
Log.d("CS", "Error in DBHelper.onCreate() : " + ex.getMessage());
}
}
ListBatchesActivity
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;
ListView listBatches;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.listbatches);
}
@Override
public void onStart() {
super.onStart();
listBatches = (ListView) this.findViewById(R.id.listBatches);
BatchesAdapter adapter = new BatchesAdapter(this);
listBatches.setAdapter(adapter);
}
382
ListClassesActivity
import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageButton;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;
import java.util.List;
String batchcode;
TableLayout tableClasses;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.listclasses);
@Override
public void onStart() {
super.onStart();
deleteRowsFromTable();
addRowsToTable(tableClasses,batchcode);
}
int classno = 1;
for(final Class c : classes) {
TableRow row = (TableRow) LayoutInflater.from(this).inflate(R.layout.classrow, null);
((TextView)row.findViewById(R.id.textNo)).setText( String.valueOf(classno));
((TextView)row.findViewById(R.id.textDate)).setText(c.getClassDate());
((TextView)row.findViewById(R.id.textTime)).setText(c.getClassTime());
table.addView(row);
line.addView(tv);
table.addView(line);
classno ++;
}
UpdateBatchActivity
import android.app.Activity;
import android.app.AlertDialog;
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.app.TimePickerDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.TimePicker;
import android.widget.Toast;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.updatebatch);
384
// get details from database
String batchcode = getIntent().getStringExtra("batchcode");
Batch batch = Database.getBatch(this, batchcode);
if ( batch == null)
{
// error
}
else
{
editBatchcode.setText( batch.getCode());
editCourse.setText( batch.getCourse());
textStartDate.setText( batch.getStartdate());
textStartTime.setText( batch.getStarttime());
editPeriod.setText( batch.getPeriod());
textClasses.setText( batch.getClasses());
textClassesPerWeek.setText( batch.getClassesperweek());
editRemarks.setText( batch.getRemarks());
setDateToStartDate( batch.getStartdate());
setTimeToStartTime( batch.getStarttime());
}
if ( done )
Toast.makeText(this,"Updated batch successfully!", Toast.LENGTH_LONG).show();
else
Toast.makeText(this,"Sorry! Could not update batch!", Toast.LENGTH_LONG).show();
385
showDialog(TIME_DIALOG);
}
@Override
protected Dialog onCreateDialog(int id) {
super.onCreateDialog(id);
switch (id) {
case DATE_DIALOG:
return new DatePickerDialog(this, dateSetListener, year, month, day);
case TIME_DIALOG:
return new TimePickerDialog(this, timeSetListener, hours,mins, false);
case DELETE_ALERT_DIALOG:
return getAlertDialog();
}
return null;
}
public void onDateSet(DatePicker view, int pYear, int pMonth, int pDay) {
year = pYear;
month = pMonth;
day = pDay;
updateDateDisplay();
}
};
@Override
public void onTimeSet(TimePicker arg0, int pHours, int pMins) {
hours = pHours;
mins = pMins;
updateTimeDisplay();
}
};
386
if ( done ) {
Toast.makeText(UpdateBatchActivity.this,"Deleted batch
successfully!", Toast.LENGTH_LONG).show();
UpdateBatchActivity.this.finish();
}
else
Toast.makeText(UpdateBatchActivity.this,"Sorry! Could not
delete batch!", Toast.LENGTH_LONG).show();
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
return builder.create();
}
UpdateClassActivity
import android.app.Activity;
import android.app.AlertDialog;
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.app.TimePickerDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.TimePicker;
import android.widget.Toast;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.updateclass);
387
Class clas = Database.getClass(this, classid);
if ( clas == null)
{
// error
}
else
{
textBatchCode.setText( clas.getBatchCode());
textClassDate.setText( clas.getClassDate());
textClassTime.setText( clas.getClassTime());
setTimeToStartTime(clas.getClassTime());
editPeriod.setText( clas.getPeriod());
editTopics.setText( clas.getTopics());
editRemarks.setText( clas.getRemarks());
}
}
if ( done )
Toast.makeText(this,"Updated class successfully!", Toast.LENGTH_LONG).show();
else
Toast.makeText(this,"Sorry! Could not update class!", Toast.LENGTH_LONG).show();
}
@Override
protected Dialog onCreateDialog(int id) {
super.onCreateDialog(id);
switch (id) {
case TIME_DIALOG:
return new TimePickerDialog(this, timeSetListener, hours,mins, false);
case CANCEL_ALERT_DIALOG:
return getCancelAlertDialog();
case DELETE_ALERT_DIALOG:
return getDeleteAlertDialog();
}
return null;
}
388
private TimePickerDialog.OnTimeSetListener timeSetListener =
new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker arg0, int pHours, int pMins) {
hours = pHours;
mins = pMins;
updateTimeDisplay();
}
};
if ( done ) {
Toast.makeText(UpdateClassActivity.this,"Deleted Class
Successfully!", Toast.LENGTH_LONG).show();
UpdateClassActivity.this.finish();
}
else
Toast.makeText(UpdateClassActivity.this,"Sorry! Could not
delete class!", Toast.LENGTH_LONG).show();
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
return builder.create();
}
389
cancel class!", Toast.LENGTH_LONG).show();
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
return builder.create();
}
Layout Files
activity_main .xml
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button1"
android:id="@+id/Bdisplay"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="177dp"
android:onClick="onButtonClick" />
</RelativeLayout>
Addbatch.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:stretchColumns="1" >
<TableRow >
<TextView
android:id="@+id/textView1"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="Code" />
<EditText
android:id="@+id/editBatchCode"
390
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<requestFocus />
</EditText>
</TableRow>
<TableRow >
<TextView
android:id="@+id/textView1"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="Course" />
<EditText
android:id="@+id/editCourse"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</EditText>
</TableRow>
<TableRow >
<TextView
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="Start Date" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="showDatePicker"
android:src="@mipmap/ic_launcher" >
</ImageButton>
<TextView
android:id="@+id/textStartDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="10dp"
android:text="2012-04-24" >
</TextView>
</LinearLayout>
</TableRow>
<TableRow >
<TextView
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="Start Time" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="showTimePicker"
android:src="@mipmap/ic_launcher" >
391
</ImageButton>
<TextView
android:id="@+id/textStartTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="10dp"
android:text="19:00" >
</TextView>
</LinearLayout>
</TableRow>
<TableRow >
<TextView
android:id="@+id/textView1"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="No. Classes" />
<EditText
android:id="@+id/editClasses"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="number" >
</EditText>
</TableRow>
<TableRow >
<TextView
android:id="@+id/textView1"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:text="Classes Per Week" />
<EditText
android:id="@+id/editClassesPerWeek"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="number" >
</EditText>
</TableRow>
<TableRow >
<TextView
android:id="@+id/textView1"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="Period (Min)" />
<EditText
android:id="@+id/editPeriod"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="number" >
</EditText>
</TableRow>
<TableRow >
<TextView
android:id="@+id/textView1"
392
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="Remarks" />
<EditText
android:id="@+id/editRemarks"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</EditText>
</TableRow>
<TableRow >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="addBatch"
android:text="Add Batch" >
</Button>
</TableRow>
</TableLayout>
</ScrollView>
Addclass.xml
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TableRow>
<TextView
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="Batch Code " />
<TextView
android:id="@+id/textBatchCode"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:text="Hib2404" >
</TextView>
</TableRow>
<TableRow >
<TextView
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="Class Date" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="showDatePicker"
android:src="@mipmap/ic_launcher" >
</ImageButton>
<TextView
android:id="@+id/textClassDate"
393
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="10dp"
android:text="2012-04-24" >
</TextView>
</LinearLayout>
</TableRow>
<TableRow >
<TextView
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="Class Time" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="showTimePicker"
android:src="@mipmap/ic_launcher" >
</ImageButton>
<TextView
android:id="@+id/textClassTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="10dp"
android:text="19:00" >
</TextView>
</LinearLayout>
</TableRow>
<TableRow >
<TextView
android:id="@+id/textView1"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="Period (Min)" />
<EditText
android:id="@+id/editPeriod"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:inputType="number" >
</EditText>
</TableRow>
<TableRow >
<TextView
android:id="@+id/textView1"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="Topics" />
<EditText
android:id="@+id/editTopics"
394
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</EditText>
</TableRow>
<TableRow >
<TextView
android:id="@+id/textView1"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="Remarks" />
<EditText
android:id="@+id/editRemarks"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</EditText>
</TableRow>
<TableRow android:layout_span="2">
<CheckBox
android:id="@+id/chkAdjust"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Adjust Last Class?" >
</CheckBox>
</TableRow>
</TableLayout>
Batch.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/textCode"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="code"
android:textSize="16sp" />
<TextView
android:id="@+id/textCourse"
android:gravity="right"
android:layout_weight="1"
android:layout_width="wrap_content"
395
android:layout_height="wrap_content"
android:textSize="16sp"
android:text="Course"/>
</LinearLayout>
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/textStartDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16sp"
android:text="stdate" />
<TextView
android:id="@+id/textEndDate"
android:gravity="right"
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16sp"
android:text="EndDate"/>
</LinearLayout>
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<Button
android:id="@+id/btnClasses"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:text="List Classes" />
<Button
android:id="@+id/btnAddClass"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:text="Add Class" />
<Button
android:id="@+id/btnUpdate"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:text="Update" />
</LinearLayout>
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="3dp"
android:background="#ff0000"
android:text="" />
</LinearLayout>
</LinearLayout>
396
Classrow.xml
<?xml version="1.0" encoding="utf-8"?>
<TableRow xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/textNo"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:gravity="center"
android:text="no" />
<TextView
android:id="@+id/textDate"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Date" />
<TextView
android:id="@+id/textTime"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Time" />
<ImageButton
android:id="@+id/btnUpdate"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_gravity="center"
android:adjustViewBounds="true"
android:src="@mipmap/ic_launcher"
android:textSize="12sp" />
</TableRow>
Listbatches.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ListView
android:id="@+id/listBatches"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
<Button
android:id="@+id/butAddBatch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="addBatch"
android:layout_gravity="center_horizontal"
android:text="Add New Batch" />
397
</LinearLayout>
Listclasses.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TableLayout
android:id="@+id/tableClasses"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:stretchColumns="*">
<TableRow android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="80dp"
android:gravity="center"
android:layout_height="wrap_content"
android:text="Class No." />
<TextView
android:layout_width="80dp"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Class Date" />
<TextView
android:layout_width="80dp"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Class Time" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="" />
</TableRow>
<TableRow android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_span="4"
android:layout_height="3dp"
android:background="#ff0000"
android:text="" />
</TableRow>
</TableLayout>
</ScrollView>
Main.xml
398
android:text="@string/hello"/>
</LinearLayout>
Updatebatch.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:stretchColumns="1" >
<TableRow >
<TextView
android:id="@+id/textView1"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="Code" />
<EditText
android:id="@+id/editBatchCode"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<requestFocus />
</EditText>
</TableRow>
<TableRow >
<TextView
android:id="@+id/textView1"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="Course" />
<EditText
android:id="@+id/editCourse"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</EditText>
</TableRow>
<TableRow >
<TextView
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="Start Date" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/textStartDate"
android:layout_width="wrap_content"
399
android:layout_height="wrap_content"
android:paddingRight="10dp"
android:text="2012-04-24"
android:textSize="20sp" >
</TextView>
</LinearLayout>
</TableRow>
<TableRow >
<TextView
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="Start Time" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="showTimePicker"
android:src="@mipmap/ic_launcher" >
</ImageButton>
<TextView
android:id="@+id/textStartTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="10dp"
android:text="19:00"
android:textSize="20sp" >
</TextView>
</LinearLayout>
</TableRow>
<TableRow >
<TextView
android:id="@+id/textView1"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="No. Classes" />
<TextView
android:id="@+id/textClasses"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp" />
</TableRow>
<TableRow >
<TextView
android:id="@+id/textView1"
400
android:layout_width="120dp"
android:layout_height="wrap_content"
android:text="Classes Per Week" />
<TextView
android:id="@+id/textClassesPerWeek"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp" />
</TableRow>
<TableRow >
<TextView
android:id="@+id/textView1"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="Period (Min)" />
<EditText
android:id="@+id/editPeriod"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="number" >
</EditText>
</TableRow>
<TableRow >
<TextView
android:id="@+id/textView1"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="Remarks" />
<EditText
android:id="@+id/editRemarks"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</EditText>
</TableRow>
<TableRow>
<LinearLayout
android:layout_span="2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="updateBatch"
android:text="Update" >
</Button>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="deleteBatch"
android:text="Delete" >
</Button>
</LinearLayout>
</TableRow>
</TableLayout>
401
</ScrollView>
Updateclass.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="Batch Code " />
<TextView
android:id="@+id/textBatchCode"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hib2404"
android:textSize="20sp" >
</TextView>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="Class Date" />
<TextView
android:id="@+id/textClassDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2012-04-24"
android:textSize="20sp" >
</TextView>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="Class Time" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="showTimePicker"
android:src="@mipmap/ic_launcher" >
</ImageButton>
402
<TextView
android:id="@+id/textClassTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="10dp"
android:text="00:00"
android:textSize="20sp" >
</TextView>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/textView1"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="Period (Min)" />
<EditText
android:id="@+id/editPeriod"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:inputType="number" >
</EditText>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/textView1"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="Topics" />
<EditText
android:id="@+id/editTopics"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</EditText>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/textView1"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="Remarks" />
<EditText
android:id="@+id/editRemarks"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</EditText>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center" >
403
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="updateClass"
android:text="Update" >
</Button>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="cancelClass"
android:text="Cancel Class" >
</Button>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="deleteClass"
android:text="Delete" >
</Button>
</LinearLayout>
</LinearLayout>
</ScrollView>
String.xml
<resources>
<string name="app_name">My Application</string>
<string name="action_settings">Settings</string>
<string name="hello">Hello World, ClassSchedulerActivity!</string>
</resources>
Manifest.xml file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.manju.myapplication">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
404
<activity android:label="List Classes" android:name=".ListClassesActivity"/>
</application>
</manifest>
*********************************************************************************************
Bank details app
JAVA FILES:
ListAccounts.java
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;
import android.widget.Toast;
ListView listAccounts;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.listaccounts);
listAccounts = (ListView) this.findViewById(R.id.listAccounts);
listAccounts.setOnItemClickListener( new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View selectedView, int arg2,long arg3)
{
TextView textAccountId = (TextView)
selectedView.findViewById(R.id.textAccountId);
Log.d("Accounts", "Selected Account Id : " + textAccountId.getText().toString());
Intent intent = new Intent(ListAccounts.this, UpdateAccount.class);
intent.putExtra("accountid", textAccountId.getText().toString());
startActivity(intent);
}
});
}
@Override
405
public boolean onCreateOptionsMenu(Menu menu) {
return Utils.inflateMenu(this,menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
return Utils.handleMenuOption(this,item);
}
@Override
public void onStart() {
super.onStart();
try {
DBHelper dbhelper = new DBHelper(this);
SQLiteDatabase db = dbhelper.getReadableDatabase();
Cursor accounts = db.query(
Database.ACCOUNTS_TABLE_NAME,null,null,null,null,null,null);
Account.java
public class Account {
private String id,acno,bank,branch,holder;
406
public void setId(String id) {
this.id = id;
}
@Override
public String toString() {
return holder + " - " + bank;
}
AddAccount.java
import android.app.Activity;
import android.content.ContentValues;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
@Override
407
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.addaccount);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
return Utils.inflateMenu(this,menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
return Utils.handleMenuOption(this,item);
}
try {
DBHelper dbhelper = new DBHelper(this);
SQLiteDatabase db = dbhelper.getWritableDatabase();
Log.d("Account","Got Writable database");
// execute insert command
408
Toast.makeText(this, ex.getMessage(), Toast.LENGTH_LONG).show();
}
AddTransaction
import java.util.Calendar;
import android.app.Activity;
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.add_transaction);
spinnerAccounts = (Spinner) this.findViewById(R.id.spinnerAccounts);
Database.populateAccounts(spinnerAccounts);
textTransDate = (TextView) this.findViewById(R.id.textTransDate);
// get the current date
final Calendar c = Calendar.getInstance();
year = c.get(Calendar.YEAR);
month = c.get(Calendar.MONTH);
day = c.get(Calendar.DAY_OF_MONTH);
updateDateDisplay();
}
@Override
public void onStart() {
super.onStart();
409
}
@Override
protected Dialog onCreateDialog(int id) {
super.onCreateDialog(id);
switch (id) {
case DATE_DIALOG:
return new DatePickerDialog(this,
dateSetListener, year, month, day);
}
return null;
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
return Utils.inflateMenu(this,menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
return Utils.handleMenuOption(this,item);
}
if ( done )
Toast.makeText(this,"Added Transaction Successfully!", Toast.LENGTH_LONG).show();
else
Toast.makeText(this, "Sorry Could Not Add Transaction!", Toast.LENGTH_LONG).show();
} // addDeposit
410
Database
import java.util.ArrayList;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;
import android.widget.ArrayAdapter;
import android.widget.DatePicker;
import android.widget.Spinner;
account.setHolder(accounts.getString(accounts.getColumnIndex(Database.ACCOUNTS_HOLDERS)));
account.setBank( accounts.getString(accounts.getColumnIndex(Database.ACCOUNTS_BANK)));
return account;
}
// adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
while (accounts.moveToNext()) {
Account account = Database.cursorToAccount(accounts);
list.add(account);
}
accounts.close();
db.close();
dbhelper.close();
411
ArrayAdapter<Account> adapter = new ArrayAdapter<Account>(context,
android.R.layout.simple_spinner_item,list);
spinnerAccounts.setAdapter(adapter);
}
412
db.endTransaction();
return false;
}
}
else
return false;
}
catch(Exception ex) {
Log.d("Account", "Error in addTransaction -->" + ex.getMessage());
return false;
}
finally {
if ( db != null && db.isOpen()) {
db.close();
}
}
} // addTransaction
DBHelper.java
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
@Override
public void onCreate(SQLiteDatabase db) {
createTables(db);
}
@Override
public void onUpgrade(SQLiteDatabase arg0, int arg1, int arg2) {
413
" +
Database.TRANSACTIONS_ID + " integer primary key autoincrement," +
Database.TRANSACTIONS_ACCOUNT_ID + " TEXT," +
Database.TRANSACTIONS_TRANSDATE + " TEXT," +
Database.TRANSACTIONS_TRANSAMOUNT + " FLOAT," +
Database.TRANSACTIONS_TRANSTYPE+ " TEXT," +
Database.TRANSACTIONS_CHEQUE_NO + " TEXT," +
Database.TRANSACTIONS_CHEQUE_PARTY + " TEXT," +
Database.TRANSACTIONS_CHEQUE_DETAILS+ " TEXT," +
Database.TRANSACTIONS_REMARKS + " TEXT)";
try {
database.execSQL(account_table_sql);
database.execSQL(transactions_table_sql);
Log.d("Accounts","Tables created!");
}
catch(Exception ex) {
Log.d("Accounts", "Error in DBHelper.onCreate() : " + ex.getMessage());
}
}
ListAccountTransactions.java
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.Map;
import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.opengl.Visibility;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.list_account_transactions);
accountId = this.getIntent().getStringExtra("accountid");
listTransactions = (ListView) this.findViewById(R.id.listTransactions);
listTransactions.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View selectedView,
int arg2, long arg3) {
TextView textTransId = (TextView) selectedView
.findViewById(R.id.textTransId);
414
Intent intent = new Intent(ListAccountTransactions.this,
TransactionDetails.class);
intent.putExtra("transid", textTransId.getText().toString());
startActivity(intent);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
return Utils.inflateMenu(this, menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
return Utils.handleMenuOption(this, item);
}
@Override
public void onStart() {
super.onStart();
try {
DBHelper dbhelper = new DBHelper(this);
SQLiteDatabase db = dbhelper.getReadableDatabase();
Cursor trans = db.query(Database.TRANSACTIONS_TABLE_NAME, null,
Database.TRANSACTIONS_ACCOUNT_ID + " = ?",
new String[] { accountId }, null, null,
Database.TRANSACTIONS_TRANSDATE + " desc");
415
SimpleAdapter adapter = new SimpleAdapter(this, listTrans,
R.layout.account_transaction, new String[] { "transid",
"transdate", "transdetails", "transtype",
"transamount" }, new int[] { R.id.textTransId,
R.id.textTransDate, R.id.textTransDetails,
R.id.textTransType, R.id.textAmount });
listTransactions.setAdapter(adapter);
} catch (Exception ex) {
Toast.makeText(this, ex.getMessage(), Toast.LENGTH_LONG).show();
}
}
ListRecentTransactions.java
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.Map;
import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;
@Override
public boolean onCreateOptionsMenu(Menu menu) {
return Utils.inflateMenu(this,menu);
416
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
return Utils.handleMenuOption(this,item);
}
@Override
public void onStart() {
super.onStart();
try {
DBHelper dbhelper = new DBHelper(this);
SQLiteDatabase db = dbhelper.getReadableDatabase();
Cursor trans = db.rawQuery("select t._id, acno,bank,
transdate,transamount,transtype,cheque_no,cheque_party,cheque_details, t.remarks from
transactions t inner join accounts a on ( a._id = t.account_id) order by transdate desc LIMIT
10",null);
if ( trans.getCount() == 0 )
this.findViewById(R.id.textError).setVisibility(View.VISIBLE);
else
this.findViewById(R.id.textError).setVisibility(View.INVISIBLE);
tran.put("transdate",trans.getString(trans.getColumnIndex(Database.TRANSACTIONS_TRANSDATE)));
tran.put("transtype",trans.getString(trans.getColumnIndex(Database.TRANSACTIONS_TRANSTYPE)));
tran.put("transamount",trans.getString(trans.getColumnIndex(Database.TRANSACTIONS_TRANSAMOUNT)));
tran.put("transremarks",trans.getString(trans.getColumnIndex(Database.TRANSACTIONS_REMARKS)));
String chequeno =
trans.getString(trans.getColumnIndex(Database.TRANSACTIONS_CHEQUE_NO));
String transDetails = "Cash";
if (! chequeno.trim().equals(""))
transDetails = "Cheque No: " + chequeno;
tran.put("transdetails",transDetails);
listTrans.add(tran);
}
trans.close();
db.close();
dbhelper.close();
listTransactions.setAdapter(adapter);
} catch (Exception ex) {
Toast.makeText(this, ex.getMessage(), Toast.LENGTH_LONG).show();
}
}
417
}
SearchTransactions.java
import java.util.Calendar;
import android.app.Activity;
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.search_transactions);
editFromDate = (EditText) this.findViewById(R.id.editFromDate);
editToDate = (EditText) this.findViewById(R.id.editToDate);
updateToDateDisplay();
updateFromDateDisplay();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
return Utils.inflateMenu(this,menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
return Utils.handleMenuOption(this,item);
}
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case FROM_DATE_DIALOG:
return new DatePickerDialog(this,
fromDateSetListener, fromYear, fromMonth, fromDay);
case TO_DATE_DIALOG:
return new DatePickerDialog(this,
toDateSetListener, toYear, toMonth, toDay);
}
return null;
}
editFromDate.setText("");
editToDate.setText("");
editFromAmount.setText("");
editToAmount.setText("");
}
419
}
TransactionDetails.java
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
transId = this.getIntent().getStringExtra("transid");
Log.d("Account", "Trans id : " + transId);
if (tran.moveToFirst()) {
accountId = tran.getString(tran.getColumnIndex(Database.TRANSACTIONS_ACCOUNT_ID));
textAcno.setText( tran.getString(tran.getColumnIndex(Database.ACCOUNTS_ACNO)));
textTransDate.setText(
tran.getString(tran.getColumnIndex(Database.TRANSACTIONS_TRANSDATE)));
textTransType.setText(
tran.getString(tran.getColumnIndex(Database.TRANSACTIONS_TRANSTYPE)));
420
textTransAmount.setText(
tran.getString(tran.getColumnIndex(Database.TRANSACTIONS_TRANSAMOUNT)));
textChequeNo.setText(
tran.getString(tran.getColumnIndex(Database.TRANSACTIONS_CHEQUE_NO)));
textChequeParty.setText(
tran.getString(tran.getColumnIndex(Database.TRANSACTIONS_CHEQUE_PARTY)));
textChequeDetails.setText(
tran.getString(tran.getColumnIndex(Database.TRANSACTIONS_CHEQUE_DETAILS)));
textRemarks.setText(tran.getString(tran.getColumnIndex(Database.TRANSACTIONS_REMARKS)));
}
else
Log.d("Accounts","No transaction found!");
db.close();
dbhelper.close();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
return Utils.inflateMenu(this,menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
return Utils.handleMenuOption(this,item);
}
421
}
else
Toast.makeText(this, "Could not delet transaction!", Toast.LENGTH_LONG).show();
}
catch (Exception ex) {
Toast.makeText(this, ex.getMessage(), Toast.LENGTH_LONG).show();
}
}
UpdateAccount.java
import android.app.Activity;
import android.app.AlertDialog;
import android.content.ContentValues;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.update_account);
editAcno = (EditText) this.findViewById(R.id.editAcno);
editCno = (EditText) this.findViewById(R.id.editCno);
editHolders = (EditText) this.findViewById(R.id.editHolders);
editBankName = (EditText) this.findViewById(R.id.editBankName);
editBranchName = (EditText) this.findViewById(R.id.editBranchName);
editAddress = (EditText) this.findViewById(R.id.editAddress);
editIFSC = (EditText) this.findViewById(R.id.editIFSC);
editMICR = (EditText) this.findViewById(R.id.editMICR);
editBalance = (EditText) this.findViewById(R.id.editBalance);
editRemarks = (EditText) this.findViewById(R.id.editRemarks);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
return Utils.inflateMenu(this,menu);
422
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
return Utils.handleMenuOption(this,item);
}
@Override
public void onStart() {
super.onStart();
accountId = this.getIntent().getStringExtra("accountid");
Log.d("Accounts", "Account Id : " + accountId);
DBHelper dbhelper = new DBHelper(this);
SQLiteDatabase db = dbhelper.getReadableDatabase();
Cursor account = db.query(Database.ACCOUNTS_TABLE_NAME, null,
" _id = ?", new String[] { accountId }, null, null, null);
//startManagingCursor(accounts);
if (account.moveToFirst()) {
// update view
editAcno.setText(account.getString(account
.getColumnIndex(Database.ACCOUNTS_ACNO)));
editCno.setText(account.getString(account
.getColumnIndex(Database.ACCOUNTS_CNO)));
editHolders.setText(account.getString(account
.getColumnIndex(Database.ACCOUNTS_HOLDERS)));
editBankName.setText(account.getString(account
.getColumnIndex(Database.ACCOUNTS_BANK)));
editBranchName.setText(account.getString(account
.getColumnIndex(Database.ACCOUNTS_BRANCH)));
editAddress.setText(account.getString(account
.getColumnIndex(Database.ACCOUNTS_ADDRESS)));
editIFSC.setText(account.getString(account
.getColumnIndex(Database.ACCOUNTS_IFSC)));
editMICR.setText(account.getString(account
.getColumnIndex(Database.ACCOUNTS_MICR)));
editBalance.setText(account.getString(account
.getColumnIndex(Database.ACCOUNTS_BALANCE)));
editRemarks.setText(account.getString(account
.getColumnIndex(Database.ACCOUNTS_REMARKS)));
}
account.close();
db.close();
dbhelper.close();
423
values.put(Database.ACCOUNTS_BALANCE, editBalance.getText()
.toString());
values.put(Database.ACCOUNTS_REMARKS, editRemarks.getText()
.toString());
db.close();
if (rows > 0)
Toast.makeText(this, "Updated Account Successfully!",
Toast.LENGTH_LONG).show();
else
Toast.makeText(this, "Sorry! Could not update account!",
Toast.LENGTH_LONG).show();
} catch (Exception ex) {
Toast.makeText(this, ex.getMessage(), Toast.LENGTH_LONG).show();
}
}
424
Utils.java
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
case R.id.optSearchTransactions :
intent = new Intent(activity,SearchTransactions.class);
activity.startActivity(intent);
break;
case R.id.optListAccounts :
intent = new Intent(activity,ListAccounts.class);
activity.startActivity(intent);
break;
case R.id.optRecentTransactions :
intent = new Intent(activity,ListRecentTransactions.class);
activity.startActivity(intent);
break;
}
return true;
}
Layout files:
listaccounts.xml
<?xml version="1.0" encoding="UTF-8"?>
425
android:text="Tap on the account to get details!" android:gravity="center"
android:textStyle="bold" android:textColor="#0000ff"/>
</LinearLayout>
</LinearLayout>
account.xml
<?xml version="1.0" encoding="UTF-8"?>
</LinearLayout>
</LinearLayout>
</LinearLayout>
account_transaction.xml
426
<?xml version="1.0" encoding="UTF-8"?>
-<TableRow>
</TableRow>
</TableLayout>
</LinearLayout>
add_transaction.xml
<?xml version="1.0" encoding="UTF-8"?>
<TableRow>
</TableRow>
<TableRow>
</RadioGroup>
</TableRow>
<TableRow>
</LinearLayout>
</TableRow>
<TableRow>
</TableRow>
<TableRow>
</TableRow>
<TableRow>
428
</TableRow>
<TableRow>
</TableRow>
<TableRow>
</TableRow>
<TableRow>
</TableRow>
</TableLayout>
</ScrollView>
addaccount.xml
<?xml version="1.0" encoding="UTF-8"?>
<TableRow>
<requestFocus/>
</EditText>
</TableRow>
429
<TableRow>
</TableRow>
<TableRow>
</TableRow>
<TableRow>
</TableRow>
<TableRow>
</TableRow>
<TableRow>
</TableRow>
<TableRow>
</TableRow>
430
<TableRow>
</TableRow>
<TableRow>
</TableRow>
<TableRow>
</TableRow>
<TableRow>
</TableRow>
</TableLayout>
</ScrollView>
list_account_transactions.xml
<?xml version="1.0" encoding="UTF-8"?>
-<TableRow>
</TableRow>
</TableLayout>
</LinearLayout>
list_transactions.xml
<?xml version="1.0" encoding="UTF-8"?>
</LinearLayout>
Search_transactions.xml
<?xml version="1.0" encoding="UTF-8"?>
<TableRow>
432
<EditText android:layout_height="wrap_content" android:layout_width="120dip"
android:inputType="date" android:id="@+id/editFromDate">
<requestFocus/>
</EditText>
</TableRow>
<TableRow>
</TableRow>
<TableRow>
</TableRow>
<TableRow>
</TableRow>
</TableLayout>
</LinearLayout>
</LinearLayout>
433
Transaction.xml
<?xml version="1.0" encoding="UTF-8"?>
-<TableRow>
</TableRow>
-<TableRow>
</TableRow>
-<TableRow>
</TableRow>
-<TableRow>
</TableRow>
-<TableRow>
</TableRow>
-<TableRow>
</TableRow>
</TableLayout>
</LinearLayout>
Transaction_details.xml
<?xml version="1.0" encoding="UTF-8"?>
-<TableRow>
</TableRow>
</TableLayout>
-<TableRow>
</TableRow>
-<TableRow>
435
android:text="Trans Date :" android:gravity="right"/>
</TableRow>
-<TableRow>
</TableRow>
-<TableRow>
</TableRow>
-<TableRow>
</TableRow>
-<TableRow>
</TableRow>
-<TableRow>
</TableRow>
-<TableRow>
436
android:text="Remarks :" android:gravity="right"/>
</TableRow>
</TableLayout>
</LinearLayout>
Update_account.xml
<?xml version="1.0" encoding="UTF-8"?>
</LinearLayout>
<requestFocus/>
</EditText>
437
<EditText android:layout_height="wrap_content" android:layout_width="match_parent"
android:id="@+id/editBankName"> </EditText>
</LinearLayout>
</ScrollView>
Menu
Common_menu.xml
<?xml version="1.0" encoding="UTF-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
</menu>
String.xml
<resources>
<string name="app_name">My Application</string>
<string name="action_settings">Settings</string>
<string name="accountsprompt">Select Account</string>
</resources>
Manifest.xml
<manifest package="com.example.manju.myapplication"
xmlns:android="http://schemas.android.com/apk/res/android">
-<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
439
*********************************************************************************************
Quiz app
JAVA FILE:
SoccerQuizGame.java
import android.support.v7.app.AppCompatActivity;
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.content.DialogInterface;
import android.content.res.AssetManager;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Menu;
import android.view.MenuItem;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.content.DialogInterface;
import android.content.res.AssetManager;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Menu;
import android.view.MenuItem;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TableLayout;
440
import android.widget.TableRow;
import android.widget.TextView;
//Instance Variables
private List<String> fileNameList; // player file names
private List<String> quizPlayersList; // names of players in quiz
private String correctAnswer; // current correct answer
private int totalGuesses; // number of guesses
private int correctAnswers; // number of correct guesses
private int guessRows; // number of rows displaying choices
private Random random; // random number generator
private Handler handler; // used to delay loading of next player
private Animation shakeAnimation; // animation for incorrect answers
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
441
// get list of all player names in this region
String[] paths = null;
try {
paths = assets.list("Players");
} catch (IOException e) {
// TODO Auto-generated catch block
Log.e(TAG, "Error loading ", e);
}
//get the filename of the next flag and remove it from the list
String nextImageName = quizPlayersList.remove(0);
correctAnswer = nextImageName; //update correct answer
try{
442
stream = assets.open(region + "/" + nextImageName + ".jpg");
// parses the player file name and returns the player name
private String getPlayerName(String name){
443
return name.substring(name.indexOf('-') + 1).replace('-', ' ');
}
if (guess.equals(answer)){
builder.setCancelable(false);
@Override
public void onClick(DialogInterface dialog, int which) {
resetQuiz();
} // end onClick
} // end anonymous inner class
); //end call to setPositiveButton
} // end if
444
} // end else
} // end if
super.onCreateOptionsMenu(menu);
445
//add possibleChoices items to the Dialog and set the
// behavior when one of the items is clicked
choicesBuilder.setItems(R.array.guessesList,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int item) {
resetQuiz();
}
});
break;
} // end switch
return super.onOptionsItemSelected(item);
@Override
public void onClick(View v){
submitGuess((Button) v); // pass selected Button to submitGuess method
}
};
} // end SoccerQuizGame
LAYOUT FILE:
main.xml
<?xml version="1.0" encoding="UTF-8"?>
<ImageView android:layout_height="@dimen/face_height"
446
android:layout_width="@dimen/face_width" android:id="@+id/faceImageView"
android:adjustViewBounds="false"/>
</TableLayout>
</LinearLayout>
guess_button.xml
color.xml
<color name="background_color">#FFFFCC</color>
<color name="correct_answer">#FFFFFF</color>
<color name="incorrect_answer">#FF0000</color>
<color name="text_color">#FFFFFF</color>
string.xml
<string name="hello_world">Hello world!</string>
<string name="menu_settings">Settings</string>
<string name="correct">correct</string>
<string name="guesses">guesses</string>
<string name="incorrect_answer">Wrong!</string>
447
<string name="of">of</string>
<string name="ok">OK</string>
<string name="question">Question</string>
<string-array name="guessesList">
<item>3</item>
<item>6</item>
<item>9</item>
</string-array>
dimen.xml
<resources>
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
<dimen name="fab_margin">16dp</dimen>
<dimen name="title_size">25sp</dimen>
<dimen name="face_width">227dp</dimen>
<dimen name="face_height">150dp</dimen>
<dimen name="answer_size">40sp</dimen>
<dimen name="text_size">20sp</dimen>
<dimen name="padding_small">8dp</dimen>
<dimen name="padding_medium">8dp</dimen>
<dimen name="padding_large">16dp</dimen>
</resources>
Drawable folder
448
anim folder
incorrect_shake.xml
assets folder
PLAYERS PHOTO
MainActivity.java
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Handler.Callback;
import android.os.Message;
import android.support.v7.app.ActionBar;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.inputmethod.EditorInfo;
import android.widget.ArrayAdapter;
import android.widget.Button;
449
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
@Override
public boolean handleMessage(Message msg) {
switch (msg.what) {
case MESSAGE_STATE_CHANGE:
switch (msg.arg1) {
case ChatService.STATE_CONNECTED:
setStatus(getString(R.string.title_connected_to,
connectedDeviceName));
chatArrayAdapter.clear();
break;
case ChatService.STATE_CONNECTING:
setStatus(R.string.title_connecting);
break;
case ChatService.STATE_LISTEN:
case ChatService.STATE_NONE:
setStatus(R.string.title_not_connected);
break;
}
break;
case MESSAGE_WRITE:
byte[] writeBuf = (byte[]) msg.obj;
450
case MESSAGE_DEVICE_NAME:
connectedDeviceName = msg.getData().getString(DEVICE_NAME);
Toast.makeText(getApplicationContext(),
"Connected to " + connectedDeviceName,
Toast.LENGTH_SHORT).show();
break;
case MESSAGE_TOAST:
Toast.makeText(getApplicationContext(),
msg.getData().getString(TOAST), Toast.LENGTH_SHORT)
.show();
break;
}
return false;
}
});
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
getWidgetReferences();
bindEventHandler();
if (bluetoothAdapter == null) {
Toast.makeText(this, "Bluetooth is not available",
Toast.LENGTH_LONG).show();
finish();
return;
}
}
btnSend.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
String message = etMain.getText().toString();
sendMessage(message);
}
});
}
451
setupChat();
} else {
Toast.makeText(this, R.string.bt_not_enabled_leaving,
Toast.LENGTH_SHORT).show();
finish();
}
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.option_menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
Intent serverIntent = null;
switch (item.getItemId()) {
case R.id.secure_connect_scan:
serverIntent = new Intent(this, DeviceListActivity.class);
startActivityForResult(serverIntent, REQUEST_CONNECT_DEVICE_SECURE);
return true;
case R.id.insecure_connect_scan:
serverIntent = new Intent(this, DeviceListActivity.class);
startActivityForResult(serverIntent,
REQUEST_CONNECT_DEVICE_INSECURE);
return true;
case R.id.discoverable:
ensureDiscoverable();
return true;
}
return false;
}
if (message.length() > 0) {
byte[] send = message.getBytes();
chatService.write(send);
outStringBuffer.setLength(0);
452
etMain.setText(outStringBuffer);
}
}
@Override
public void onStart() {
super.onStart();
if (!bluetoothAdapter.isEnabled()) {
Intent enableIntent = new Intent(
BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableIntent, REQUEST_ENABLE_BT);
} else {
if (chatService == null)
setupChat();
}
}
@Override
public synchronized void onResume() {
super.onResume();
if (chatService != null) {
if (chatService.getState() == ChatService.STATE_NONE) {
chatService.start();
}
}
}
@Override
public synchronized void onPause() {
super.onPause();
}
453
@Override
public void onStop() {
super.onStop();
}
@Override
public void onDestroy() {
super.onDestroy();
if (chatService != null)
chatService.stop();
}
DeviceListActivity
import java.util.Set;
import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
setContentView(R.layout.device_list);
setResult(Activity.RESULT_CANCELED);
getWidgetReferences();
bindEventHandler();
initializeValues();
}
454
findViewById(R.id.tvDeviceListPairedDeviceTitle);
tvDeviceListNewDeviceTitle = (TextView) findViewById(R.id.tvDeviceListNewDeviceTitle);
btnDeviceListScan.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
startDiscovery();
btnDeviceListScan.setVisibility(View.GONE);
}
});
}
lvDeviceListPairedDevice.setAdapter(pairedDevicesArrayAdapter);
lvDeviceListNewDevice.setAdapter(newDevicesArrayAdapter);
bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
Set<BluetoothDevice> pairedDevices = bluetoothAdapter
.getBondedDevices();
tvDeviceListNewDeviceTitle.setVisibility(View.VISIBLE);
if (bluetoothAdapter.isDiscovering()) {
bluetoothAdapter.cancelDiscovery();
}
455
bluetoothAdapter.startDiscovery();
}
setResult(Activity.RESULT_OK, intent);
finish();
}
};
if (BluetoothDevice.ACTION_FOUND.equals(action)) {
BluetoothDevice device = intent
.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
if (device.getBondState() != BluetoothDevice.BOND_BONDED) {
newDevicesArrayAdapter.add(device.getName() + "\n"
+ device.getAddress());
}
} else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED
.equals(action)) {
setProgressBarIndeterminateVisibility(false);
setTitle(R.string.select_device);
if (newDevicesArrayAdapter.getCount() == 0) {
String noDevices = getResources().getText(
R.string.none_found).toString();
newDevicesArrayAdapter.add(noDevices);
}
}
}
};
@Override
protected void onDestroy() {
super.onDestroy();
if (bluetoothAdapter != null) {
bluetoothAdapter.cancelDiscovery();
}
this.unregisterReceiver(discoveryFinishReceiver);
}
ChatService
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.UUID;
import android.bluetooth.BluetoothAdapter;
456
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothServerSocket;
import android.bluetooth.BluetoothSocket;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
// Member fields
private final BluetoothAdapter bluetoothAdapter;
private final Handler handler;
private AcceptThread secureAcceptThread;
private AcceptThread insecureAcceptThread;
private ConnectThread connectThread;
private ConnectedThread connectedThread;
private int state;
this.handler = handler;
}
// start service
public synchronized void start() {
// Cancel any thread
if (connectThread != null) {
connectThread.cancel();
connectThread = null;
}
457
}
setState(STATE_LISTEN);
if (secureAcceptThread != null) {
secureAcceptThread.cancel();
secureAcceptThread = null;
}
if (insecureAcceptThread != null) {
insecureAcceptThread.cancel();
insecureAcceptThread = null;
}
458
Message msg = handler.obtainMessage(MainActivity.MESSAGE_DEVICE_NAME);
Bundle bundle = new Bundle();
bundle.putString(MainActivity.DEVICE_NAME, device.getName());
msg.setData(bundle);
handler.sendMessage(msg);
setState(STATE_CONNECTED);
}
if (connectedThread != null) {
connectedThread.cancel();
connectedThread = null;
}
if (secureAcceptThread != null) {
secureAcceptThread.cancel();
secureAcceptThread = null;
}
if (insecureAcceptThread != null) {
insecureAcceptThread.cancel();
insecureAcceptThread = null;
}
setState(STATE_NONE);
}
459
private class AcceptThread extends Thread {
private final BluetoothServerSocket serverSocket;
private String socketType;
try {
if (secure) {
tmp = bluetoothAdapter.listenUsingRfcommWithServiceRecord(
NAME_SECURE, MY_UUID_SECURE);
} else {
tmp = bluetoothAdapter
.listenUsingInsecureRfcommWithServiceRecord(
NAME_INSECURE, MY_UUID_INSECURE);
}
} catch (IOException e) {
}
serverSocket = tmp;
}
460
// runs while attempting to make an outgoing connection
private class ConnectThread extends Thread {
private final BluetoothSocket socket;
private final BluetoothDevice device;
private String socketType;
try {
if (secure) {
tmp = device
.createRfcommSocketToServiceRecord(MY_UUID_SECURE);
} else {
tmp = device
.createInsecureRfcommSocketToServiceRecord(MY_UUID_INSECURE);
}
} catch (IOException e) {
}
socket = tmp;
}
461
public ConnectedThread(BluetoothSocket socket, String socketType) {
this.bluetoothSocket = socket;
InputStream tmpIn = null;
OutputStream tmpOut = null;
try {
tmpIn = socket.getInputStream();
tmpOut = socket.getOutputStream();
} catch (IOException e) {
}
inputStream = tmpIn;
outputStream = tmpOut;
}
// write to OutputStream
public void write(byte[] buffer) {
try {
outputStream.write(buffer);
handler.obtainMessage(MainActivity.MESSAGE_WRITE, -1, -1,
buffer).sendToTarget();
} catch (IOException e) {
}
}
LAYOUT FILES:
activity_main.xml
462
android:layout_width="match_parent" xmlns:android="http://schemas.android.com/apk/res/android">
</LinearLayout>
</LinearLayout>
device_list.xml
</LinearLayout>
device_name.xml
message.xml
463
<?xml version="1.0" encoding="UTF-8"?>
<TextView android:textSize="18sp" android:padding="5dp" android:layout_height="wrap_content"
android:layout_width="match_parent" xmlns:android="http://schemas.android.com/apk/res/android"/>
MENU
option_menu.xml
<?xml version="1.0" encoding="UTF-8"?>
<menu xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android">
</menu>
string.xml
<resources xmlns:xliff="http://schemas.android.com/tools">
<string name="app_name">My Application</string>
<string name="action_settings">Settings</string>
<string name="send">Send</string>
<string name="title_connecting">Connecting...</string>
-<string name="title_connected_to">
Connected to
<xliff:g id="device_name">%1$s</xliff:g>
</string>
464
<string name="title_other_devices">Other Available Devices</string>
</resources>
Manifest.xml
<?xml version="1.0"?>
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
Contacts View
JAVA FILE:
ContactsView.java
import android.app.Activity;
import android.database.Cursor;
465
import android.net.Uri;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.widget.TextView;
while (cursor.moveToNext()) {
LAYOUT FILE:
main.xml
Android manifest.xml
<uses-permission android:name="android.permission.READ_CONTACTS"/>
466
WEB PAGE Download and save in SD CARD
Java files:
MainActivity.java:
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.Messenger;
import android.view.View;
import android.widget.Toast;
};
};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
467
}
}
DownloadService.java
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import android.app.Activity;
import android.app.IntentService;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.os.Message;
import android.os.Messenger;
import android.util.Log;
public DownloadService() {
super("DownloadService");
}
try {
Thread.sleep(4000);
} catch (InterruptedException e2) {
e2.printStackTrace();
}
Uri data = intent.getData();
String urlPath = intent.getStringExtra("urlpath");
String fileName = data.getLastPathSegment();
File output = new File(Environment.getExternalStorageDirectory(),
fileName);
if (output.exists()) {
output.delete();
}
} catch (Exception e) {
e.printStackTrace();
468
} finally {
if (stream != null) {
try {
stream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (fos != null) {
try {
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
}
WrongDownloadService.java
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import android.app.Activity;
import android.app.Service;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.os.IBinder;
import android.os.Message;
import android.os.Messenger;
import android.os.StrictMode;
import android.util.Log;
public WrongDownloadService() {
super();
}
469
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
// Don't do this
// This will run in the main thread
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
.permitAll().build();
StrictMode.setThreadPolicy(policy);
try {
Thread.sleep(4000);
} catch (InterruptedException e2) {
e2.printStackTrace();
}
Uri data = intent.getData();
String urlPath = intent.getStringExtra("urlpath");
String fileName = data.getLastPathSegment();
File output = new File(Environment.getExternalStorageDirectory(),
fileName);
if (output.exists()) {
output.delete();
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (stream != null) {
try {
stream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (fos != null) {
try {
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
470
} catch (android.os.RemoteException e1) {
Log.w(getClass().getName(), "Exception sending message", e1);
}
}
return Service.START_NOT_STICKY;
@Override
public IBinder onBind(Intent intent) {
return null;
}
}
LAYOUT FILE:
activity_main.xml
</LinearLayout>
Android manifest.xml
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
*********************************************************************************************
SHARE WORDS
JAVA FILES:
MainActivity.java
import android.os.Bundle;
471
import android.support.v7.app.AppCompatActivity;
import android.content.Intent;
import android.view.View;
import android.widget.EditText;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
ShareReceiver.java
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Toast;
LAYOUT FILES:
activity_main.xml
472
<EditText android:layout_height="wrap_content" android:layout_width="match_parent"
android:text="Practice, practice, practice, dear Developers!" android:id="@+id/input">
<requestFocus/>
</EditText>
</LinearLayout>
receiver.xml
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
*******************************************************************************************
MainActivity.java
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.os.BatteryManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.util.Log;
import android.widget.TextView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
473
setContentView(R.layout.activity_main);
registerBatteryLevelReceiver();
}
@Override
protected void onDestroy() {
unregisterReceiver(battery_receiver);
super.onDestroy();
}
Log.i("BatteryLevel", bundle.toString());
if (isPresent) {
if (rawlevel >= 0 && scale > 0) {
level = (rawlevel * 100) / scale;
}
switch (plugged) {
case BatteryManager.BATTERY_PLUGGED_AC:
plugType = "AC";
474
break;
case BatteryManager.BATTERY_PLUGGED_USB:
plugType = "USB";
break;
}
return plugType;
}
switch (health) {
case BatteryManager.BATTERY_HEALTH_DEAD:
healthString = "Dead";
break;
case BatteryManager.BATTERY_HEALTH_GOOD:
healthString = "Good";
break;
case BatteryManager.BATTERY_HEALTH_OVER_VOLTAGE:
healthString = "Over Voltage";
break;
case BatteryManager.BATTERY_HEALTH_OVERHEAT:
healthString = "Over Heat";
break;
case BatteryManager.BATTERY_HEALTH_UNSPECIFIED_FAILURE:
healthString = "Failure";
break;
}
return healthString;
}
switch (status) {
case BatteryManager.BATTERY_STATUS_CHARGING:
statusString = "Charging";
break;
case BatteryManager.BATTERY_STATUS_DISCHARGING:
statusString = "Discharging";
break;
case BatteryManager.BATTERY_STATUS_FULL:
statusString = "Full";
break;
case BatteryManager.BATTERY_STATUS_NOT_CHARGING:
statusString = "Not Charging";
break;
}
return statusString;
}
475
private void registerBatteryLevelReceiver() {
IntentFilter filter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
registerReceiver(battery_receiver, filter);
}
}
LAYOUT FILE:
activity_main.xml:
<?xml version="1.0"?>
</LinearLayout>
*********************************************************************************************
JAVA FILE:
MainActivity.java
import android.app.Activity;
import android.content.ContentResolver;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;
// GUI Widget
Button btnSent, btnInbox, btnDraft;
TextView lblMsg, lblNo;
ListView lvMsg;
// Cursor Adapter
SimpleCursorAdapter adapter;
@Override
public void onClick(View v) {
if (v == btnInbox) {
if (v == btnSent) {
477
if (v == btnDraft) {
// Create Draft box URI
Uri draftURI = Uri.parse("content://sms/draft");
}
}
LAYOUT FILES:
messagebox.xml
</LinearLayout>
row.xml
478
<TextView android:textAppearance="?android:attr/textAppearanceLarge"
android:text="TextView" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="@+id/lblMsg"></TextView>
<TextView android:textAppearance="?android:attr/textAppearanceMedium"
android:text="TextView" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:textColor="#00f"
android:id="@+id/lblNumber"></TextView>
</LinearLayout>
Android manifest.xml
<uses-permission android:name="android.permission.SEND_SMS"/>
<uses-permission android:name="android.permission.READ_SMS"/>
*********************************************************************************************
Date Picker
JAVA FILE:
MainActivity.java
import android.os.Bundle;
import android.widget.TextView;
import android.support.v7.app.AppCompatActivity;
import java.util.Calendar;
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.DatePicker;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
479
// Get current date by calender
Output.setText(new StringBuilder()
// Month is 0 based, just add 1
.append(month + 1).append("-").append(day).append("-")
.append(year).append(" "));
changeDate.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
});
}
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case DATE_PICKER_ID:
year = selectedYear;
month = selectedMonth;
day = selectedDay;
}
};
480
LAYOUT FILE
activity_main.xml
</LinearLayout>
*********************************************************************************************
Time Picker
JAVA FILE:
MainActivity.java
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import java.util.Calendar;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.TimePicker;
import android.app.Dialog;
import android.app.TimePickerDialog;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnClick.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
showDialog(TIME_DIALOG_ID);
});
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case TIME_DIALOG_ID:
}
return null;
}
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minutes) {
// TODO Auto-generated method stub
hour = hourOfDay;
minute = minutes;
updateTime(hour,minute);
};
482
if (value < 10)
return "0" + String.valueOf(value);
else
return String.valueOf(value);
}
// Append in a StringBuilder
String aTime = new StringBuilder().append(hours).append(':')
.append(minutes).append(" ").append(timeSet).toString();
output.setText(aTime);
}
}
LAYOUT FILE
activity_main.xml
</LinearLayout>
483
*********************************************************************************************
Check Internet Connectivity
JAVA FILE:
MainActivity.java
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.net.ConnectivityManager;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
Save.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
isInternetOn();
}
});
}
} else if ( connec.getNetworkInfo(0).getState() ==
android.net.NetworkInfo.State.DISCONNECTED || connec.getNetworkInfo(1).getState() ==
android.net.NetworkInfo.State.DISCONNECTED ) {
484
Toast.makeText(this, " Not Connected ", Toast.LENGTH_LONG).show();
return false;
}
return false;
}
}
LAYOUT FILE
activity_main.xml
</LinearLayout>
Android manifest.xml
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
Camera
JAVA FILE:
MainActivity.java
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import java.io.File;
import java.util.List;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.graphics.Bitmap;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity implements OnClickListener {
485
Button btnTackPic;
TextView tvHasCamera, tvHasCameraApp;
ImageView ivThumbnailPhoto;
Bitmap bitMap;
static int TAKE_PICTURE = 1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// The Android Camera application encodes the photo in the return Intent delivered to
onActivityResult()
// as a small Bitmap in the extras, under the key "data"
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
// get
bitMap = (Bitmap) extras.get("data");
ivThumbnailPhoto.setImageBitmap(bitMap);
486
}
}
}
}
LAYOUT FILE
activity_main.xml
<?xml version="1.0"?>
</LinearLayout>
Android manifest.xml
<uses-feature android:name="android.hardware.camera"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
487
List view (Search engine)
JAVA FILE:
MainActivity.java
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import java.util.ArrayList;
import java.util.HashMap;
import android.app.Activity;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ListView;
// List view
private ListView lv;
// Listview Adapter
ArrayAdapter<String> adapter;
// Search EditText
EditText inputSearch;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Listview Data
String products[] = {"Afghanistan",
"Albania",
"Algeria",
"Andorra",
"Angola",
"Antigua and Barbuda",
"Argentina",
"Armenia",
"Australia",
"Austria",
"Azerbaijan",
"Bahamas",
"Bahrain",
"Bangladesh",
"Barbados",
"Belarus",
488
"Belgium",
"Belize",
"Benin",
"Bhutan",
"Bolivia",
"Bosnia and Herzegovina",
"Botswana",
"Brazil",
"Brunei",
"Bulgaria",
"Burkina Faso",
"Burundi",
"Cambodia",
"Cameroon",
"Canada",
"Cape Verde",
"Central African Republic",
"Chad",
"Chile",
"China",
"Colombi",
"Comoros",
"Congo (Brazzaville)",
"Congo",
"Costa Rica",
"Cote d'Ivoire",
"Croatia",
"Cuba",
"Cyprus",
"Czech Republic",
"Denmark",
"Djibouti",
"Dominica",
"Dominican Republic",
"East Timor (Timor Timur)",
"Ecuador",
"Egypt",
"El Salvador",
"Equatorial Guinea",
"Eritrea",
"Estonia",
"Ethiopia",
"Fiji",
"Finland",
"France",
"Gabon",
"Gambia, The",
"Georgia",
"Germany",
"Ghana",
"Greece",
"Grenada",
"Guatemala",
"Guinea",
"Guinea-Bissau",
"Guyana",
"Haiti",
"Honduras",
"Hungary",
"Iceland",
"India",
"Indonesia",
"Iran",
"Iraq",
"Ireland",
"Israel",
489
"Italy",
"Jamaica",
"Japan",
"Jordan",
"Kazakhstan",
"Kenya",
"Kiribati",
"Korea, North",
"Korea, South",
"Kuwait",
"Kyrgyzstan",
"Laos",
"Latvia",
"Lebanon",
"Lesotho",
"Liberia",
"Libya",
"Liechtenstein",
"Lithuania",
"Luxembourg",
"Macedonia",
"Madagascar",
"Malawi",
"Malaysia",
"Maldives",
"Mali",
"Malta",
"Marshall Islands",
"Mauritania",
"Mauritius",
"Mexico",
"Micronesia",
"Moldova",
"Monaco",
"Mongolia",
"Morocco",
"Mozambique",
"Myanmar",
"Namibia",
"Nauru",
"Nepal",
"Netherlands",
"New Zealand",
"Nicaragua",
"Niger",
"Nigeria",
"Norway",
"Oman",
"Pakistan",
"Palau",
"Panama",
"Papua New Guinea",
"Paraguay",
"Peru",
"Philippines",
"Poland",
"Portugal",
"Qatar",
"Romania",
"Russia",
"Rwanda",
"Saint Kitts and Nevis",
"Saint Lucia",
"Saint Vincent",
"Samoa",
"San Marino",
490
"Sao Tome and Principe",
"Saudi Arabia",
"Senegal",
"Serbia and Montenegro",
"Seychelles",
"Sierra Leone",
"Singapore",
"Slovakia",
"Slovenia",
"Solomon Islands",
"Somalia",
"South Africa",
"Spain",
"Sri Lanka",
"Sudan",
"Suriname",
"Swaziland",
"Sweden",
"Switzerland",
"Syria",
"Taiwan",
"Tajikistan",
"Tanzania",
"Thailand",
"Togo",
"Tonga",
"Trinidad and Tobago",
"Tunisia",
"Turkey",
"Turkmenistan",
"Tuvalu",
"Uganda",
"Ukraine",
"United Arab Emirates",
"United Kingdom",
"United States",
"Uruguay",
"Uzbekistan",
"Vanuatu",
"Vatican City",
"Venezuela",
"Vietnam",
"Yemen",
"Zambia",
"Zimbabwe"};
lv = (ListView) findViewById(R.id.list_view);
inputSearch = (EditText) findViewById(R.id.inputSearch);
/**
* Enabling Search Filter
* */
inputSearch.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) {
// When user changed the Text
MainActivity.this.adapter.getFilter().filter(cs);
}
@Override
491
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
int arg3) {
// TODO Auto-generated method stub
@Override
public void afterTextChanged(Editable arg0) {
// TODO Auto-generated method stub
}
});
}
LAYOUT FILE
activity_main.xml
</LinearLayout>
list_item.xml
</LinearLayout>
492
BIBLIOGRAPHY
493
Android Uniquie ID
JAVA FILE:
MainActivity.java
import android.support.v7.app.AppCompatActivity;
import java.lang.reflect.Method;
import android.content.Context;
import android.os.Bundle;
import android.provider.Settings;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.widget.TextView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
@Override
protected void onResume() {
super.onResume();
// Get "Device Serial Number". The Android SystemProperties is apparently not for public
use,
// as it exists on-device but is NOT exposed in the SDK, so treat with a grain of salt!
String serialNumber = "unknown";
try {
Class<?> c = Class.forName("android.os.SystemProperties");
Method get = c.getMethod("get", String.class, String.class);
serialNumber = (String) get.invoke(c, "ro.serialno", serialNumber);
} catch (Exception e) {
Log.e(TAG, "Failed to get serial number", e);
}
((TextView) findViewById(R.id.serial_number)).setText(serialNumber);
494
LAYOUT FILE:
main.xml
<?xml version="1.0"?>
<TableRow>
</TableRow>
<TableRow>
</TableRow>
<TableRow>
</TableRow>
</TableLayout>
string.xml
<string name="imei">IMEI (Mobile ID)</string>
Android manifest.xml
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
495
Telephony Manager
JAVA FILE:
MainActivity.java
import android.support.v7.app.AppCompatActivity;
import java.util.List;
import android.os.Bundle;
import android.telephony.CellLocation;
import android.telephony.NeighboringCellInfo;
import android.telephony.PhoneStateListener;
import android.telephony.ServiceState;
import android.telephony.TelephonyManager;
import android.telephony.gsm.GsmCellLocation;
import android.util.Log;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
startSignalLevelListener();
displayTelephonyInfo();
}
@Override
protected void onPause() {
super.onPause();
stopListening();
}
@Override
protected void onResume() {
super.onResume();
496
startSignalLevelListener();
}
@Override
protected void onDestroy() {
stopListening();
super.onDestroy();
}
switch (direction) {
case TelephonyManager.DATA_ACTIVITY_IN:
resid = R.drawable.data_in;
break;
case TelephonyManager.DATA_ACTIVITY_OUT:
resid = R.drawable.data_out;
break;
case TelephonyManager.DATA_ACTIVITY_INOUT:
resid = R.drawable.data_both;
break;
case TelephonyManager.DATA_ACTIVITY_NONE:
resid = R.drawable.data_none;
break;
default:
resid = R.drawable.data_none;
break;
}
return resid;
}
497
private void startSignalLevelListener() {
TelephonyManager tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
int events = PhoneStateListener.LISTEN_SIGNAL_STRENGTH
| PhoneStateListener.LISTEN_DATA_ACTIVITY
| PhoneStateListener.LISTEN_CELL_LOCATION
| PhoneStateListener.LISTEN_CALL_STATE
| PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR
| PhoneStateListener.LISTEN_DATA_CONNECTION_STATE
| PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR
| PhoneStateListener.LISTEN_SERVICE_STATE;
tm.listen(phoneStateListener, events);
}
498
private String getNetworkTypeString(int type) {
String typeString = "Unknown";
switch (type) {
case TelephonyManager.NETWORK_TYPE_EDGE:
typeString = "EDGE";
break;
case TelephonyManager.NETWORK_TYPE_GPRS:
typeString = "GPRS";
break;
case TelephonyManager.NETWORK_TYPE_UMTS:
typeString = "UMTS";
break;
default:
typeString = "UNKNOWN";
break;
}
return typeString;
}
@Override
public void onCallForwardingIndicatorChanged(boolean cfi) {
Log.i(APP_NAME, "onCallForwardingIndicatorChanged " + cfi);
super.onCallForwardingIndicatorChanged(cfi);
}
@Override
public void onCallStateChanged(int state, String incomingNumber) {
String callState = "UNKNOWN";
switch (state) {
case TelephonyManager.CALL_STATE_IDLE:
callState = "IDLE";
break;
case TelephonyManager.CALL_STATE_RINGING:
callState = "Ringing (" + incomingNumber + ")";
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
callState = "Offhook";
break;
}
setTextViewText(info_ids[INFO_CALL_STATE_INDEX], callState);
Log.i(APP_NAME, "onCallStateChanged " + callState);
super.onCallStateChanged(state, incomingNumber);
}
499
@Override
public void onCellLocationChanged(CellLocation location) {
String locationString = location.toString();
setTextViewText(info_ids[INFO_CELL_LOCATION_INDEX], locationString);
@Override
public void onDataActivity(int direction) {
String directionString = "none";
switch (direction) {
case TelephonyManager.DATA_ACTIVITY_IN:
directionString = "IN";
break;
case TelephonyManager.DATA_ACTIVITY_OUT:
directionString = "OUT";
break;
case TelephonyManager.DATA_ACTIVITY_INOUT:
directionString = "INOUT";
break;
case TelephonyManager.DATA_ACTIVITY_NONE:
directionString = "NONE";
break;
default:
directionString = "UNKNOWN: " + direction;
break;
}
setDataDirection(info_ids[INFO_DATA_DIRECTION_INDEX], direction);
Log.i(APP_NAME, "onDataActivity " + directionString);
super.onDataActivity(direction);
}
@Override
public void onDataConnectionStateChanged(int state) {
String connectionState = "Unknown";
switch (state) {
case TelephonyManager.DATA_CONNECTED:
connectionState = "Connected";
break;
case TelephonyManager.DATA_CONNECTING:
connectionState = "Connecting";
break;
case TelephonyManager.DATA_DISCONNECTED:
connectionState = "Disconnected";
break;
case TelephonyManager.DATA_SUSPENDED:
connectionState = "Suspended";
break;
default:
setTextViewText(info_ids[INFO_CONNECTION_STATE_INDEX],
connectionState);
super.onDataConnectionStateChanged(state);
}
@Override
500
public void onMessageWaitingIndicatorChanged(boolean mwi) {
Log.i(APP_NAME, "onMessageWaitingIndicatorChanged " + mwi);
super.onMessageWaitingIndicatorChanged(mwi);
}
@Override
public void onServiceStateChanged(ServiceState serviceState) {
String serviceStateString = "UNKNOWN";
switch (serviceState.getState()) {
case ServiceState.STATE_IN_SERVICE:
serviceStateString = "IN SERVICE";
break;
case ServiceState.STATE_EMERGENCY_ONLY:
serviceStateString = "EMERGENCY ONLY";
break;
case ServiceState.STATE_OUT_OF_SERVICE:
serviceStateString = "OUT OF SERVICE";
break;
case ServiceState.STATE_POWER_OFF:
serviceStateString = "POWER OFF";
break;
default:
serviceStateString = "UNKNOWN";
break;
}
setTextViewText(info_ids[INFO_SERVICE_STATE_INDEX],
serviceStateString);
super.onServiceStateChanged(serviceState);
}
@Override
public void onSignalStrengthChanged(int asu) {
Log.i(APP_NAME, "onSignalStrengthChanged " + asu);
setSignalLevel(info_ids[INFO_SIGNAL_LEVEL_INDEX],
info_ids[INFO_SIGNAL_LEVEL_INFO_INDEX], asu);
super.onSignalStrengthChanged(asu);
}
};
}
LAYOUT FILE:
activity_main.xml
<?xml version="1.0" encoding="UTF-8"?>
<ScrollView android:scrollbarAlwaysDrawVerticalTrack="false"
android:scrollbarStyle="insideOverlay" android:orientation="vertical"
android:layout_height="wrap_content" android:layout_width="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
501
<TextView style="@style/labelStyleRight" android:text="Service State"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
502
android:layout_width="wrap_content" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>
Android manifest.xml
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
Video Capture
JAVA FILE:
MainActivity.java
import android.support.v7.app.AppCompatActivity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.VideoView;
503
Button captureVideoButton;
Button playVideoButton;
VideoView videoView;
Uri videoFileUri;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
LAYOUT FILE:
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Button android:text="Capture Video" android:id="@+id/CaptureVideoButton"
android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
<Button android:text="Play Video" android:id="@+id/PlayVideoButton"
android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
<VideoView android:id="@+id/VideoView" android:layout_width="wrap_content"
android:layout_height="wrap_content"></VideoView>
</LinearLayout>
Android manifest.xml
<uses-permission android:name="android.permission.RECORD_AUDIO"></uses-permission>
<uses-permission android:name="android.permission.CAMERA"></uses-permission>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
504
Image, Video & Audio
JAVA FILE:
MainActivity.java
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.support.v7.app.AppCompatActivity;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(resultCode == Activity.RESULT_OK) {
Uri selectedContent = data.getData();
if(requestCode == REQUEST_IMAGE) {
//Display the image
}
if(requestCode == REQUEST_VIDEO) {
//Play the video clip
}
if(requestCode == REQUEST_AUDIO) {
//Play the audio clip
}
}
}
@Override
public void onClick(View v) {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_GET_CONTENT);
switch(v.getId()) {
case R.id.imageButton:
intent.setType("image/*");
startActivityForResult(intent, REQUEST_IMAGE);
return;
case R.id.videoButton:
505
intent.setType("video/*");
startActivityForResult(intent, REQUEST_VIDEO);
return;
case R.id.audioButton:
intent.setType("audio/*");
startActivityForResult(intent, REQUEST_AUDIO);
return;
default:
return;
}
}
}
LAYOUT FILE:
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button
android:id="@+id/imageButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Images"
/>
<Button
android:id="@+id/videoButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Video"
/>
<Button
android:id="@+id/audioButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Audio"
/>
</LinearLayout>
*********************************************************************************************
MainActivity.java
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.widget.TextView;
506
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
/** Setting the density, width and height of the screen to the TextView object */
tvMetrics.setText("Density : "+density + "\n" + "Resolution in pixels : " +
resolution + "\nResolution in dp : " + resolution_dp );
}
}
LAYOUT FILE:
activity_main.xml
<?xml version="1.0" encoding="UTF-8"?>
</LinearLayout>
*********************************************************************************************
507
JAVA FILE:
MainActivity.java
import android.support.v7.app.AppCompatActivity;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
LAYOUT FILE:
activity_main.xml
<?xml version="1.0" encoding="UTF-8"?>
</LinearLayout>
string.xml
508
*********************************************************************************************
MainActivity.java
import android.support.v7.app.AppCompatActivity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
@Override
public void onClick(View v) {
/** Getting a reference to the textedit object of the main.xml */
EditText txt = (EditText) findViewById(R.id.te_url);
/** Start an activity that matches intent action and intent data */
startActivity(intent);
}
};
btn.setOnClickListener(listener);
}
}
LAYOUT FILE:
509
activity_main.xml
<?xml version="1.0" encoding="UTF-8"?>
</LinearLayout>
string.xml
<string name="lbl_btn_browse">Browse</string>
Android manifest.xml
<uses-permission android:name="android.permission.INTERNET"/>
******************************************************************************
Calculator
JAVA FILE:
MainActivity.java
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
EditText edt1 ;
@Override
protected void onCreate(Bundle savedInstanceState) {
510
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
edt1.setText(edt1.getText()+"1");
}
});
button2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
edt1.setText(edt1.getText()+"2");
}
});
button3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
edt1.setText(edt1.getText()+"3");
}
});
button4.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
edt1.setText(edt1.getText()+"4");
}
});
button5.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
edt1.setText(edt1.getText()+"5");
}
});
button6.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
edt1.setText(edt1.getText()+"6");
}
});
button7.setOnClickListener(new View.OnClickListener() {
511
@Override
public void onClick(View v) {
edt1.setText(edt1.getText()+"7");
}
});
button8.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
edt1.setText(edt1.getText()+"8");
}
});
button9.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
edt1.setText(edt1.getText()+"9");
}
});
button0.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
edt1.setText(edt1.getText()+"0");
}
});
buttonAdd.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (edt1 == null){
edt1.setText("");
}else {
mValueOne = Float.parseFloat(edt1.getText() + "");
mAddition = true;
edt1.setText(null);
}
}
});
buttonSub.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mValueOne = Float.parseFloat(edt1.getText() + "");
mSubtract = true ;
edt1.setText(null);
}
});
buttonMul.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mValueOne = Float.parseFloat(edt1.getText() + "");
mMultiplication = true ;
edt1.setText(null);
}
});
buttonDivision.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mValueOne = Float.parseFloat(edt1.getText()+"");
mDivision = true ;
edt1.setText(null);
}
512
});
buttonEqual.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mValueTwo = Float.parseFloat(edt1.getText() + "");
if (mAddition == true){
if (mSubtract == true){
edt1.setText(mValueOne - mValueTwo+"");
mSubtract=false;
}
if (mMultiplication == true){
edt1.setText(mValueOne * mValueTwo+"");
mMultiplication=false;
}
if (mDivision == true){
edt1.setText(mValueOne / mValueTwo+"");
mDivision=false;
}
}
});
buttonC.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
edt1.setText("");
}
});
button10.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
edt1.setText(edt1.getText()+".");
}
});
}
LAYOUT FILE:
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"
android:id="@+id/relative1">
<EditText
android:layout_width="match_parent"
513
android:layout_height="wrap_content"
android:id="@+id/edt1"/>
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1"
android:id="@+id/button1"
android:layout_marginTop="94dp"
android:layout_below="@+id/edt1"
android:layout_toStartOf="@+id/button4"
android:layout_alignRight="@+id/button4"
android:layout_alignEnd="@+id/button4" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2"
android:id="@+id/button2"
android:layout_alignTop="@+id/button1"
android:layout_toLeftOf="@+id/button3"
android:layout_toStartOf="@+id/button3" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="3"
android:id="@+id/button3"
android:layout_alignTop="@+id/button2"
android:layout_centerHorizontal="true" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="4"
android:id="@+id/button4"
android:layout_below="@+id/button1"
android:layout_toLeftOf="@+id/button2" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="5"
android:id="@+id/button5"
android:layout_alignBottom="@+id/button4"
android:layout_alignLeft="@+id/button2"
android:layout_alignStart="@+id/button2" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="6"
android:id="@+id/button6"
android:layout_below="@+id/button3"
android:layout_alignLeft="@+id/button3"
android:layout_alignStart="@+id/button3" />
<Button
style="?android:attr/buttonStyleSmall"
514
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="7"
android:id="@+id/button7"
android:layout_below="@+id/button4"
android:layout_toLeftOf="@+id/button2" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="8"
android:id="@+id/button8"
android:layout_below="@+id/button5"
android:layout_alignLeft="@+id/button5"
android:layout_alignStart="@+id/button5" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="9"
android:id="@+id/button9"
android:layout_below="@+id/button6"
android:layout_alignLeft="@+id/button6"
android:layout_alignStart="@+id/button6" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="+"
android:id="@+id/buttonadd"
android:layout_alignTop="@+id/button3"
android:layout_toRightOf="@+id/button3"
android:layout_marginLeft="46dp"
android:layout_marginStart="46dp"
android:layout_alignRight="@+id/edt1"
android:layout_alignEnd="@+id/edt1" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="-"
android:id="@+id/buttonsub"
android:layout_below="@+id/buttonadd"
android:layout_alignLeft="@+id/buttonadd"
android:layout_alignStart="@+id/buttonadd"
android:layout_alignRight="@+id/buttonadd"
android:layout_alignEnd="@+id/buttonadd" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="*"
android:id="@+id/buttonmul"
android:layout_below="@+id/buttonsub"
android:layout_alignLeft="@+id/buttonsub"
android:layout_alignStart="@+id/buttonsub"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<Button
style="?android:attr/buttonStyleSmall"
515
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="."
android:id="@+id/button10"
android:layout_below="@+id/button7"
android:layout_toLeftOf="@+id/button2" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0"
android:id="@+id/button0"
android:layout_below="@+id/button8"
android:layout_alignLeft="@+id/button8"
android:layout_alignStart="@+id/button8" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="C"
android:id="@+id/buttonC"
android:layout_below="@+id/button9"
android:layout_alignLeft="@+id/button9"
android:layout_alignStart="@+id/button9" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="/"
android:id="@+id/buttondiv"
android:layout_below="@+id/buttonmul"
android:layout_alignLeft="@+id/buttonmul"
android:layout_alignStart="@+id/buttonmul"
android:layout_alignRight="@+id/buttonmul"
android:layout_alignEnd="@+id/buttonmul" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="="
android:id="@+id/buttoneql"
android:layout_below="@+id/button0"
android:layout_marginTop="37dp"
android:layout_alignRight="@+id/buttondiv"
android:layout_alignEnd="@+id/buttondiv"
android:layout_alignLeft="@+id/button10"
android:layout_alignStart="@+id/button10" />
</RelativeLayout>
**********************************************************
Battery level
JAVA FILE:
516
MainActivity.java
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.os.BatteryManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.view.Menu;
import android.widget.TextView;
/* @Override*/
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
batteryPercent = (TextView) this.findViewById(R.id.batteryLevel);
getBatteryPercentage();
}
// @Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
LAYOUT FILE:
activity_main.xml
<?xml version="1.0"?>
</RelativeLayout>
517
**********************************************************
Airplane mode
JAVA FILE:
MainActivity.java
import android.support.v7.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.provider.Settings;
import android.view.View;
import android.widget.Toast;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@SuppressWarnings("deprecation")
public void airPlanemodeON(View v) {
boolean isEnabled = Settings.System.getInt(this.getContentResolver(),
Settings.System.AIRPLANE_MODE_ON, 0) == 1;
if (isEnabled == false) {
modifyAirplanemode(true);
Toast.makeText(getApplicationContext(), "Airplane Mode ON",
Toast.LENGTH_LONG).show();
}
}
}
}
518
LAYOUT FILE:
activity_main.xml
<?xml version="1.0" encoding="UTF-8"?>
</RelativeLayout>
Android manifest.xml
<uses-permission android:name="android.permission.WRITE_SETTINGS"/>
*************************************************************************************
MainActivity.java
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.content.Context;
import android.content.pm.PackageManager;
import android.view.Menu;
import android.widget.TextView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView value = (TextView) findViewById(R.id.res);
String result = "";
Context context = this;
PackageManager packageManager = context.getPackageManager();
if (packageManager.hasSystemFeature(PackageManager.FEATURE_CAMERA)) {
result += "Camera: YES";
}else{
result += "Camera: NO";
}
if (packageManager
519
.hasSystemFeature(PackageManager.FEATURE_CAMERA_FRONT)) {
result += "\nFront facing camera: YES";
}else{
result += "\nFront facing camera: NO";
}
if (packageManager
.hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH)) {
result += "\nCamera support flash: YES";
}else{
result += "\nCamera support flash: NO";
}
if (packageManager.hasSystemFeature(PackageManager.FEATURE_BLUETOOTH)) {
result += "\nBluetooth: YES";
}else{
result += "\nBluetooth: NO";
}
if (packageManager.hasSystemFeature(PackageManager.FEATURE_NFC)) {
result += "\nNFC: YES";
}else{
result += "\nNFC: NO";
}
if (packageManager.hasSystemFeature(PackageManager.FEATURE_MICROPHONE)) {
result += "\nMicrophone: YES";
}else{
result += "\nMicrophone: NO";
}
if (packageManager
.hasSystemFeature(PackageManager.FEATURE_SENSOR_ACCELEROMETER)) {
result += "\nAccelerometer sensor: YES";
}else{
result += "\nAccelerometer sensor: NO";
}
if (packageManager
.hasSystemFeature(PackageManager.FEATURE_SENSOR_BAROMETER)) {
result += "Barometer (air pressure sensor) :YES";
}else{
result += "Barometer (air pressure sensor) :NO";
}
if (packageManager
.hasSystemFeature(PackageManager.FEATURE_SENSOR_COMPASS)) {
result += "\nMagnetometer (compass): YES";
}else{
result += "\nMagnetometer (compass): NO";
}
if (packageManager
.hasSystemFeature(PackageManager.FEATURE_SENSOR_GYROSCOPE)) {
result += "\nGyroscope: YES";
}else{
result += "\nGyroscope: NO";
}
if (packageManager
.hasSystemFeature(PackageManager.FEATURE_SENSOR_LIGHT)) {
result += "\nLight sensor: YES";
}else{
result += "\nLight sensor: YES";
}
if (packageManager
.hasSystemFeature(PackageManager.FEATURE_SENSOR_PROXIMITY)) {
result += "\nProximity sensor: YES";
} else {
result += "\nProximity sensor: NO";
}
value.setText(result);
}
@Override
520
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
LAYOUT FILE:
activity_main.xml
<?xml version="1.0"?>
</RelativeLayout>
********************************************************************************************
MainActivity.java
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
521
WebSettings webSettings = displayYoutubeVideo.getSettings();
webSettings.setJavaScriptEnabled(true);
displayYoutubeVideo.loadData(frameVideo, "text/html", "utf-8");
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
LAYOUT FILE:
activity_main.xml
<?xml version="1.0"?>
</RelativeLayout>
Android manifest.xml
<uses-permission android:name="android.permission.INTERNET"/>
*********************************************************************************************
MainActivity.java
522
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.provider.AlarmClock;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
LAYOUT FILE:
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="alarm"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="177dp"
android:onClick="browser1" />
</LinearLayout>
Android manifest.xml
<uses-permission android:name="com.android.alarm.permission.SET_ALARM"/>
*************************************************************************************
Battery Information
JAVA FILE:
MainActivity.java
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
523
import android.content.IntentFilter;
import android.os.BatteryManager;
import android.os.Bundle;
import android.widget.TextView;
import android.support.v7.app.AppCompatActivity;
batteryLevel = (TextView)findViewById(R.id.batterylevel);
batteryVoltage = (TextView)findViewById(R.id.batteryvoltage);
batteryTemperature = (TextView)findViewById(R.id.batterytemperature);
batteryTechnology = (TextView)findViewById(R.id.batterytechology);
batteryStatus = (TextView)findViewById(R.id.batterystatus);
batteryHealth = (TextView)findViewById(R.id.batteryhealth);
this.registerReceiver(this.myBatteryReceiver,
new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
}
@Override
public void onReceive(Context arg0, Intent arg1) {
// TODO Auto-generated method stub
if (arg1.getAction().equals(Intent.ACTION_BATTERY_CHANGED)){
batteryLevel.setText("Level: "
+ String.valueOf(arg1.getIntExtra("level", 0)) + "%");
batteryVoltage.setText("Voltage: "
+ String.valueOf((float)arg1.getIntExtra("voltage", 0)/1000) + "V");
batteryTemperature.setText("Temperature: "
+ String.valueOf((float)arg1.getIntExtra("temperature", 0)/10) + "c");
batteryTechnology.setText("Technology: " + arg1.getStringExtra("technology"));
524
strHealth = "Over Heat";
} else if (health == BatteryManager.BATTERY_HEALTH_DEAD){
strHealth = "Dead";
} else if (health == BatteryManager.BATTERY_HEALTH_OVER_VOLTAGE){
strHealth = "Over Voltage";
} else if (health == BatteryManager.BATTERY_HEALTH_UNSPECIFIED_FAILURE){
strHealth = "Unspecified Failure";
} else{
strHealth = "Unknown";
}
batteryHealth.setText("Health: " + strHealth);
}
}
};
}
LAYOUT FILE:
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Battery Info."
/>
<TextView
android:id="@+id/batterylevel"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Battery Level:"
/>
<TextView
android:id="@+id/batteryvoltage"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Battery Voltage:"
/>
<TextView
android:id="@+id/batterytemperature"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Battery Temperature:"
/>
<TextView
android:id="@+id/batterytechology"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Technology:"
/>
<TextView
android:id="@+id/batterystatus"
525
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Status:"
/>
<TextView
android:id="@+id/batteryhealth"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Health:"
/>
</LinearLayout>
*******************************************************************************************
Note: If you want to change the application name (from MyApplication to MyApplication5496), you have to
replace the statement
<string name="app_name">My Application</string>
in string.xml by the statement
<string name="app_name">My Application5496</string>
*******************************************************************************************
Brightness Control
JAVA FILE:
MainActivity.java
import android.support.v7.app.AppCompatActivity;
import android.content.ContentResolver;
import android.os.Bundle;
import android.provider.Settings.SettingNotFoundException;
import android.provider.Settings.System;
import android.util.Log;
import android.view.Window;
import android.view.WindowManager.LayoutParams;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;
TextView txtPerc;
526
brightbar = (SeekBar) findViewById(R.id.brightbar);
try {
// Get the current system brightness
brightness = System.getInt(cResolver, System.SCREEN_BRIGHTNESS);
} catch (SettingNotFoundException e) {
// Throw an error case it couldn't be retrieved
Log.e("Error", "Cannot access system brightness");
e.printStackTrace();
}
// Set the progress of the seek bar based on the system's brightness
brightbar.setProgress(brightness);
527
LAYOUT FILE:
activity_main.xml
<?xml version="1.0" encoding="UTF-8"?>
</LinearLayout>
Android manifest.xml
******************************************************************************
MainActivity.java
import android.support.v7.app.AppCompatActivity;
import java.util.List;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.wifi.ScanResult;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ListView;
@Override
protected void onCreate(Bundle savedInstanceState) {
528
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnRefresh.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
scanWifiList();
}
});
}
setAdapter();
ListAdapter.java
import java.util.List;
import android.content.Context;
import android.net.wifi.ScanResult;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
Context context;
LayoutInflater inflater;
List<ScanResult> wifiList;
529
@Override
public int getCount() {
return wifiList.size();
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
Holder holder;
View view = convertView;
if (view == null) {
view = inflater.inflate(R.layout.dataset, null);
holder = new Holder();
holder.tvDetails = (TextView) view.findViewById(R.id.tvDetails);
view.setTag(holder);
} else {
holder = (Holder) view.getTag();
}
holder.tvDetails.setText("SSID :: " + wifiList.get(position).SSID
+ "\nStrength :: " + wifiList.get(position).level
+ "\nBSSID :: " + wifiList.get(position).BSSID
+ "\nChannel :: "
+ convertFrequencyToChannel(wifiList.get(position).frequency)
+ "\nFrequency :: " + wifiList.get(position).frequency
+ "\nCapability :: " + wifiList.get(position).capabilities);
return view;
}
class Holder {
TextView tvDetails;
}
}
LAYOUT FILES:
activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
530
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="${relativePackage}.${activityClass}" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.9"
android:orientation="vertical" >
<ListView
android:id="@+id/lvWifiDetails"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.1"
android:orientation="vertical" >
<Button
android:id="@+id/btnRefresh"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="5dp"
android:text="Refresh" />
</LinearLayout>
</LinearLayout>
dataset.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/tvDetails"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000000" />
</LinearLayout>
Android manifest.xml
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
531
*********************************************************************************************
Battery level in percentage (picture)
JAVA FILE:
MainActivity.java
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.widget.ProgressBar;
import android.widget.TextView;
};
LAYOUT FILE:
activity_main.xml
<?xml version="1.0" encoding="UTF-8"?>
</LinearLayout>
532
*********************************************************************************************
MainActivity.java
import android.support.v7.app.AppCompatActivity;
import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.provider.ContactsContract.Contacts;
import android.provider.ContactsContract.Intents.Insert;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.Toast;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
edtName = (EditText) findViewById(R.id.edtName);
edtNumber = (EditText) findViewById(R.id.edtPhone);
findViewById(R.id.btnInsert).setOnClickListener(this);
findViewById(R.id.btnGetContact).setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btnInsert:
Intent i = new Intent(Intent.ACTION_INSERT_OR_EDIT);
i.setType(Contacts.CONTENT_ITEM_TYPE);
i.putExtra(Insert.NAME, edtName.getText().toString());
i.putExtra(Insert.PHONE, edtNumber.getText().toString());
startActivity(i);
break;
case R.id.btnGetContact:
Intent callContactPickerIntent = new Intent(Intent.ACTION_PICK,
ContactsContract.Contacts.CONTENT_URI);
// filters contact with phone numbers
callContactPickerIntent
.setType(ContactsContract.CommonDataKinds.Phone.CONTENT_TYPE);
startActivityForResult(callContactPickerIntent, CALL_CONTACT_PICKER);
break;
default:
break;
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
533
if (resultCode == RESULT_OK) {
Cursor cursor = null;
cursor.close();
Toast.makeText(this, "Selection Fail", Toast.LENGTH_LONG)
.show();
return;
}
String contactName = cursor
.getString(cursor
.getColumnIndex((ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME)
.toString().trim()));
String contactNumber = cursor
.getString(cursor
.getColumnIndex((ContactsContract.CommonDataKinds.Phone.NUMBER)));
switch (requestCode) {
case CALL_CONTACT_PICKER:
Toast.makeText(this,
"Name :" + contactName + "Number :" + contactNumber,
Toast.LENGTH_LONG).show();
break;
default:
break;
}
cursor.close();
} else {
// gracefully handle failure
Log.w("Auto Respond", "Warning: activity result not ok");
}
}
LAYOUT FILE:
activity_main.xml
<?xml version="1.0" encoding="UTF-8"?>
534
android:hint="Name" android:id="@+id/edtName"/>
</LinearLayout>
*********************************************************************************************
IP Address
JAVA FILE:
MainActivity.java
import android.support.v7.app.AppCompatActivity;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.util.Enumeration;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.text.format.Formatter;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
Button button;
TextView textview;
String IPaddress;
Boolean IPValue;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = (Button)findViewById(R.id.button1);
textview = (TextView)findViewById(R.id.textView1);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
NetwordDetect();
535
});
ConnectivityManager CM = (ConnectivityManager)
getSystemService(Context.CONNECTIVITY_SERVICE);
if (netInfo.getTypeName().equalsIgnoreCase("WIFI"))
if (netInfo.isConnected())
WIFI = true;
if (netInfo.getTypeName().equalsIgnoreCase("MOBILE"))
if (netInfo.isConnected())
MOBILE = true;
}
if(WIFI == true)
{
IPaddress = GetDeviceipWiFiData();
textview.setText(IPaddress);
if(MOBILE == true)
{
IPaddress = GetDeviceipMobileData();
textview.setText(IPaddress);
536
Log.e("Current IP", ex.toString());
}
return null;
}
@SuppressWarnings("deprecation")
String ip = Formatter.formatIpAddress(wm.getConnectionInfo().getIpAddress());
return ip;
LAYOUT FILE:
activity_main.xml
<?xml version="1.0"?>
<RelativeLayout tools:context="com.displayipaddress_android_examples.com.MainActivity"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingBottom="@dimen/activity_vertical_margin" android:layout_height="match_parent"
android:layout_width="match_parent" xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android">
</RelativeLayout>
Android manifest.xml
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
*********************************************************************************************
537
ZoomInOut WebView
JAVA FILE:
MainActivity.java
import android.support.v7.app.AppCompatActivity;
import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;
WebView Webview;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Webview = (WebView)findViewById(R.id.webView1);
WebSettings webSetting = Webview.getSettings();
Webview.setWebViewClient(new WebViewClient());
Webview.loadUrl("http://google.com");
}
LAYOUT FILE:
activity_main.xml
<?xml version="1.0"?>
<RelativeLayout tools:context=".MainActivity"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingBottom="@dimen/activity_vertical_margin" android:layout_height="match_parent"
android:layout_width="match_parent" xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android">
538
android:id="@+id/webView1"/>
</RelativeLayout>
Android manifest.xml
<uses-permission android:name="android.permission.INTERNET"/>
*************************************************************************************
MainActivity.java
import android.support.v7.app.AppCompatActivity;
import android.content.Context;
import android.content.Intent;
import android.location.LocationManager;
import android.os.Bundle;
import android.provider.Settings;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
Button button;
Context context;
Intent intent1, intent2;
TextView textview;
LocationManager locationManager ;
boolean GpsStatus ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = (Button)findViewById(R.id.button1);
textview = (TextView)findViewById(R.id.textView1);
context = getApplicationContext();
CheckGpsStatus();
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
});
539
}
locationManager =
(LocationManager)context.getSystemService(Context.LOCATION_SERVICE);
GpsStatus = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
if(GpsStatus == true)
{
textview.setText("Location Services Is Enabled");
}else {
textview.setText("Location Services Is Disabled");
}
LAYOUT FILE:
activity_main.xml
<?xml version="1.0"?>
<RelativeLayout tools:context=".MainActivity"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingBottom="@dimen/activity_vertical_margin" android:layout_height="match_parent"
android:layout_width="match_parent" xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android">
</RelativeLayout>
Android manifest.xml
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
540
*************************************************************************************
BLUETOOTH
JAVA FILE:
MainActivity.java
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.BroadcastReceiver;
import android.content.Context;
import java.util.Set;
import android.content.Intent;
import android.content.IntentFilter;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
on(v);
541
}
});
offBtn = (Button)findViewById(R.id.turnOff);
offBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
off(v);
}
});
listBtn = (Button)findViewById(R.id.paired);
listBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
list(v);
}
});
findBtn = (Button)findViewById(R.id.search);
findBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
find(v);
}
});
myListView = (ListView)findViewById(R.id.listView1);
// create the arrayAdapter that contains the BTDevices, and set it to the ListView
BTArrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1);
myListView.setAdapter(BTArrayAdapter);
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
if(requestCode == REQUEST_ENABLE_BT){
if(myBluetoothAdapter.isEnabled()) {
text.setText("Status: Enabled");
} else {
text.setText("Status: Disabled");
}
}
}
542
public void list(View view){
// get paired devices
pairedDevices = myBluetoothAdapter.getBondedDevices();
@Override
protected void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
unregisterReceiver(bReceiver);
}
LAYOUT FILE:
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
543
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="@string/Text" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="30dp" >
<Button
android:id="@+id/turnOn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/on" />
<Button
android:id="@+id/turnOff"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/off" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginTop="80dp" >
<Button
android:id="@+id/paired"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/List" />
<Button
android:id="@+id/search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Find" />
<ListView
android:id="@+id/listView1"
android:layout_width="fill_parent"
android:layout_height="200dp" >
</ListView>
</LinearLayout>
</RelativeLayout>
String.xml
544
<string name="Text">Status: -</string>
Android manifest.xml
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
*********************************************************************************************
MainActivity.java
import android.support.v7.app.AppCompatActivity;
import android.app.Activity;
import android.content.Context;
import android.location.LocationManager;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
Button button;
TextView textview;
Context context;
LocationManager locationManager ;
boolean GpsStatus ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = (Button)findViewById(R.id.button1);
textview = (TextView)findViewById(R.id.textView1);
context = getApplicationContext();
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
CheckGpsStatus() ;
if(GpsStatus == true)
545
{
textview.setText("Location Services Is Enabled");
}else {
textview.setText("Location Services Is Disabled");
}
}
});
}
locationManager =
(LocationManager)context.getSystemService(Context.LOCATION_SERVICE);
GpsStatus = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
}
LAYOUT FILE:
activity_main.xml
<?xml version="1.0"?>
<RelativeLayout tools:context=".MainActivity"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingBottom="@dimen/activity_vertical_margin" android:layout_height="match_parent"
android:layout_width="match_parent" xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android">
</RelativeLayout>
Android manifest.xml
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
*************************************************************************************
JAVA FILE:
546
MainActivity.java
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.MediaController;
import android.widget.VideoView;
VideoView videoview ;
MediaController mediacontroller;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
videoview = (VideoView)findViewById(R.id.videoView1);
mediacontroller = new MediaController(MainActivity.this);
videoview.setVideoPath(
"http://www.android-examples.com/wp-
content/uploads/2016/01/sample_video.3gp");
mediacontroller.setAnchorView(videoview);
videoview.setMediaController(mediacontroller);
videoview.start();
}
}
LAYOUT FILE:
activity_main.xml
<?xml version="1.0"?>
</RelativeLayout>
Android manifest.xml
<uses-permission android:name="android.permission.INTERNET"/>
547
*********************************************************************************************
Play music from internet
JAVA FILE:
MainActivity.java
import android.support.v7.app.AppCompatActivity;
import java.io.IOException;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
Button buttonStop,buttonStart ;
MediaPlayer mediaplayer;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
buttonStart = (Button)findViewById(R.id.button1);
buttonStop = (Button)findViewById(R.id.button2);
buttonStart.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
try {
mediaplayer.setDataSource(AudioURL);
mediaplayer.prepare();
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
mediaplayer.start();
548
}
});
buttonStop.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
mediaplayer.stop();
}
});
}
LAYOUT FILE:
activity_main.xml
<?xml version="1.0"?>
<RelativeLayout tools:context=".MainActivity"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingBottom="@dimen/activity_vertical_margin" android:layout_height="match_parent"
android:layout_width="match_parent" xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android">
</RelativeLayout>
Android manifest.xml
<uses-permission android:name="android.permission.INTERNET"/>
*************************************************************************************
MainActivity.java
549
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
model = (TextView)findViewById(R.id.textView1);
device = (TextView)findViewById(R.id.textView2);
getboth = (Button)findViewById(R.id.button1);
getboth.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
DeviceModel= android.os.Build.MODEL;
DeviceName= android.os.Build.MANUFACTURER;
model.setText(DeviceModel);
device.setText(DeviceName);
}
});
}
}
LAYOUT FILE:
activity_main.xml
<?xml version="1.0"?>
<RelativeLayout tools:context=".MainActivity"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingBottom="@dimen/activity_vertical_margin" android:layout_height="match_parent"
android:layout_width="match_parent" xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android">
</RelativeLayout>
*************************************************************************************
MainActivity.java
import android.support.v7.app.AppCompatActivity;
import android.content.Context;
import android.media.AudioManager;
import android.os.Bundle;
import android.widget.SeekBar;
alarm = (SeekBar)findViewById(R.id.seekBar1);
mediaPlayer = (SeekBar)findViewById(R.id.seekBar2);
ringer = (SeekBar)findViewById(R.id.seekBar3);
notification = (SeekBar)findViewById(R.id.seekBar4);
alarm.setMax(audioManager.getStreamMaxVolume(AudioManager.STREAM_ALARM));
mediaPlayer.setMax(audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC));
ringer.setMax(audioManager.getStreamMaxVolume(AudioManager.STREAM_RING));
notification.setMax(audioManager.getStreamMaxVolume(AudioManager.STREAM_NOTIFICATION));
alarm.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
audioManager.setStreamVolume(AudioManager.STREAM_ALARM, i, 0);
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
@Override
551
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
mediaPlayer.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, i, 0);
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
ringer.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
audioManager.setStreamVolume(AudioManager.STREAM_RING, i, 0);
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
notification.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
audioManager.setStreamVolume(AudioManager.STREAM_NOTIFICATION, i, 0);
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
}
}
LAYOUT FILE:
552
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="Set Alarm Volume"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_marginTop="10dp" />
<SeekBar
android:id="@+id/seekBar1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/textView1"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/seekBar1"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:text="Set Media Player Volume"
android:textAppearance="?android:attr/textAppearanceLarge" />
<SeekBar
android:id="@+id/seekBar2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/textView2"
android:layout_marginTop="10dp" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/seekBar2"
android:layout_centerHorizontal="true"
android:text="Set Ringer Volume"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_marginTop="10dp" />
<SeekBar
android:id="@+id/seekBar3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginTop="10dp" />
553
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/seekBar3"
android:layout_centerHorizontal="true"
android:text="Set Notification Volume"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_marginTop="10dp" />
<SeekBar
android:id="@+id/seekBar4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/textView4"
android:layout_marginTop="10dp" />
</RelativeLayout>
*************************************************************************************
JAVA FILE:
MainActivity.java
554
import android.content.Intent;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.widget.EditText;
});
555
//perform Browser open action
@Override
public void onClick(View v) {
}
});
}
}
556
LAYOUT FILE:
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/black"
android:orientation="vertical" >
<!-- EDIT TEXT with the hint of "Enter Phone No." -->
<EditText
android:id="@+id/etNo"
android:layout_width="match_parent"
android:layout_height="60dp"
android:hint="Enter phone no."
android:inputType="phone" />
557
android:layout_height="55dp"
android:text="Dialpad" />
</LinearLayout>
Android manifest.xml
*********************************************************************************************
Bill Gates
Co-Founder & Technology Advisor, Microsoft Corporation
Mark Zuckerberg
Chairman and CEO, Facebook, Inc.
*********************************************************************************************
MainActivity.java
import android.content.Intent;
import android.content.res.AssetManager;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.content.Context;
import android.util.Log;
558
;import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
InputStream in = null;
OutputStream out = null;
File file = new File(getFilesDir(), "006JavaScript.pdf");
try {
in = assetManager.open("006JavaScript.pdf");
out = openFileOutput(file.getName(), Context.MODE_WORLD_READABLE);
copyPdfFile(in, out);
in.close();
in = null;
out.flush();
out.close();
out = null;
} catch (Exception e) {
Log.e("exception", e.getMessage());
}
startActivity(intent);
}
Android manifest.xml
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
559
*********************************************************************************************
MainActivity.java
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import android.app.ExpandableListActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ExpandableListAdapter;
import android.widget.ExpandableListView;
import android.widget.ExpandableListView.OnChildClickListener;
import android.widget.SimpleExpandableListAdapter;
import android.widget.Toast;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
/* ***ChildData ***/
Map<String, String> curChildMap4 = new HashMap<String, String>();
children1.add(curChildMap4);
curChildMap4.put("child", "State");
/* ***ChildData ***/
Map<String, String> curChildMap5 = new HashMap<String, String>();
children1.add(curChildMap5);
curChildMap5.put("child", "City");
560
childData.add(children1);
childData.add(children2);
expand = getExpandableListView();
expand.setOnChildClickListener(new OnChildClickListener() {
@Override
public boolean onChildClick(ExpandableListView parent, View v,
int groupPosition, int childPosition, long id) {
// TODO Auto-generated method stub
switch (groupPosition)
{
case 0 :
switch(childPosition)
{
case 0 :
Toast.makeText(getBaseContext(), "Bank",
Toast.LENGTH_SHORT).show();
break;
case 1:
Toast.makeText(getBaseContext(), "Executive",
Toast.LENGTH_SHORT).show();
break;
561
case 2:
Toast.makeText(getBaseContext(), "Customer",
Toast.LENGTH_SHORT).show();
break;
case 3 :
Toast.makeText(getBaseContext(), "State",
Toast.LENGTH_SHORT).show();
break;
case 4 :
Toast.makeText(getBaseContext(), "City",
Toast.LENGTH_SHORT).show();
break;
}
break;
case 1:
switch(childPosition)
{
case 0 :
Toast.makeText(getBaseContext(), "Android",
Toast.LENGTH_SHORT).show();
break;
case 1:
Toast.makeText(getBaseContext(), "iPhone",
Toast.LENGTH_SHORT).show();
break;
case 2:
Toast.makeText(getBaseContext(), "Windows",
Toast.LENGTH_SHORT).show();
break;
}
break;
}
return false;
}
});
}
}
LAYOUT FILE:
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</RelativeLayout>
*********************************************************************************************************************
Note:
562
3. AndroidManifest.xml file stores essential information about the android application and provides essential
information about your app to the Android system, information the system must have before it can run any
of the app's code.
*********************************************************************************************
SQL
Sql: Structured query language – a computer language developed by American computer scientists Donald D.
Chamberlin and Raymond F. Boyce at IBM in 1974 to create database, store, manipulate, delete and retrieve data
stored in database.
First you have to open MYSQL terminal and then you have to enter the command:
or
will be displayed on the console screen indicating that database named data is created. And if you enter the
command:
show databases;
+--------------------
+
| Database |
+--------------------
+
| CODINGGROUND |
| data |
| information_schema |
| mysql |
| performance_schema |
| test
563
will be displayed on the console screen. And if you want to create a table in the database “data”, then you have to
enter the command:
use data;
Database changed
will be displayed on the console screen stating that your active database is now “data”. And if you want to create a
table named "states" with three fields: id, state, and population:
in your active database named “data”, then you have to enter the command:
CREATE TABLE states (id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, state CHAR(25), population INT(9));
will be displayed on the console screen stating that the above table is created.
Note:
The INT command will make the id field contain only numbers (i.e., integers).
The NOT NULL command makes sure that the id field cannot be left blank / empty.
The PRIMARY KEY designates the id field as the key field in the table.
The AUTO_INCREMENT command will automatically assign increasing values into the id field, essentially automatically numbering
each entry.
The CHAR(characters) and INT(integers) commands designate the types of data allowed in those fields. The number next to the
commands CHAR and INT indicate how many characters or integers can fit in the field.
Now it’s time to start entering your information. Use the following command:
INSERT INTO states (id, state, population) VALUES (NULL, 'Karnataka', 256666); INSERT INTO states
(id, state, population) VALUES (NULL, 'Assam', 2568585); INSERT INTO states (id, state, population)
VALUES (NULL, 'Kashmir', 2569);
564
Query OK, 1 row affected (0.03 sec)
will be displayed on the console screen stating that you have inputted your entry. And if you enter the following
command:
select*from states;
Then, your created table named “states” will be displayed on the screen as follows:
+----+-----------+------------
+
| id | state | population |
+----+-----------+------------
+
| 1 | Karnataka | 256666 |
| 2 | Assam | 2568585 |
| 3 | Kashmir | 2569 |
+----+-----------+------------+
+----+-----------+------------+----------
+
+----+-----------+------------+----------
+
CREATE TABLE states (id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, state CHAR (25),
population INT (9), language CHAR (25));
565
will be displayed on the console screen and then you should enter the following command:
INSERT INTO states (id, state, population, language) VALUES (NULL, 'Karnataka', 256666, 'Kannada');
INSERT INTO states (id, state, population, language) VALUES (NULL,'Assam',2569,'Assami');
will be displayed on the console screen and if you enter the command:
select*from states;
*********************************************************************************************
Then
state | population |
+----------------+------------
+
| Karnataka | 2562 |
| assam | 25695 |
will be displayed on the console screen. And if you enter the command:
Then
| state |
+----------------
+
| Karnataka |
| assam
********************************************************************************************
566
If you enter the command:
Then
+----+-----------+------------+----------+-----------
+
+----+-----------+------------+----------+-----------
+
Then
+----+-------+------------+----------+---------
+
+----+-------+------------+----------+---------
+
*******************************************************************************************
or
Then
+----+-----------+------------+----------
+
+----+-----------+------------+----------
+
567
| 1 | Karnataka | 2566 | Kannada |
+----+-----------+------------+----------+
+----+-----------+------------+----------
+
+----+-----------+------------+----------
+
*********************************************************************************************
INSERT INTO states (id, state, population, language) VALUES (NULL, 'tamil nadu', 288,'tamil');
Then
+----+------------+------------+----------
+
+----+------------+------------+----------
+
+----+------------+------------+----------+
*********************************************************************************************
568
UPDATE INFORMATION
If you enter the command:
update states set language =' telagu', population = 1 where state ='Karnataka';
Then
will be displayed on the console screen. And if you enter the command:
select*from states;
Then
+----+------------+------------+----------
+
+----+------------+------------+----------
+
| 1 | Karnataka | 1 | telagu |
+----+------------+------------+----------
+
*********************************************************************************************
DELETE information
If you enter the command:
Then
569
will be displayed on the console screen. And if you enter the command:
select*from states;
Then
+----+------------+------------+----------
+
+----+------------+------------+----------
+
| 1 | Karnataka | 1 | telagu |
+----+------------+------------+----------
+
********************************************************************************************
Then
will be displayed on the console screen stating that database “dbtest” is deleted from MYSQL.
If want to delete table “states” from database “dbtest”.Then you have to enter the command:
Then
will be displayed on the console screen stating that table “states” is deleted from database “dbtest”.
********************************************************************************************
Then
+----+------------+------------+----------
+
Then
+----+------------+------------+----------
+
*********************************************************************************************
(Brian Kernigan)
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.”
Send EMAIL
JAVA FILE:
MainActivity.java
571
import android.support.v7.app.AppCompatActivity;
import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
Button Send;
EditText TO, CC, SUBJECT, MSG;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Send.setOnClickListener(new View.OnClickListener() {
String to = TO.getText().toString();
String cc = CC.getText().toString();
String subject = SUBJECT.getText().toString();
String msg = MSG.getText().toString();
TO.setText(null);
CC.setText(null);
SUBJECT.setText(null);
MSG.setText(null);
}
});
}
emailIntent.setData(Uri.parse("mailto:"));
String to = emailAddresses;
String cc = carbonCopies;
emailIntent.putExtra(Intent.EXTRA_EMAIL, to);
emailIntent.putExtra(Intent.EXTRA_CC, cc);
emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
emailIntent.putExtra(Intent.EXTRA_TEXT, message);
emailIntent.setType("message/rfc822");
startActivity(Intent.createChooser(emailIntent, "Email"));
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
572
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
}
LAYOUT FILE:
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<EditText
android:id="@+id/editText1"
android:hint="To"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="50dp"
android:ems="13"
android:inputType="textEmailAddress" >
<requestFocus />
</EditText>
<EditText
android:id="@+id/editText2"
android:hint="cc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="100dp"
android:ems="13"
android:inputType="textEmailAddress" />
<EditText
android:id="@+id/editText3"
android:hint="Subject"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="150dp"
android:ems="13" />
<EditText
android:id="@+id/editText4"
android:hint="Message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="200dp"
android:ems="13"
android:inputType="textMultiLine" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
573
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="280dp"
android:text="Send E-Mail" />
</RelativeLayout>
Android manifest.xml
<uses-permission android:name="android.permission.INTERNET"/>
********************************************************************************************
MainActivity.java
import android.annotation.TargetApi;
import android.os.Build;
import android.support.v7.app.AppCompatActivity;
import java.util.Calendar;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
@Override
public void onClick(View arg0) {
});
574
intent.putExtra("beginTime", cal.getTimeInMillis());
intent.putExtra("allDay", true);
intent.putExtra("rrule", "FREQ=YEARLY");
intent.putExtra("endTime", cal.getTimeInMillis()+60*60*1000);
intent.putExtra("title", "Test Event");
intent.putExtra("description", "This is a sample description");
startActivity(intent);
}
}
LAYOUT FILE:
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TextView
android:id="@+id/txt1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Android Calender" />
<Button
android:id="@+id/btn1"
android:layout_below="@+id/txt1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/event" />
</RelativeLayout>
Android manifest.xml
String.xml
<string name="event">Add Calender Event</string>
*********************************************************************************************
MainActivity.java
575
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
LAYOUT FILE:
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ViewFlipper
android:id="@+id/viewflipper"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autoStart="true"
android:flipInterval="2000" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/picture1" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/picture2" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/picture3" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/picture4" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/picture4" />
</ViewFlipper>
</RelativeLayout>
*********************************************************************************************
576
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:orientation="vertical"
tools:context=".MainActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello"
android:textStyle="bold|italic"
android:layout_gravity="center_horizontal" />
<TextView
android:id="@+id/shadowtext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="http://android-er.blogspot.com/"
android:textStyle="bold"
android:textSize="50sp"
android:textColor="#0000ff"
android:focusable="true"
android:focusableInTouchMode="true"
android:singleLine="true"
android:scrollHorizontally="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit ="marquee_forever" />
</LinearLayout>
*********************************************************************************************
JAVASCRIPT
JavaScript / Jscript (designed by an American A simple javascript program to print the word
technologist and co-founder of the Mozilla project, “Hello World!” on screen:
the Mozilla Foundation, and the Mozilla Corporation <!DOCTYPE html>
“Brendan Eich”) is an relatively popular object- <html>
oriented scripting interpreted programming language <body>
imbedded in high level programming language of <script>
HyperText Markup Language ( the language that document.write("Hello World!");
websites are rendered in and basically, everything </script>
you and your readers see on the "front-end" is </body>
HTML), commonly abbreviated as HTML pages – </html>
primarily used to design interactive websites with In the above example,
dynamic content and perform functions that the <!DOCTYPE html> <html> <body>
HTML cannot do, because of its reliability, simplicity
and easy to understand, easy to use, write, modify </body>
and debug and quick to learn. </html> denote HTML document and
577
<script> document.write("Hello World!");
document.write("Hello World!"); document.write("Hello World!");
</script> </script>
denote Javascript code to print out the string “Hello </body>
World!” on screen. In the above example, </html>
document.write → denote function or method which
print out the string “Hello World!” on the console Output on the screen:
screen. Hello World!Hello World!
If you fail to include the tag (b)
<script> <!DOCTYPE html>
</script> in the above example i.e., <html>
<!DOCTYPE html> <body>
<html> <script>
<body> document.write("\nHello World!");
document.write("Hello World!"); document.write("\nHello World!");
</body> </script>
</html> </body>
Then </html>
document.write("Hello World!"); Output on the screen:
will be outputted on the screen instead of Hello Hello World! Hello World!
World!. (c)
If you replace the text within the double quotation <!DOCTYPE html>
marks by the word “hello” <html>
i.e., <body>
<!DOCTYPE html> <script>
<html> document.write("<br>Hello World!</br>");
<body> document.write("Hello World!");
document.write("hello"); </script>
</body> </body>
</html> </html>
Then the output on the screen is: Output on the screen:
hello
Note: Hello World!
Even if you write <SCRIPT> </SCRIPT> instead Hello World!
of <script> </script>. There will be no change (d)
in the output on the screen. But if you write <!DOCTYPE html>
Document.write("hello"); instead of <html>
document.write("hello"); <body>
There will be no display of the output on the screen. <script>
Program 1.1 document.write("<br>Hello World!</br>");
(a) document.write("<br>Hello World!</br>");
<!DOCTYPE html> </script>
<html> </body>
<body> </html>
<script> Output on the screen:
Hello World!
578
y = 200;
Hello World! z = x+ y;
document.write(" The sum of two numbers is: " + z);
(e) </script>
<!DOCTYPE html> </body>
<html> </html>
<body>
Output on the screen:
<script>
A typical arithmetic operation takes two numbers and
document.write("<b><br>Hello World!</br></b>");
produces a new number.
document.write("<br>Hello World!</br>"); The sum of two numbers is: 200
</script> The statements
</body> var x ;
</html> var y ;
Output on the screen: var z ;
imply: that we are creating the variables x, y & z.
Hello World! The statements
x=100;
Hello World! y = 200;
z = x+ y;
(f) imply that we are assigning the values to the created
<!DOCTYPE html> variables (i.e., we are assigning the value 100 for x
<html> and 100 for y and x + y for z).
<body> The statement
<script> document.write(" The sum of two numbers is: " + z);
document.write("<i><b><br>Hello make provision to print the output:
World!</br></b></i>"); The sum of two numbers is: 200
document.write("<br>Hello World!</br>"); on the screen.
</script> In the statement
document.write(" The sum of two numbers is: " + z);
</body>
There are two strings:
</html>
1. The sum of two numbers is:
Output on the screen:
2. z
Hello World! plus operator (+) functions as the concatenation
operator (concatenation means connecting two
Hello World! statements to produce a single statement) – which
(here) concatenates the string “The sum of two numbers
Program 1.2 is: ” and the string “z (which is 100+ 100 =200)” --
Javascript program to add two numbers: producing a String statement
<!DOCTYPE html> The sum of two numbers is: 200, which is displayed on
<html> the screen as the result.
<body> The statement
<p>A typical addition operation adds two numbers and
<p>A typical addition operation adds two numbers and
produces a new number.</p>
produces a new number.</p>
<script>
make provision to print the output:
var x ;
A typical arithmetic operation takes two numbers and
var y;
produces a new number.
var z;
x=100;
on the screen.
579
Note: Program 1.4
If the statement Javascript program to divide two numbers:
<p>A typical addition operation adds two numbers and
produces a new number.</p> <!DOCTYPE html>
is replaced by the statement <html>
<h>A typical addition operation adds two numbers and <body>
produces a new number.</h> <p>A typical division operation divides two numbers and
Then the output on the screen is: produces a new number.</p>
A typical arithmetic operation takes two numbers and <script>
produces a new number. The sum of two numbers is: 200 var x ;
If the statement var y;
<p>A typical addition operation adds two numbers and var z;
produces a new number.</p> x=300;
is replaced by the statement y = 200;
<h1>A typical addition operation adds two numbers and z = x/ y;
produces a new number.</h1> document.write(" The division of two numbers is: " + z);
</script>
Then the output on the screen is:
</body>
A typical arithmetic operation takes two </html>
numbers and produces a new number. Output on the screen:
The sum of two numbers is: 200 A typical division operation divides two numbers and
produces a new number.
Program 1.3 The division of two numbers is: 1.5
Javascript program to subtract two numbers:
Program 1.5
<!DOCTYPE html> Javascript program to multiply two numbers:
<html>
<body> <!DOCTYPE html>
<h1>A typical subtraction operation subtracts two numbers <html>
and produces a new number.</h1> <body>
<script> <p>A typical multiplication operation multiplies two
var x ; numbers and produces a new number.</p>
var y; <script>
var z; var x ;
x=300; var y;
y = 200; var z;
z = x- y; x=300;
document.write(" The difference of two numbers is: "+ y = 200;
z); z = x* y;
</script> document.write(" The multiplication of two numbers is:
</body> " + z);
</html> </script>
Output on the screen: </body>
A typical subtraction operation subtracts </html>
two numbers and produces a new Output on the screen:
number.
A typical multiplication operation multiplies two
The difference of two numbers is: 100
numbers and produces a new number.
The multiplication of two numbers is: 60000
580
<html>
Program 1.5 <body>
Javascript program to find the area of a circle <script>
var x ;
<!DOCTYPE html> var z;
<html> x=4;
<body> z = x*x;
<script> document.write(" The square of a number z is: " + z);
var r ; </script>
var area; </body>
r=3; </html>
area = 4*3.14* r* r;
document.write(" The area of the circle is: " + area Output on the screen:
+"\ncentimeter square"); The square of a number z is: 16
</script>
</body> If the statement z = x*x; is replaced by z =
</html> Math.pow((x), 2);
Output on the screen: i.e., if the above program is rewritten as:
The area of the circle is: 113.03999999999999 <!DOCTYPE html>
centimeter square <html>
<body>
<script>
var x ;
Program 1.6
var z;
Javascript program to find the square root of a
x=4;
number z = Math.pow((x), 2);
document.write(" The square of a number z is: " + z);
<!DOCTYPE html>
</script>
<html> </body>
<body> </html>
<script>
var x ; Then there will be no change in the output on the
var z; screen i.e.,
x=4; The square of a number z is: 16 will be outputted on
z = Math.sqrt(x); the screen.
document.write(" The square root of a number z is: " Which means:
+ z); z = pow((x), 2); is the same as z = x*x;
</script>
</body>
</html> Program 1.8
Javascript program to find the cube root of a number
Output on the screen:
<!DOCTYPE html>
The square root of a number z is: 2
<html>
Program 1.7 <body>
Javascript program to find the square of a number <script>
var x ;
<!DOCTYPE html> var z;
581
x=4; y=6;
z = Math.cbrt(x); z=x+1;
document.write(" The cube root of a number z is: " + p=x-1;
z); a = y+1;
</script> b= y-1;
</body> document.write(" The incremented value of x is: " +
</html> z);
document.write(" The decremented value of x is: " +
Output on the screen: p);
The cube root of a number z is: 1.5874010519681996 document.write(" The incremented value of y is: " +
a);
Program 1.9 document.write(" The decremented value of y is: " +
Javascript program to round off a number b);
</script>
<!DOCTYPE html>
</body>
<html>
</html>
<body>
<script>
Output on the screen:
var x ;
The incremented value of x is: 5 The decremented
var z;
value of x is: 3 The incremented value of y is: 7 The
x=4.5;
decremented value of y is: 5
z = Math.round(x);
document.write(" The round off a number z is: " + z); Program 2.0
</script> Javascript program to find the greatest of two
</body> numbers using if – else statement
</html>
The syntax of if – else statement is:
Output on the screen:
The round off a number z is: 5 if (this condition is true)
{
Program 2.0 print this statement using document.write function;
Javascript program to find the incremented and }
decremented values of two numbers. else
{
print this statement using document.write function;
}
<!DOCTYPE html>
<html>
<!DOCTYPE html>
<body>
<html>
<script>
<body>
var x ;
<script>
var y;
var x ;
var z;
var y;
var p;
x=4;
var a;
y=6;
var b;
if(x>y){
x=4;
582
document.write(" x is greater than y"); z=12;
} else {
document.write(" y is greater than x"); if(x>y&&x>z){
}
document.write(" x is greater than y and z");
</script>
</body> } else if (y>x&&y>z)
</html>
{
Output on the screen:
y is greater than x document.write(" y is greater than x and z");
} else {
Program 2.1 document.write(" z is greater than x and y");
Javascript program to find the greatest of three
numbers using if –else if – else statement }
x=4; for (i=1; i<=10; i++) denote the for loop statement
and the syntax of the for loop statement is:
y=6; for (initialization; condition; increment)
Here:
583
i=1 denote initialization (i.e., from where to start) i= 4+1 = 5
i<=10 denote the condition (i.e., stop when 10 is The statement document.write(" " + i); make
reached) provision to print the output:
i++ imply increment (which tells the value of i to 5
increase by 1 each time the loop is executed) and i++ Now, the value of i is:
is the same as i+1. i= 5
Since the initialization i.e., i=1 Is the condition (i<=10) is true?
The statement document.write(" " + i); make Yes because i=5
provision to print the output: Do this
1 i= 5+1 = 6
on the screen. The statement document.write(" " + i); make
After this, the following execution takes place: provision to print the output:
value of i 6
i= 1 Now, the value of i is:
Is the condition (i<=10) is true? i= 6
Yes because i=1 Is the condition (i<=10) is true?
Do this Yes because i=6
i= 1+1 = 2 Do this
The statement i= 6+1 = 7
document.write(" " + i); make provision to print the The statement document.write(" " + i); make
output: provision to print the output:
2 7
Now, the value of i is: Now, the value of i is:
i= 2 i= 7
Is the condition (i<=10) is true? Is the condition (i<=10) is true?
Yes because i=2 Yes because i=7
Do this Do this
i= 2+1 = 3 i= 7+1 = 8
The statement document.write(" " + i); make The statement document.write(" " + i); make
provision to print the output: provision to print the output:
3 8
Now, the value of i is: Now, the value of i is:
i= 3 i= 8
Is the condition (i<=10) is true? Is the condition (i<=10) is true?
Yes because i=3 Yes because i=8
Do this Do this
i= 3+1 = 4 i= 8+1 = 9
The statement document.write(" " + i); make The statement document.write(" " + i); make
provision to print the output: provision to print the output:
4 9
Now, the value of i is: Now, the value of i is:
i= 4 i= 9
Is the condition (i<=10) is true? Is the condition (i<=10) is true?
Yes because i=4 Yes because i=9
Do this Do this
584
i= 9+1 = 10 var i ;
The statement document.write(" " + i); make for (i=1; i<=10; i++)
provision to print the output: document.write("<br> javascript </br>");
</script>
10
</body>
stop because the condition i<=10 is achieved.
</html>
Then there will be no display of output on the screen. The syntax of while loop statement is:
7 Program 2.4
Javascript program to print the first nine natural
8 numbers using do while loop statement
do
10
{
What will be the output of the following program: execute this statement;
}
<!DOCTYPE html> while(this is the condition);
<html>
<body> <!DOCTYPE html>
<script>
585
<html> (a)
<body>
<script> <!DOCTYPE html>
var i=1 ; <html>
do{ <body>
document.write(" " + i++);} while (i<10) <script>
</script>
</body> var ch ='2';
</html> switch(ch)
{
Output on the screen: case '1':
123456789 document.write("Red");
break;
Program 2.6 case '2':
document.write("White");
Javascript program to print the average of the first10 break;
numbers using for loop statement case '3':
document.write("Yellow");
<!DOCTYPE html> break;
<html> case '4':
<body> document.write("Green");
<script> break;
var i, avg, sum = 0; default:
for( i=1; i<=10; i++) document.write("Error");
sum = sum + i; break;
avg = sum/10; }
document.write("<br> sum of the first 10 numbers =
</br>" + sum); </script>
document.write("<br> average of the first10 numbers </body>
= </br>" + avg); </html>
</script>
</body> Output on the screen:
</html> White
586
document.write("elephant");
break; </script>
case 'reptiles': </body>
document.write("crocodile"); </html>
break;
case 'birds': Output on the screen:
document.write("parrot"); 7
break;
case 'mammals':
document.write("cow");
“ It's hard enough to find an error in your code when
break;
you're looking for it; it's even harder when you've
default:
assumed your code is error-free. ” - Steve
document.write("Error");
McConnell.
break;
} What is the mistake in the following program:
function addition(a, b) {
*********************************************************************************************
Text view
(a) Javascript program to print the output:
587
Mc2 = m0c2 + KE
KE = kinetic energy
Enter E=mc2. This seemingly simple algebraic formula represents the correlation of energy to matter (energy
equivalence of any given amount of mass). Many have heard of it, but not very many understand what it
implies. Many people are unaware of just how much energy is contained within matter. So, for the next few
minutes, I will attempt to convey to you the magnitude of your own personal potential energy equivalence.
First, we must break down this equation. What do each of the letters mean? What are their values? Let’s break it
down from left to right:
<!DOCTYPE html>
<html>
<body>
<center>
<h1> <b> <i> <font size="56" face="times" color="green"> Mc <sup> 2 </sup> = m <sub> 0 </sub> c
<sup> 2 </sup> + KE </font> </i> </b> </h2>
</center>
<p><font size="5" face="calibri" color="black" > <div style="margin-top: 19px"> Where Mc <sup> 2
</sup> = total energy </div> </font> </p>
<sup> 2 </sup>. This seemingly simple algebraic formula represents the correlation of energy to
matter (energy equivalence of any given amount of mass). Many have heard of it, but not very many
understand what it implies. Many people are unaware of just how much energy is contained within
matter. So, for the next few minutes, I will attempt to convey to you the magnitude of your own
personal potential energy equivalence.
588
</font> </p>
<p><font size="5" face="calibri" color="black">First, we must break down this equation. What do
each of the letters mean? What are their values? Let’s break it down from left to right: </p>
</body>
</html>
Image view
<!DOCTYPE html>
<html>
<body>
</body>
</html>
*********************************************************************************************
Note:
GO to GOOGLE images → select an image →view image →right click on it → select Inspect
→ you will find the url address of the image.
*********************************************************************************************
Video display
<!DOCTYPE html>
<html>
<body>
<center>
</iframe>
</center>
</body>
</html>
*****************************************************************************
CALCULATOR
<!DOCTYPE html>
<html>
<body>
<FORM NAME="Calc">
<center>
<TABLE BORDER=4>
<TR>
<TD>
<br>
</TD>
</TR>
<TR>
<TD>
<br>
590
<INPUT TYPE="button" NAME="six" VALUE=" 6 " OnClick="Calc.Input.value += '6'">
<br>
<br>
<br>
</TD>
</TR>
</TABLE>
</center>
</FORM>
</body>
</html>
*********************************************************************************************
<html>
<body>
<form>
<select name="menu">
591
<option value="http://www.msn.com/">MSN</option>
<option value="http://www.google.com/">Google</option>
</select>
</form>
</body>
</html>
*********************************************************************************************
<!DOCTYPE html>
<html>
<title>W3.CSS</title>
<style>
.mySlides {display:none;}
</style>
<body>
592
</div>
<script>
var myIndex = 0;
carousel();
function carousel() {
var i;
var x = document.getElementsByClassName("mySlides");
x[i].style.display = "none";
myIndex++;
x[myIndex-1].style.display = "block";
</script>
</body>
</html>
*********************************************************************************************
<html>
<head>
<style style="text/css">
593
.example1 {
height: 50px;
overflow: hidden;
position: relative;
.example1 p3 {
position: absolute;
width: 100%;
height: 100%;
margin: 0;
line-height: 50px;
text-align: center;
/* Starting position */
-moz-transform:translateX(100%);
-webkit-transform:translateX(100%);
transform:translateX(100%);
@-moz-keyframes example1 {
0% { -moz-transform: translateX(100%); }
@-webkit-keyframes example1 {
0% { -webkit-transform: translateX(100%); }
594
@keyframes example1 {
0% {
transform: translateX(100%);
100% {
transform: translateX(-100%);
</style>
</head>
<body>
<div class="example1">
</div>
</body>
</html>
Note:
What if h3 is replaced by p3
*****************************************************************************
Image button
<div style="position: absolute; center: 10px; top: 50px;">
<img src="http://www.google.com/logos/doodles/2015/googles-new-logo-5078286822539264.3-
hp2x.gif" width="114" height="38" onclick=
"window.open('http://www.google.com','name','width=200,height=200')" />
</div>
595
<div style="position: absolute; left: 112px; top: 50px;">
<img src="http://www.nlbilearningcenter.org/wp-content/uploads/2013/03/facebook-logo.gif"
width="114" height="38" onclick=
"window.open('http://www.facebook.com','name','width=200,height=200')" />
</div>
<img src="http://dpmcltd.co.uk/m-tec2013/wp-content/uploads/2013/04/Twitter-Logo.png"
width="100" height="48" onclick=
"window.open('http://www.twitter.com','name','width=200,height=200')" />
</div>
*****************************************************************************
Copy your Html / JavaScript codes to notepad and save it as .html and open
this .html file with Google chrome.
*****************************************************************************
LINUX
Open source operating system (the most important technology advancement of the twenty-first century and Licensed
under General Public License (GPL) that Linux uses ensures that the software will always be open to anyone)
originally created as a labor of love by Linus Torvalds (computer science student at the University of Helsinki in
Finland) in the early 1990s and later developed by more than a thousand people around the world – that runs your
computer, handling all interactions between you and the hardware.
LINUX COMMANDS
1. date → display date and time
2. cal → display calendar
3. shutdown → shutdown the operating system
4. clear→ clear / empty the screen
5. exit→ exit and get to login page
6. passwd → change user password
7. free → free memory information
************************************************************************************************
Information bar
<!DOCTYPE html>
596
<html>
<head>
<style type="text/css">
#information_bar{
position: fixed;
left: 0;
width: 100%;
text-indent: 5px;
padding: 10px 0;
background-color: antiquewhite;
color:#000000;
</style>
<script type="text/javascript">
//for information_bar
function information_bar(){
this.displayfreq="always"
this.content='<a href="javascript:information_bar.close()"><img
src="http://findicons.com/files/icons/766/base_software/256/close_box_red.png" style="width:
24px; height: 24px; float: right; border: 0; margin-right: 5px" /></a>'
//set content
information_bar.prototype.setContent=function(data){
this.content=this.content+data
597
document.write('<div id="information_bar" style="top: -500px">'+this.content+'</div>')
//animation to view
information_bar.prototype.animatetoview=function(){
var barinstance=this
if (parseInt(this.barref.style.top)<0){
this.barref.style.top=parseInt(this.barref.style.top)+5+"px"
setTimeout(function(){barinstance.animatetoview()}, 50)
else{
this.barref.style.setExpression("top", 'document.compatMode=="CSS1Compat"?
document.documentElement.scrollTop+"px" : body.scrollTop+"px"')
else
this.barref.style.top=0
information_bar.close=function(){
document.getElementById("information_bar").style.display="none"
if (this.displayfreq=="session")
document.cookie="infobarshown=1;path=/"
//setting frequency
information_bar.prototype.setfrequency=function(type){
this.displayfreq=type
//for initializing
information_bar.prototype.initialize=function(){
598
this.barref=document.getElementById("information_bar")
this.barheight=parseInt(this.barref.offsetHeight)
this.barref.style.top=this.barheight*(-1)+"px"
this.animatetoview()
window.onunload=function(){
this.barref=null
</script>
<!---Execute-->
<script type="text/javascript">
//infobar.setfrequency('session') //Uncomment this line to set once the information bar per
browser session.
infobar.initialize()
</script>
<body>
</body>
</html>
*****************************************************************************
Web Link
<p>Video courtesy of <a href="http://www.bigbuckbunny.org/" target="_blank"> Buck Bunny</a>.</p>
*****************************************************************************
<!DOCTYPE html>
599
<html>
<title>W3.CSS</title>
<body>
</div>
<script>
var slideIndex = 1;
showDivs(slideIndex);
function plusDivs(n) {
showDivs(slideIndex += n);
function showDivs(n) {
var i;
var x = document.getElementsByClassName("mySlides");
x[i].style.display = "none";
x[slideIndex-1].style.display = "block";
</script>
</body>
</html>
*********************************************************************************************
<html>
<head>
<style type="text/css">
body {
color:blue;
#jsalarmclock{
font-family: Tahoma;
font-weight: bold;
font-size: 12px;
#jsalarmclock div{
601
margin-bottom: 0.8em;
#jsalarmclock div.leftcolumn{
float: left;
width: 150px;
font-size: 13px;
clear: left;
#jsalarmclock span{
margin-right: 5px;
.button_menu {
width: 100px;
height: 28px;
background-color: buttonface;
border-radius: 10px;
color: blue;
font-size:18px;
.select_menu {
width: 100px;
height: 28px;
background-color: buttonface;
border-radius: 10px;
602
color: red;
.text_menu {
width: 400px;
height: 28px;
background-color: buttonface;
border-radius: 10px;
color: blue;
</style>
<script type="text/javascript">
var jsalarm={
padfield:function(f){
},
showcurrenttime:function(){
var
ct=this.padfield(dateobj.getHours())+":"+this.padfield(dateobj.getMinutes())+":"+this.padfield(da
teobj.getSeconds())
this.ctref.innerHTML=ct
this.ctref.setAttribute("title", ct)
if (this.ctref.title==(this.hourwake+":"+this.minutewake+":"+this.secondwake)){
clearInterval(jsalarm.timer)
window.location=document.getElementById("musicloc").value
603
},
init:function(){
this.ctref=document.getElementById("alarm_alarm")
this.submitref=document.getElementById("submit_submit")
this.submitref.onclick=function(){
jsalarm.setalarm()
this.value="Alarm Set"
this.disabled=true
return false
this.resetref=document.getElementById("reset_reset")
this.resetref.onclick=function(){
jsalarm.submitref.disabled=false
jsalarm.hourwake=undefined
jsalarm.hourselect.disabled=false
jsalarm.minuteselect.disabled=false
jsalarm.secondselect.disabled=false
return false
var selections=document.getElementsByTagName("select")
this.hourselect=selections[0]
this.minuteselect=selections[1]
this.secondselect=selections[2]
604
this.secondselect[i]=new Option(this.padfield(i), this.padfield(i), false,
dateobj.getSeconds()==i)
jsalarm.showcurrenttime()
jsalarm.timer=setInterval(function(){jsalarm.showcurrenttime()}, 1000)
},
setalarm:function(){
this.hourwake=this.hourselect.options[this.hourselect.selectedIndex].value
this.minutewake=this.minuteselect.options[this.minuteselect.selectedIndex].value
this.secondwake=this.secondselect.options[this.secondselect.selectedIndex].value
this.hourselect.disabled=true
this.minuteselect.disabled=true
this.secondselect.disabled=true
</script>
</style>
</head>
<body>
<div id="jsalarmclock">
<div>
</div>
605
<div>
</div>
<div>
<p style=" margin-left: 150px; color: blue; font-size: 15px; font-weight: bold;">Location of
page to launch</p>
</span>
</div>
</div>
</form>
<script type="text/javascript">
jsalarm.init()
</script>
</body>
</html>
*********************************************************************************************
606
Date and time display in JavaScript
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
tday=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
tmonth=new
Array("January","February","March","April","May","June","July","August","September","October","No
vember","December");
function GetClock(){
var nday=d.getDay(),nmonth=d.getMonth(),ndate=d.getDate(),nyear=d.getYear();
if(nyear<1000) nyear+=1900;
var nhour=d.getHours(),nmin=d.getMinutes(),nsec=d.getSeconds(),ap;
if(nhour==0){ap=" AM";nhour=12;}
if(nmin<=9) nmin="0"+nmin;
if(nsec<=9) nsec="0"+nsec;
window.onload=function(){
GetClock();
setInterval(GetClock,1000);
</script>
</body>
607
</html>
*********************************************************************************************
Calender view
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
function fToggleColor(myElement) {
var toggleColor = "#ff0000";
if (myElement.id == "calDateText") {
if (myElement.color == toggleColor) {
myElement.color = "";
} else {
myElement.color = toggleColor;
}
} else if (myElement.id == "calCell") {
for (var i in myElement.children) {
if (myElement.children[i].id == "calDateText") {
if (myElement.children[i].color == toggleColor) {
myElement.children[i].color = "";
} else {
myElement.children[i].color = toggleColor;
}
}
}
}
}
function fSetSelectedDay(myElement){
if (myElement.id == "calCell") {
if (!isNaN(parseInt(myElement.children["calDateText"].innerText))) {
myElement.bgColor = "#c0c0c0";
objPrevElement.bgColor = "";
document.all.calSelectedDate.value = parseInt(myElement.children["calDateText"].innerText);
objPrevElement = myElement;
}
}
}
function fGetDaysInMonth(iMonth, iYear) {
var dPrevDate = new Date(iYear, iMonth, 0);
return dPrevDate.getDate();
}
function fBuildCal(iYear, iMonth, iDayStyle) {
var aMonth = new Array();
aMonth[0] = new Array(7);
aMonth[1] = new Array(7);
aMonth[2] = new Array(7);
608
aMonth[3] = new Array(7);
aMonth[4] = new Array(7);
aMonth[5] = new Array(7);
aMonth[6] = new Array(7);
var dCalDate = new Date(iYear, iMonth-1, 1);
var iDayOfFirst = dCalDate.getDay();
var iDaysInMonth = fGetDaysInMonth(iMonth, iYear);
var iVarDate = 1;
var i, d, w;
if (iDayStyle == 2) {
aMonth[0][0] = "Sunday";
aMonth[0][1] = "Monday";
aMonth[0][2] = "Tuesday";
aMonth[0][3] = "Wednesday";
aMonth[0][4] = "Thursday";
aMonth[0][5] = "Friday";
aMonth[0][6] = "Saturday";
} else if (iDayStyle == 1) {
aMonth[0][0] = "Sun";
aMonth[0][1] = "Mon";
aMonth[0][2] = "Tue";
aMonth[0][3] = "Wed";
aMonth[0][4] = "Thu";
aMonth[0][5] = "Fri";
aMonth[0][6] = "Sat";
} else {
aMonth[0][0] = "Su";
aMonth[0][1] = "Mo";
aMonth[0][2] = "Tu";
aMonth[0][3] = "We";
aMonth[0][4] = "Th";
aMonth[0][5] = "Fr";
aMonth[0][6] = "Sa";
}
for (d = iDayOfFirst; d < 7; d++) {
aMonth[1][d] = iVarDate;
iVarDate++;
}
for (w = 2; w < 7; w++) {
for (d = 0; d < 7; d++) {
if (iVarDate <= iDaysInMonth) {
aMonth[w][d] = iVarDate;
iVarDate++;
}
}
}
return aMonth;
}
function fDrawCal(iYear, iMonth, iCellWidth, iCellHeight, sDateTextSize, sDateTextWeight,
iDayStyle) {
var myMonth;
myMonth = fBuildCal(iYear, iMonth, iDayStyle);
document.write("<table border='1'>")
document.write("<tr>");
document.write("<td align='center' style='FONT-FAMILY:Arial;FONT-SIZE:12px;FONT-WEIGHT: bold'>" +
myMonth[0][0] + "</td>");
document.write("<td align='center' style='FONT-FAMILY:Arial;FONT-SIZE:12px;FONT-WEIGHT: bold'>" +
myMonth[0][1] + "</td>");
609
document.write("<td align='center' style='FONT-FAMILY:Arial;FONT-SIZE:12px;FONT-WEIGHT: bold'>" +
myMonth[0][2] + "</td>");
document.write("<td align='center' style='FONT-FAMILY:Arial;FONT-SIZE:12px;FONT-WEIGHT: bold'>" +
myMonth[0][3] + "</td>");
document.write("<td align='center' style='FONT-FAMILY:Arial;FONT-SIZE:12px;FONT-WEIGHT: bold'>" +
myMonth[0][4] + "</td>");
document.write("<td align='center' style='FONT-FAMILY:Arial;FONT-SIZE:12px;FONT-WEIGHT: bold'>" +
myMonth[0][5] + "</td>");
document.write("<td align='center' style='FONT-FAMILY:Arial;FONT-SIZE:12px;FONT-WEIGHT: bold'>" +
myMonth[0][6] + "</td>");
document.write("</tr>");
for (w = 1; w < 7; w++) {
document.write("<tr>")
for (d = 0; d < 7; d++) {
document.write("<td align='left' valign='top' width='" + iCellWidth + "' height='" + iCellHeight
+ "' id=calCell style='CURSOR:Hand' onMouseOver='fToggleColor(this)'
onMouseOut='fToggleColor(this)' onclick=fSetSelectedDay(this)>");
if (!isNaN(myMonth[w][d])) {
document.write("<font id=calDateText onMouseOver='fToggleColor(this)' style='CURSOR:Hand;FONT-
FAMILY:Arial;FONT-SIZE:" + sDateTextSize + ";FONT-WEIGHT:" + sDateTextWeight + "'
onMouseOut='fToggleColor(this)' onclick=fSetSelectedDay(this)>" + myMonth[w][d] + "</font>");
} else {
document.write("<font id=calDateText onMouseOver='fToggleColor(this)' style='CURSOR:Hand;FONT-
FAMILY:Arial;FONT-SIZE:" + sDateTextSize + ";FONT-WEIGHT:" + sDateTextWeight + "'
onMouseOut='fToggleColor(this)' onclick=fSetSelectedDay(this)> </font>");
}
document.write("</td>")
}
document.write("</tr>");
}
document.write("</table>")
}
function fUpdateCal(iYear, iMonth) {
myMonth = fBuildCal(iYear, iMonth);
objPrevElement.bgColor = "";
document.all.calSelectedDate.value = "";
for (w = 1; w < 7; w++) {
for (d = 0; d < 7; d++) {
if (!isNaN(myMonth[w][d])) {
calDateText[((7*w)+d)-7].innerText = myMonth[w][d];
} else {
calDateText[((7*w)+d)-7].innerText = " ";
}
}
}
}
// End -->
</script>
</head>
</HEAD>
<BODY>
610
for (i = 0; i < frmCalendarSample.tbSelYear.length; i++)
if (frmCalendarSample.tbSelYear.options[i].value == dCurDate.getFullYear())
frmCalendarSample.tbSelYear.options[i].selected = true;
</script>
<table border="1">
<tr>
<td>
<select name="tbSelMonth" onchange='fUpdateCal(frmCalendarSample.tbSelYear.value,
frmCalendarSample.tbSelMonth.value)'>
<option value="1">January</option>
<option value="2">February</option>
<option value="3">March</option>
<option value="4">April</option>
<option value="5">May</option>
<option value="6">June</option>
<option value="7">July</option>
<option value="8">August</option>
<option value="9">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12">December</option>
</select>
<option value="2005">2005</option>
<option value="2006">2006</option>
<option value="2007">2007</option>
<option value="2008">2008</option>
<option value="2009">2009</option>
<option value="2010">2010</option>
<option value="2011">2011</option>
<option value="2012">2012</option>
<option value="2013">2013</option>
<option value="2014">2014</option>
<option value="2015">2015</option>
<option value="2016">2016</option>
</select>
</td>
</tr>
<tr>
<td>
<script language="JavaScript">
var dCurDate = new Date();
611
fDrawCal(dCurDate.getFullYear(), dCurDate.getMonth()+1, 30, 30, "12px", "bold", 1);
</script>
</td>
</tr>
</table>
</form>
<p><center>
<font face="arial, helvetica" size="-2">search engine<br/>
by <a href="http://www.google.com">google</a></font>
</center><p>
*********************************************************************************************
Table
<!DOCTYPE html>
<html>
<head>
<style>
table {
font-family: arial, sans-serif;
border-collapse: collapse;
width: 100%;
margin-top:10px;
td, th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}
tr:nth-child(even) {
background-color: #dddddd;
}
</style>
</head>
<body>
<table align="center">
<tr>
<th>Company</th></b>
<th>Contact</th>
<th>Country</th>
</tr>
<tr>
<td>Alfreds Futterkiste</td>
<td>Maria Anders</td>
<td>Germany</td>
</tr>
<tr>
<td>Centro comercial Moctezuma</td>
<td>Francisco Chang</td>
612
<td>Mexico</td>
</tr>
<tr>
<td>Ernst Handel</td>
<td>Roland Mendel</td>
<td>Austria</td>
</tr>
<tr>
<td>Island Trading</td>
<td>Helen Bennett</td>
<td>UK</td>
</tr>
<tr>
<td>Laughing Bacchus Winecellars</td>
<td>Yoshi Tannamuri</td>
<td>Canada</td>
</tr>
<tr>
<td>Magazzini Alimentari Riuniti</td>
<td>Giovanni Rovelli</td>
<td>Italy</td>
</tr>
<tr>
<td>Magazzini Alimentari Riuniti</td>
<td>Giovanni Rovelli</td>
<td>Italy</td>
</tr>
</table>
</body>
</html>
*********************************************************************************************
613
</td>
</tr>
</table>
</form>
</td>
</tr>
</table>
<p>
<script language="JavaScript">
/*
Drop down messages script
By Website Abstraction (http://wsabstract.com)
Over 400+ free scripts here!
*/
//change contents of message box, where the first one corresponds with the first drop down box,
second with second box etc
var thecontents=new Array()
thecontents[1]='The first few words that come to mind are: "Freedom baby, freedom!" With html,
you are restricted to creating static, non interactive webpages. This, in today\'s internet
standards, is unacceptable. With JavaScript, you can change that. Imagine being able to break
free and allow your creativity to dictate what you put on your webpage, instead of the other way
round.'
thecontents[3]='DHTML, or Dynamic HTML, is a new web technology that enables elements inside your
web page to be, well, dynamic. Things once considered unchangeable once the page has loaded, such
as text, page styles (font color, size etc), element position, etc, can now all be changed
dynamically, thanks to DHTML. It brings your web pages one step closer to how things look inside
your television, where images appear and disappear, text flies in and out, and content move
around freely inside the screen.'
function changecontent(which){
document.ddmessage.contentbox.value=thecontents[which.selectedIndex]
}
document.ddmessage.contentbox.value=thecontents[document.ddmessage.selectbox.selectedIndex]
</script>
614
*********************************************************************************************
<tr><td valign=top>
This is a great way to display code snippets to your visitors, allowing them to make changes and
preview those changes all from the same page - keeping them on your site longer. Just replace
this text within the script with whatever code you want to have displayed to your visitors. Click
on the 'Generate Code' button to launch preview. More great scripts at <a href=http://www.java-
scripts.net>Java-Scripts.net</a><br><br>
</textarea>
</form>
</td><td valign=top>
</iframe>
</td>
</tr>
</table>
<button onclick="window.document.form1.code.value='';preview.document.write
(document.getElementsByTagName ('TEXTAREA')[0].value); preview.document.close();
preview.focus()">Clear All</button>
<button onClick="window.location.href=window.location.href">Reload</button>
*********************************************************************************************
615
Animated Side display of text
<script>
if (document.layers)
var ns4def=''
</script>
<script language="JavaScript1.2">
if (document.getElementById||document.all)
function animatein(){
if (parseInt(crossheader.left)<0)
crossheader.left=parseInt(crossheader.left)+20
else{
crossheader.left=0
crossheader.fontStyle="normal"
clearInterval(start)
if (document.getElementById||document.all)
start=setInterval("animatein()",50)
</script>
*********************************************************************************************
Scroll Up of text
<SCRIPT language=JavaScript1.2>
var marqueewidth="150"
var marqueeheight="150"
616
var marqueespeed=3
var pauseit=1
var marqueecontent='<font face=Arial color=lightgreen size=2><b>'
function populate(){
if (iedom){
cross_marquee = document.getElementById? document.getElementById("iemarquee") :
document.all.iemarquee
cross_marquee.style.top=parseInt(marqueeheight)+8+"px"
cross_marquee.innerHTML=marqueecontent
actualheight=cross_marquee.offsetHeight
}
else if (document.layers){
ns_marquee=document.ns_marquee.document.ns_marquee2
ns_marquee.top=parseInt(marqueeheight)+8
ns_marquee.document.write(marqueecontent)
ns_marquee.document.close()
actualheight=ns_marquee.document.height
}
lefttime=setInterval("scrollmarquee()",20)
}
window.onload=populate
function scrollmarquee(){
if (iedom){
if (parseInt(cross_marquee.style.top)>(actualheight*(-1)+8))
cross_marquee.style.top=parseInt(cross_marquee.style.top)-copyspeed+"px"
else
cross_marquee.style.top=parseInt(marqueeheight)+8+"px"
}
else if (document.layers){
if (ns_marquee.top>(actualheight*(-1)+18))
ns_marquee.top-=copyspeed
else
ns_marquee.top=parseInt(marqueeheight)+8
}
}
if (iedom||document.layers){
with (document){
if (iedom){
write('<div style="position:relative; width:'+marqueewidth+'; height:'+marqueeheight+';
overflow:hidden" onMouseover="copyspeed=pausespeed" onMouseout="copyspeed=marqueespeed">')
write('<div id="iemarquee" style="position:absolute; left:0px; top:0px; width:100%;">')
write('</div></div>')
}
else if (document.layers){
write('<ilayer width='+marqueewidth+' height='+marqueeheight+' name="ns_marquee">')
617
write('<layer name="ns_marquee2" width='+marqueewidth+' height='+marqueeheight+' left=0 top=0
onMouseover="copyspeed=pausespeed" onMouseout="copyspeed=marqueespeed"></layer>')
write('</ilayer>')
}
}
}
</SCRIPT>
*********************************************************************************************
<form name="openlocation">
<input type="text" name="href" value="http://">
<input type="button" value="Go To" onClick="location.href=document.openlocation.href.value;; ">
</form>
*********************************************************************************************
<SCRIPT LANGUAGE="JavaScript">
function myprint()
{
window.print();
}
</script>
<form>
<input type=button value="Print Page" onClick="myprint()">
</form>
*********************************************************************************************
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function addChar(input, character) {
618
if(input.value == null || input.value == "0")
input.value = character
else
input.value += character
}
function cos(form) {
form.display.value = Math.cos(form.display.value);}
function sin(form) {
form.display.value = Math.sin(form.display.value);}
function tan(form) {
form.display.value = Math.tan(form.display.value);}
function sqrt(form) {
form.display.value = Math.sqrt(form.display.value);}
function ln(form) {
form.display.value = Math.log(form.display.value);}
function exp(form) {
form.display.value = Math.exp(form.display.value);}
function cbrt(form) {
form.display.value = Math.cbrt(form.display.value);}
function sqrt(form) {
form.display.value = Math.sqrt(form.display.value);}
function deleteChar(input) {
input.value = input.value.substring(0, input.value.length - 1)
}
function changeSign(input) {
substring
if(input.value.substring(0, 1) == "-")
input.value = input.value.substring(1, input.value.length)
else
input.value = "-" + input.value
}
function compute(form) {
form.display.value = eval(form.display.value)}
function square(form) {
form.display.value = eval(form.display.value) *
eval(form.display.value)}
function checkNum(str) {
for (var i = 0; i < str.length; i++) {
var ch = str.substring(i, i+1)
if (ch < "0" || ch > "9") {
if (ch != "/" && ch != "*" && ch != "+" && ch !=
"-" && ch != "."
&& ch != "(" && ch!= ")") {
alert("invalid entry!")
return false
}
}
}
return true
}
// End -->
</SCRIPT>
<BODY>
619
<CENTER>
<FORM>
<input name="display" value="0" size="25"></td>
<br>
<input type="button" value=" exp " onClick="if (checkNum(this.form.display.value)) {
exp(this.form) }">
*********************************************************************************************
620
Glowing bar Link to a website
<script>
//enter a color name or hex to be used as the background color of the message
var backgroundcolor="#FFFF8A"
//Set duration message should appear on screen, in seconds (10000=10 sec, 0=perpetual)
var displayduration=0
function regenerate(){
window.location.reload()
}
function regenerate2(){
if (document.layers)
setTimeout("window.onresize=regenerate",400)
}
var which=0
function flash(){
if (which==0){
if (document.layers)
topmsg_obj.bgColor=flashtocolor
else
topmsg_obj.style.backgroundColor=flashtocolor
which=1
}
else{
if (document.layers)
topmsg_obj.bgColor=backgroundcolor
else
topmsg_obj.style.backgroundColor=backgroundcolor
which=0
}
}
if (ie||document.getElementById)
621
document.write('<div id="topmsg" style="position:absolute;visibility:hidden;z-
index:1000">'+message+'</div>')
function positionit(){
var dsocleft=ie? document.body.scrollLeft : pageXOffset
var dsoctop=ie? document.body.scrollTop : pageYOffset
var window_width=ieNOTopera? document.body.clientWidth : window.innerWidth-20
var window_height=ieNOTopera? document.body.clientHeight : window.innerHeight
if (ie||document.getElementById){
topmsg_obj.style.left=parseInt(dsocleft)+window_width/2-topmsg_obj.offsetWidth/2
topmsg_obj.style.top=parseInt(dsoctop)+parseInt(window_height)-topmsg_obj.offsetHeight-4
}
else if (document.layers){
topmsg_obj.left=dsocleft+window_width/2-topmsg_obj.document.width/2
topmsg_obj.top=dsoctop+window_height-topmsg_obj.document.height-5
}
}
function setmessage(){
if (displaymode==2&&(!display_msg_or_not()))
return
if (document.layers){
topmsg_obj=new Layer(window.innerWidth)
topmsg_obj.bgColor=backgroundcolor
regenerate2()
topmsg_obj.document.write(message)
topmsg_obj.document.close()
positionit()
topmsg_obj.visibility="show"
if (displayduration!=0)
setTimeout("topmsg_obj.visibility='hide'",displayduration)
}
else{
positionit()
topmsg_obj.style.backgroundColor=backgroundcolor
topmsg_obj.style.visibility="visible"
if (displayduration!=0)
setTimeout("topmsg_obj.style.visibility='hidden'",displayduration)
}
setInterval("positionit()",100)
if (flashmode==1)
setInterval("flash()",1000)
}
function get_cookie(Name) {
var search = Name + "="
var returnvalue = ""
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search)
if (offset != -1) {
offset += search.length
end = document.cookie.indexOf(";", offset)
if (end == -1)
end = document.cookie.length;
622
returnvalue=unescape(document.cookie.substring(offset, end))
}
}
return returnvalue;
}
function display_msg_or_not(){
if (get_cookie("displaymsg")==""){
document.cookie="displaymsg=yes"
return true
}
else
return false
}
if (document.layers||ie||document.getElementById)
window.onload=setmessage
</script>
*********************************************************************************************
</script>
<script>
//Specify affected tags. Add or remove from list:
var tgs = new Array( 'div','td','tr');
sz += inc;
if ( sz < 0 ) sz = 0;
if ( sz > 6 ) sz = 6;
startSz = sz;
cEl.style.fontSize = szs[ sz ];
623
for ( j = 0 ; j < cTags.length ; j++ ) cTags[ j ].style.fontSize = szs[ sz ];
}
}
</script>
*********************************************************************************************
Flying Letters
<h2 id="fly">Thanks for visiting $ my website!</h2>
<script type="text/javascript">
var txt="",
num=0,
num4=0,
flyofle="",
flyofwi="",
flyofto="",
fly=document.getElementById("fly");
function stfly() {
for(i=0;i != message.length;i++) {
if(message.charAt(i) != "$")
txt += "<span style='position:relative;visibility:hidden;'
id='n"+i+"'>"+message.charAt(i)+"<\/span>";
else
txt += "<br>";
}
fly.innerHTML = txt;
txt = "";
flyofle = fly.offsetLeft;
flyofwi = fly.offsetWidth;
flyofto = fly.offsetTop;
fly2b();
}
function fly2b() {
if(num4 != message.length) {
if(message.charAt(num4) != "$") {
var then = document.getElementById("n" + num4);
then.style.left = flyofle - then.offsetLeft + flyofwi / 2 + 'px';
then.style.top = flyofto - then.offsetTop + distance + 'px';
fly3(then.id, parseInt(then.style.left), parseInt(then.style.left) / 5,
parseInt(then.style.top), parseInt(then.style.top) / 5);
}
num4++;
624
setTimeout("fly2b()", speed);
}
}
function fly3(target,lef2,num2,top2,num3) {
if((Math.floor(top2) != 0 && Math.floor(top2) != -1) || (Math.floor(lef2) != 0 &&
Math.floor(lef2) != -1)) {
if(lef2 >= 0)
lef2 -= num2;
else
lef2 += num2 * -1;
if(Math.floor(lef2) != -1) {
document.getElementById(target).style.visibility = "visible";
document.getElementById(target).style.left = Math.floor(lef2) + 'px';
} else {
document.getElementById(target).style.visibility = "visible";
document.getElementById(target).style.left = Math.floor(lef2 + 1) + 'px';
}
if(lef2 >= 0)
top2 -= num3
else
top2 += num3 * -1;
if(Math.floor(top2) != -1)
document.getElementById(target).style.top = Math.floor(top2) + 'px';
else
document.getElementById(target).style.top = Math.floor(top2 + 1) + 'px';
setTimeout("fly3('"+target+"',"+lef2+","+num2+","+top2+","+num3+")",50)
}
}
stfly()
</script>
*********************************************************************************************
</center>
*********************************************************************************************
Background colour
<!DOCTYPE html>
<html>
<body style="background-color:lightgreen;" >
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
625
</body>
</html>
*********************************************************************************************
HTML code:
<body background="http://www.parentirappresentanze.com/wp-content/uploads/2014/12/Fashion.jpg">
Css code:
<style>
body { background-image: url("http://www.parentirappresentanze.com/wp-
content/uploads/2014/12/Fashion.jpg");}
</style>
*********************************************************************************************
<style type="text/css">
body {
background-image: url(http://www.parentirappresentanze.com/wp-
content/uploads/2014/12/Fashion.jpg);
background-position: 160px 160px;
background-size: 850px 650px;
background-repeat: no-repeat;
}
</style>
*********************************************************************************************
World clock
<html>
<head>
<title>World Clock javascript | World Clock html script </title>
<script type='text/javascript'>
var hr;
var mins;
var secs;
var nd;
var countryname='India';//Change the country name here
function addOption(selectbox,text,value){var optn = document.createElement("OPTION");
optn.text = text;optn.value = value;selectbox.options.add(optn);}
626
function addOption_list(){var sds = document.getElementById("dum");if(sds == null){}var sdss =
document.getElementById("dumdiv");if(sdss == null){alert("
welcome");document.getElementById("content").style.visibility="hidden";}
627
var out = "";for(i=0; i < countries.length;
i++){if(countries[i]==country){newtime=calcTime(countries[i],uct[i]);out=uct[i]+":00";
document.getElementById("coun_date").innerHTML=newtime;
document.getElementById("cntryname").innerHTML="Current Date and Time of "+country;}
}
var id=document.getElementById("list");
if (id == null) {}
else{
addOption_list();
document.getElementById('sel').style.display = "none";
}
function calcTime(city, offset){
var d = new Date();var utc = d.getTime() + (d.getTimezoneOffset() * 60000);var plus = utc +
(3600000*offset);nd = new Date(plus);hr = nd.getHours();mins = nd.getMinutes();secs =
nd.getSeconds();
return nd.toLocaleString();
}setInterval(function(){function re(el, deg){el.setAttribute('transform', 'rotate('+ deg +' 90
90)');}var hh =hr;var mm = mins;var ss = secs;if(hh==0 && mm==0 && ss==0) ss=0; else ss--;var d =
new Date();re(second, 6*d.getSeconds()) ; re(minute, 6*nd.getMinutes());re(hourr,
30*(nd.getHours()%12) + nd.getMinutes()/2);}, 1000) ;
}</script>
<style>
.blue_bg {background: none repeat scroll 0 0 #3BBEC0;}
.date_time_top {height: 210px;padding: 10px;text-align: center;width:32%;}
.blue_bg2 {background: none repeat scroll 0 0 #298586;width:32%;padding:10px 10px 10px
10px;}h3{color:#fff !important;font-family: Tahoma,Geneva,sans-serif;font-size: 0.9em;margin:0;}
.frms
{border:none !important;
}@media screen and (max-width: 480px){.date_time_top{height: 210px;padding: 10px;text-align:
center;width:auto;}.blue_bg2 {background: none repeat scroll 0 0 #298586;width:auto;}
}
-webkit-border-radius:.3em;
-o-border-radius:.3em;
font-family:Tahoma, Geneva, sans-serif;
color:#333;
font-size:.9em;
line-height:1.2em;
}
.frms
{
margin:0 auto;
padding:10px;
border:#ddd 1px solid;
border-radius:.3em;
-moz-border-radius:.3em;
-webkit-border-radius:.3em;
-o-border-radius:.3em;
font-family:Tahoma, Geneva, sans-serif;
color:#333;
font-size:.9em;
line-height:1.2em;
}
.frms input:hover,textarea:hover,select:hover
{
box-shadow:#dae1e5 0px 0px 5px;
-moz-box-shadow:#dae1e5 0px 0px 5px;
-webkit-box-shadow:#dae1e5 0px 0px 5px;
-o-box-shadow:#dae1e5 0px 0px 5px;
628
}
.frms input:focus,textarea:focus,select:focus
{
-webkit-box-shadow: inset 7px 4px 7px -7px rgba(0,0,0,0.42);
-moz-box-shadow: inset 7px 4px 7px -7px rgba(0,0,0,0.42);
box-shadow: inset 7px 4px 7px -7px rgba(0,0,0,0.42);
border:#9d9983 1px solid;
}
.frms select
{
width:99%;
background:#fff;
border:#ddd 1px solid;
border-radius:.35em;
-moz-border-radius:.35em;
-webkit-border-radius:.35em;
-o-border-radius:.35em;
padding:0 .5%;
margin-top:5px;
margin-bottom:15px;
height:35px;
}
.resp_code
{
margin:5px 10px 10px 300px;
padding:10px 20px 10px 20px;
color:#333;
background:#f8f8f8;
border:#ddd 1px solid;
border-radius:.25em;
overflow:auto;width:50%;
}
@media screen and (max-width: 480px)
{
.resp_code
{width:auto !important;margin:0px !important;
}
}
</style></head>
<body onload="selecteval(countryname)">
<div class='resp_code' align='center'>
629
<path fill="none" stroke="#000000" d="M163,114L166,115" style="stroke-width: 3;" stroke-
width="3"/>
<path fill="none" stroke="#000000" d="M160,121L163,123" style="stroke-width: 3;" stroke-
width="3"/>
<path fill="none" stroke="#000000" d="M151,125L159,130" style="stroke-width: 7;" stroke-
width="7"/>
<path fill="none" stroke="#000000" d="M152,135L155,137" style="stroke-width: 3;" stroke-
width="3"/>
<path fill="none" stroke="#000000" d="M147,142L149,144" style="stroke-width: 3;" stroke-
width="3"/>
<path fill="none" stroke="#000000" d="M142,147L144,149" style="stroke-width: 3;" stroke-
width="3"/>
<path fill="none" stroke="#000000" d="M135,152L137,155" style="stroke-width: 3;" stroke-
width="3"/>
<path fill="none" stroke="#000000" d="M125,151L130,159" style="stroke-width: 7;" stroke-
width="7"/>
<path fill="none" stroke="#000000" d="M121,160L123,163" style="stroke-width: 3;" stroke-
width="3"/>
<path fill="none" stroke="#000000" d="M114,163L115,166" style="stroke-width: 3;" stroke-
width="3"/>
<path fill="none" stroke="#000000" d="M106,165L107,168" style="stroke-width: 3;" stroke-
width="3"/>
<path fill="none" stroke="#000000" d="M98,167L98,170" style="stroke-width: 3;" stroke-width="3"/>
<path fill="none" stroke="#000000" d="M90,160L90,170" style="stroke-width: 7;" stroke-width="7"/>
<path fill="none" stroke="#000000" d="M82,167L82,170" style="stroke-width: 3;" stroke-width="3"/>
<path fill="none" stroke="#000000" d="M74,165L73,168" style="stroke-width: 3;" stroke-width="3"/>
<path fill="none" stroke="#000000" d="M66,163L65,166" style="stroke-width: 3;" stroke-width="3"/>
<path fill="none" stroke="#000000" d="M59,160L57,163" style="stroke-width: 3;" stroke-width="3"/>
<path fill="none" stroke="#000000" d="M55,151L50,159" style="stroke-width: 7;" stroke-width="7"/>
<path fill="none" stroke="#000000" d="M45,152L43,155" style="stroke-width: 3;" stroke-width="3"/>
<path fill="none" stroke="#000000" d="M38,147L36,149" style="stroke-width: 3;" stroke-width="3"/>
<path fill="none" stroke="#000000" d="M33,142L31,144" style="stroke-width: 3;" stroke-width="3"/>
<path fill="none" stroke="#000000" d="M28,135L25,137" style="stroke-width: 3;" stroke-width="3"/>
<path fill="none" stroke="#000000" d="M29,125L21,130" style="stroke-width: 7;" stroke-width="7"/>
<path fill="none" stroke="#000000" d="M20,121L17,123" style="stroke-width: 3;" stroke-width="3"/>
<path fill="none" stroke="#000000" d="M17,114L14,115" style="stroke-width: 3;" stroke-width="3"/>
<path fill="none" stroke="#000000" d="M15,106L12,107" style="stroke-width: 3;" stroke-width="3"/>
<path fill="none" stroke="#000000" d="M13,98L10,98" style="stroke-width: 3;" stroke-width="3"/>
<path fill="none" stroke="#000000" d="M20,90L10,90" style="stroke-width: 7;" stroke-width="7"/>
<path fill="none" stroke="#000000" d="M13,82L10,82" style="stroke-width: 3;" stroke-width="3"/>
<path fill="none" stroke="#000000" d="M15,74L12,73" style="stroke-width: 3;" stroke-width="3"/>
<path fill="none" stroke="#000000" d="M17,66L14,65" style="stroke-width: 3;" stroke-width="3"/>
<path fill="none" stroke="#000000" d="M20,59L17,57" style="stroke-width: 3;" stroke-width="3"/>
<path fill="none" stroke="#000000" d="M29,55L21,50" style="stroke-width: 7;" stroke-width="7"/>
<path fill="none" stroke="#000000" d="M28,45L25,43" style="stroke-width: 3;" stroke-width="3"/>
<path fill="none" stroke="#000000" d="M33,38L31,36" style="stroke-width: 3;" stroke-width="3"/>
<path fill="none" stroke="#000000" d="M38,33L36,31" style="stroke-width: 3;" stroke-width="3"/>
<path fill="none" stroke="#000000" d="M45,28L43,25" style="stroke-width: 3;" stroke-width="3"/>
<path fill="none" stroke="#000000" d="M55,29L50,21" style="stroke-width: 7;" stroke-width="7"/>
<path fill="none" stroke="#000000" d="M59,20L57,17" style="stroke-width: 3;" stroke-width="3"/>
<path fill="none" stroke="#000000" d="M66,17L65,14" style="stroke-width: 3;" stroke-width="3"/>
<path fill="none" stroke="#000000" d="M74,15L73,12" style="stroke-width: 3;" stroke-width="3"/>
<path fill="none" stroke="#000000" d="M82,13L82,10" style="stroke-width: 3;" stroke-width="3"/>
<path fill="none" stroke="#000000" d="M90,20L90,10" style="stroke-width: 7;" stroke-width="7"/>
<path fill="none" stroke="#000000" d="M98,13L98,10" style="stroke-width: 3;" stroke-width="3"/>
<path fill="none" stroke="#000000" d="M106,15L107,12" style="stroke-width: 3;" stroke-width="3"/>
<path fill="none" stroke="#000000" d="M114,17L115,14" style="stroke-width: 3;" stroke-width="3"/>
<path fill="none" stroke="#000000" d="M121,20L123,17" style="stroke-width: 3;" stroke-width="3"/>
630
<path fill="none" stroke="#000000" d="M125,29L130,21" style="stroke-width: 7;" stroke-width="7"/>
<path fill="none" stroke="#000000" d="M135,28L137,25" style="stroke-width: 3;" stroke-width="3"/>
<path fill="none" stroke="#000000" d="M142,33L144,31" style="stroke-width: 3;" stroke-width="3"/>
<path fill="none" stroke="#000000" d="M147,38L149,36" style="stroke-width: 3;" stroke-width="3"/>
<path fill="none" stroke="#000000" d="M152,45L155,43" style="stroke-width: 3;" stroke-width="3"/>
<path fill="none" stroke="#000000" d="M151,55L159,50" style="stroke-width: 7;" stroke-width="7"/>
<path fill="none" stroke="#000000" d="M160,59L163,57" style="stroke-width: 3;" stroke-width="3"/>
<path fill="none" stroke="#000000" d="M163,66L166,65" style="stroke-width: 3;" stroke-width="3"/>
<path fill="none" stroke="#000000" d="M165,74L168,73" style="stroke-width: 3;" stroke-width="3"/>
<path fill="none" stroke="#000000" d="M167,82L170,82" style="stroke-width: 3;" stroke-width="3"/>
<path fill="none" stroke="#000000" d="M90,90L90,30" style="stroke-width: 9;" stroke-width="9"
transform="rotate()" id='hourr'/>
<path fill="none" stroke="#000000" d="M90,90L90,25" style="stroke-width: 6;" stroke-width="6"
transform="rotate()" id='minute'/>
<path fill="none" stroke="#ff0000" d="M90,90L90,20" style="stroke-width: 4;" stroke-width="4"
transform="rotate()" id='second'/>
<circle cx="90.5" cy="90.5" r="7" fill="#000000" stroke="#000"/>
</svg>
</div>
</div>
<div class="date_time_bottom blue_bg2">
<h3 id="coun_date"></h3>
<h3 id="coun_clock"></h3>
</div>
</form>
<div id="dumdiv" align="center" style=" font-size: 10px;color: #dadada;">
</div>
</div>
</body>
</html>
*********************************************************************************************
<script type="text/javascript">
function checnum(as)
{
var a = as.value;
for(var x=0; x<a.length; x++)
{
var ff = a[x];
if(isNaN(a) || ff==" ")
{
a = a.substring(0,(a.length-1));
as.value = a;
}}}
function getCheckedValue( groupName ) {
var radios = document.getElementsByName( groupName );
for( i = 0; i < radios.length; i++ ) {
if( radios[i].checked ) {
return radios[i].value;
}
}
return null;
631
}
function tqe_perc()
{
var sds = document.getElementById("dum");
if(sds == null){
}
var sdss = document.getElementById("dumdiv");
if(sdss == null){
}
if(sdss != null)
{
var totamount=0;
var p1= document.getElementById("amount").value;
var age1=document.getElementById("age").value;
if(age1=="")
document.getElementById("err_msg").innerHTML="<font color='red'><b>Enter the current
age</b></font>";
else if(p1=="")
document.getElementById("err_msg").innerHTML="<font color='red'><b>Enter the premium
payable</b></font>"
else
{
document.getElementById("err_msg").innerHTML="";
var p= parseFloat(p1);
var age= parseFloat(age1);
var y= parseFloat(getCheckedValue("year"));
var t=getCheckedValue("t")
if(p==""||age==""||y=="")
{
alert("enter the amount,interstand year");
}
else
{
if(t=="Yearly")
{
totamount=(y*p)+(y*500*41);
document.getElementById("r1").value=totamount;
}
else
{
totamount=(p*12*y)+(y*500*41);
document.getElementById("r1").value=totamount;
}
}
}
}
//alert(totamount+(p*y*6/100));
}
</script>
<html>
<head>
<title>Life Insurance Calculator Script</title>
</head>
<div id="calculator" align=center>
632
<h2>Life Insurance Monthly/Yearly Premium Payment Calculation</h2>
<form name=first>
<table align=center border=0 cellpadding=1 cellspacing=1 id=tqe_calc>
<tr><td colspan=2 align='center'> <div id='err_msg'></div> </td></tr>
<tr><td align=left>Current Age:</td><td><input type=text id=age onkeyup=checnum(this)></td></tr>
<tr><td colspan=2>
</td></tr>
<tr><td align=left>Premium Payable:</td><td><input type=text id=amount
onkeyup=checnum(this)><input type=radio name=t value=Monthly>Monthly <input type=radio name=t
value=Yearly checked>Yearly</td></tr>
<tr><td colspan=2>
</td></tr>
<tr><td align=left>For policy term of</td><td><div id=y><input type=radio name=year value=15
checked>15-Year <input type=radio name=year value=20>20-Year <input type=radio name=year
value=25>25-year</div></td></tr>
<tr><td colspan=2>
</td></tr>
<tr><td align=center colspan=2> <input type=button value='Calculate' onclick=tqe_perc()><input
type=reset value='Reset'> </td></tr>
<tr><td colspan=2> <div align='center' style=" padding-left: 10px;font-size: 10px;color:
#dadada;" id="dumdiv">
<tr><td colspan=2>
</td></tr>
<tr><td align=left>Fund Amount:</td><td><input type=text id=r1></td></tr>
<tr><td colspan=2>
</td></tr>
</table></form></div>
</html>
*********************************************************************************************
<style type="text/css">
.subheading
{
font-size:13px;
font-family: arial, verdana, san-serif;
color: black;
}
</style>
</td></tr> </table>
*********************************************************************************************
Calorie Calculator
<script type="text/javascript">
var cneed;
var fneed;
var crneed;
var pneed;
var aneed;
634
var fd;
function cc()
{
var age=parseInt(document.getElementById("age").value);
var wtype=document.getElementById("wtype").value;
var foot=parseInt(document.getElementById("foot").value);
var inch=parseInt(document.getElementById("inch").value);
var cm =document.getElementById("cen").value;
var weight=document.getElementById("weight").value;
if (age!='' && cm!='' && weight!='') {
if (wtype=="pounds")
{weight=parseInt(weight);
weight=Math.round(weight/2.2046);
}
var loa=document.getElementById("loa").value;
if(document.getElementById("gen").checked)
{
fd=(10*weight)+(6.25*cm)-(5*age)+5;
}
else
{
fd=(10*weight)+(6.25*cm)-(5*age)-161;
}
switch(loa)
{
case "1":
cneed=fd*1.2;
break;
case "2":
cneed=fd*1.375
break;
case "3":
cneed=fd*1.53;
break;
case "4":
cneed=fd*1.725;
break;
case "5":
cneed=fd*1.9;
break;
}
cneed=Math.floor(cneed);
//cneed1=Math.floor(cneed*0.0353);
fneed=Math.floor((cneed*0.25)/9);
if (wtype=="pounds")
{
fneed=Math.floor(fneed*0.0353);
//fneed=fneed*0.0022 ;
}
pneed=Math.floor((cneed*0.25)/4);
if (wtype=="pounds")
{
pneed=Math.floor(pneed*0.0353);
}
crneed=Math.floor((cneed*0.25)/4);
if (wtype=="pounds")
{
crneed=Math.floor(crneed*0.0353);
635
}
aneed=Math.floor((cneed*0.25)/7);
if (wtype=="pounds")
{
aneed=Math.floor(aneed*0.0353);
}
document.getElementById("rc").value=" "+cneed;
document.getElementById("rf").value=" "+fneed;
document.getElementById("rp").value=" "+pneed;
document.getElementById("rh").value=" "+crneed;
document.getElementById("ra").value=" "+aneed;
document.getElementById("l1").innerHTML="grams";
document.getElementById("l2").innerHTML="grams";
document.getElementById("l3").innerHTML="grams";
document.getElementById("l4").innerHTML="grams";
var caltype=document.getElementById("caltype").value;
if (caltype=='g') {
document.getElementById("l1").innerHTML="grams";
document.getElementById("l2").innerHTML="grams";
document.getElementById("l3").innerHTML="grams";
document.getElementById("l4").innerHTML="grams";
}
if (wtype=="pounds")
{
fat1 = fneed * 0.0022 ;
pro1 = pneed * 0.0022 ;
car1 = crneed * 0.0022 ;
alh1 = aneed * 0.0022 ;
fat1=fat1.toFixed(3);
pro1 = pro1.toFixed(3);
car1 = car1.toFixed(3);
alh1 = alh1.toFixed(3);
document.getElementById("rf").value=" "+fat1;
document.getElementById("rp").value=" "+pro1;
document.getElementById("rh").value=" "+car1;
document.getElementById("ra").value=" "+alh1;
document.getElementById("l1").innerHTML="lbs";
document.getElementById("l2").innerHTML="lbs";
document.getElementById("l3").innerHTML="lbs";
document.getElementById("l4").innerHTML="lbs";
}
if (caltype=='pounds') {
fat1 = fneed * 0.0022 ;
pro1 = pneed * 0.0022 ;
car1 = crneed * 0.0022 ;
alh1 = aneed * 0.0022 ;
fat1=fat1.toFixed(3);
pro1 = pro1.toFixed(3);
car1 = car1.toFixed(3);
alh1 = alh1.toFixed(3);
document.getElementById("rf").value=" "+fat1;
document.getElementById("rp").value=" "+pro1;
document.getElementById("rh").value=" "+car1;
document.getElementById("ra").value=" "+alh1;
document.getElementById("l1").innerHTML="lbs";
document.getElementById("l2").innerHTML="lbs";
document.getElementById("l3").innerHTML="lbs";
document.getElementById("l4").innerHTML="lbs";
636
}
if (caltype=='kg') {
fat2 = fneed / 1000;
pro2 = pneed / 1000;
car2 = crneed / 1000;
alh2 = aneed / 1000;
fat2=fat2.toFixed(3);
pro2 = pro2.toFixed(3);
car2 = car2.toFixed(3);
alh2 = alh2.toFixed(3);
document.getElementById("rf").value=" "+fat2;
document.getElementById("rp").value=" "+pro2;
document.getElementById("rh").value=" "+car2;
document.getElementById("ra").value=" "+alh2;
document.getElementById("l1").innerHTML="kilogram";
document.getElementById("l2").innerHTML="kilogram";
document.getElementById("l3").innerHTML="kilogram";
document.getElementById("l4").innerHTML="kilogram";
}
}
else{
alert("Please fill your details properly!");
}
}
function con(num)
{
var hc=parseInt(num.value);
var hi=hc/2.54;
var hf=Math.floor(hi/12);
var ri=Math.round(hi%12);
if(hc>40 && hc<=210)
{
document.getElementById("foot").value=hf;
}
document.getElementById("inch").value=ri;
}
function hcon()
{
var hf=parseInt(document.getElementById("foot").value);
var hi=parseInt(document.getElementById("inch").value);
var hc;
hc=Math.round((hf*30.48)+(hi*2.54));
document.getElementById("cen").value=hc;
}
function cknum(event,num)
{var kc;
if(window.event)
{
kc=event.keyCode;
}
else
{
kc=event.which;
}
var a=num.value;
if(kc==48)
{
if(a=="")
637
{
return false;
}
else
{
return true;
}
}if (kc!=8 && kc!=0)
{
if (kc<49||kc>57)
{
return false;
}
}
}
function isNumberKey(id)
{var no=eval('"'+id+'"');var number= document.getElementById(no).value; if(!number.match(/^[0-
9\.]+$/) && number !=""){number = number.substring(0,number.length-
1);document.getElementById(id).value = number;}
}
function convert() {
var age=parseInt(document.getElementById("age").value);
var cm =document.getElementById("cen").value;
var weight=document.getElementById("weight").value;
if (age!='' && cm!='' && weight!='') {
var caltype=document.getElementById("caltype").value;
var fat = document.getElementById("rf").value;
var pro = document.getElementById("rp").value;
var car = document.getElementById("rh").value;
var alh = document.getElementById("ra").value;
if (caltype=='g') {
document.getElementById("rc").value=" "+cneed;
document.getElementById("rf").value=" "+fneed;
document.getElementById("rp").value=" "+pneed;
document.getElementById("rh").value=" "+crneed;
document.getElementById("ra").value=" "+aneed;
document.getElementById("l1").innerHTML="grams";
document.getElementById("l2").innerHTML="grams";
document.getElementById("l3").innerHTML="grams";
document.getElementById("l4").innerHTML="grams";
}
if (caltype=='pounds') {
fat1 = fneed * 0.0022 ;
pro1 = pneed * 0.0022 ;
car1 = crneed * 0.0022 ;
alh1 = aneed * 0.0022 ;
fat1=fat1.toFixed(3);
pro1 = pro1.toFixed(3);
car1 = car1.toFixed(3);
alh1 = alh1.toFixed(3);
document.getElementById("rf").value=" "+fat1;
document.getElementById("rp").value=" "+pro1;
document.getElementById("rh").value=" "+car1;
document.getElementById("ra").value=" "+alh1;
document.getElementById("l1").innerHTML="lbs";
document.getElementById("l2").innerHTML="lbs";
document.getElementById("l3").innerHTML="lbs";
document.getElementById("l4").innerHTML="lbs";
638
}
if (caltype=='kg') {
fat2 = fneed / 1000;
pro2 = pneed / 1000;
car2 = crneed / 1000;
alh2 = aneed / 1000;
fat2=fat2.toFixed(3);
pro2 = pro2.toFixed(3);
car2 = car2.toFixed(3);
alh2 = alh2.toFixed(3);
document.getElementById("rf").value=" "+fat2;
document.getElementById("rp").value=" "+pro2;
document.getElementById("rh").value=" "+car2;
document.getElementById("ra").value=" "+alh2;
document.getElementById("l1").innerHTML="kilogram";
document.getElementById("l2").innerHTML="kilogram";
document.getElementById("l3").innerHTML="kilogram";
document.getElementById("l4").innerHTML="kilogram";
}
}
else{
alert("Please fill your details properly!");
}
}
function chk(){
var sds = document.getElementById('dum');
if(sds == null){
document.getElementById("tab").style.visibility="hidden";
}
var sdss = document.getElementById("dumdiv");
if(sdss == null){}
}
window.onload=chk;
</script>
<style>
.blue_button{background: none repeat scroll 0 0 #468CD2;border-bottom: 3px solid #3277BC;text-
shadow: 1px 1px 0 #214D73;border: medium none;border-radius: 0.3em;color: #FFFFFF;cursor:
pointer;font-weight: bold;margin: 10px 0;padding: 7px 14px;}
.frms input[type="text"], [type="password"], [type="file"], textarea, select {background: none
repeat scroll 0 0 #fff;border: 1px solid #ddd;border-radius: 0.35em;height: 35px;margin-bottom:
15px;margin-top: 5px;padding: 0 0.5%;width: 99%;
}
.resp_code {background: none repeat scroll 0 0 #f8f8f8;border: 1px solid #ddd;border-radius:
0.25em;color: #333;font: 1em/1.3em Tahoma,Geneva,sans-serif;margin: 5px 10px 10px 20%;overflow:
auto;padding: 10px 20px;width:50%;
}
@media only screen and (max-width:650px) {.resp_code {margin: 5px 1px 10px !important;width:auto
!important;}
}
</style>
639
name="age" id="age" align="left" size="3" maxlength="2" onkeypress="return
cknum(event,age)"></td><td><font color="#3D366F" size="2">years</font></td></tr><tr><td
style="color: #3D366F; font-size:13px;">Gender:</td><td><input type="radio" name="gen" id="gen"
checked><font color="#3D366F" size="0.7">Male</font><input type="radio" name="gen" id="gen"><font
color="#3D366F" size="0.7">Female</font></td></tr><tr><td style="color: #3D366F; font-
size:13px;">Height:</td><td><select style='width:50%;' name="foot" id="foot"
onchange="hcon()"><option value="1">1'</option><option value="2">2'</option><option
value="3">3'</option><option value="4">4'</option><option value="5">5'</option><option
value="6">6'</option><option value="7">7'</option></select><select style='width:40%;'name="inch"
id="inch" onchange="hcon()"><option value="1">1"</option><option value="2">2"</option><option
value="3">3"</option><option value="4">4"</option><option value="5">5"</option><option
value="6">6"</option><option value="7">7"</option><option value="8">8"</option><option
value="9">9"</option><option value="10">10"</option><option
value="11">11"</option></select></td></tr><tr><td style="color: #3D366F; font-size:13px;">Cms
:</td><td><input type="text" name="cen" id="cen" size="4" onkeyup="con(cen)"></td></tr><tr><td
style="color: #3D366F; font-size:13px;">Weight:</td><td><input type="text" name="weight"
id="weight" maxlength="3" size="3" onkeyup="isNumberKey(this.id)"></td><td><select name="wtype"
id="wtype"><option value="kg">Kg</option><option
value="pounds">Pounds</option></select></td></tr><tr><td style="color: #3D366F; font-
size:13px;">Activeness:</td><td><select style='width:100px;' name="loa" id="loa"><option
value="1">Sedentary</option><option value="2">Light Active</option><option value="3">Moderately
Active</option><option value="4">Very Active</option><option value="5">Extra
Active</option></select></td></tr><tr><td colspan='2' align="center"><input class='blue_button'
type="button" value="Calculate The Calorie" onclick="cc()"><span id="dumdiv" align="center"
style=" font-size: 10px;color: #dadada;"><a id="dum" style="padding-right:0px; text-
decoration:none;color: green;text-align:center;" href="#"> </a></span></td></tr></table></form>
<br><table align="center" border="0" class="frms noborders"><caption><b>Calorie
Result</b></caption><tr><td align="right" style="color: #3D366F; font-size:13px;">Calorie
Needed:</td><td><input type="text" id="rc" style="font-size:13px;" size="15"
readonly></td><td><select name="caltype" id="caltype" onChange="convert()"><option
value="g">Grams</option><option value="kg">Kilograms</option><option
value="pounds">Pounds</option></select></td></tr></table><div style="color: #3D366F; font-
size:13px;">You Must Intake The Following Daily</div><table class="frms noborders"><tr><td
style="color: #3D366F; font-size:13px;">Fat:</td><td style="color: #3D366F; font-
size:13px;"><input type="text" id="rf" style="font-size:13px;" size="10" readonly></td><td><font
color="#3D366F" size="2" style='float:right'><label id="l1"></label> per
day</font></td></tr><tr><td style="color: #3D366F; font-size:13px;">Protein:</td><td
style="color: #3D366F; font-size:13px;"><input type="text" id="rp" style="font-size:13px;"
size="10" readonly></td><td><font color="#3D366F" size="2" style='float:right'><label
id="l2"></label> per day</font></td></tr><tr><td style="color: #3D366F; font-
size:13px;">Carbohydrate:</td><td style="color: #3D366F; font-size:13px;"><input type="text"
id="rh" style="font-size:13px;" size="10" readonly></td><td><font color="#3D366F" size="2"
style='float:right'><label id="l3"></label> per day</font></td></tr><tr><td style="color:
#3D366F; font-size:13px;">Alcohol:</td><td style="color: #3D366F; font-size:13px;"><input
type="text" id="ra" style="font-size:13px;" size="10" readonly></td><td><font color="#3D366F"
size="2" style='float:right'><label id="l4"></label> per day</font></td></tr></table>
</tr></td>
</table>
</div>
*********************************************************************************************
Age Calculator
640
<script type="text/javascript">
var startyear = "1910";
var endyear = "2010";
var dat = new Date();
var curday = dat.getDate();
var curmon = dat.getMonth()+1;
var curyear = dat.getFullYear();
function checkleapyear(datea)
{
if(datea.getYear()%4 == 0)
{
if(datea.getYear()% 10 != 0)
{
return true;
}
else
{
if(datea.getYear()% 400 == 0)
return true;
else
return false;
}
}
return false; } function DaysInMonth(Y, M) {
with (new Date(Y, M, 1, 12)) {
setDate(0);
return getDate();
} } function datediff(date1, date2) {
var y1 = date1.getFullYear(), m1 = date1.getMonth(), d1 = date1.getDate(),
y2 = date2.getFullYear(), m2 = date2.getMonth(), d2 = date2.getDate();
if (d1 < d2) {
m1--;
d1 += DaysInMonth(y2, m2);
}
if (m1 < m2) {
y1--;
m1 += 12;
}
return [y1 - y2, m1 - m2, d1 - d2]; } function calage() {
var calday = document.birthday.day.options[document.birthday.day.selectedIndex].value;
var calmon = document.birthday.month.options[document.birthday.month.selectedIndex].value;
var calyear = document.birthday.year.options[document.birthday.year.selectedIndex].value;
if(curday == "" || curmon=="" || curyear=="" || calday=="" || calmon=="" || calyear=="")
{
alert("please fill all the values and click go -");
}
else
{
var curd = new Date(curyear,curmon-1,curday);
var cald = new Date(calyear,calmon-1,calday);
var diff =
Date.UTC(curyear,curmon,curday,0,0,0) - Date.UTC(calyear,calmon,calday,0,0,0);
var dife = datediff(curd,cald);
document.birthday.age.value=dife[0]+" years, "+dife[1]+" months, and "+dife[2]+" days";
var monleft = (dife[0]*12)+dife[1];
var secleft = diff/1000/60;
var hrsleft = secleft/60;
var daysleft = hrsleft/24;
641
document.birthday.months.value=monleft+" Month since your birth";
document.birthday.daa.value=daysleft+" days since your birth";
document.birthday.hours.value=hrsleft+" hours since your birth";
document.birthday.min.value=secleft+" minutes since your birth";
var as = parseInt(calyear)+dife[0]+1;
var diff =
Date.UTC(as,calmon,calday,0,0,0) - Date.UTC(curyear,curmon,curday,0,0,0);
var datee = diff/1000/60/60/24;
document.birthday.nbday.value=datee+" days left for your next birthday";
} } </script>
<center>
<form name="birthday">
Date<select name="day" size="1">
<script type="text/javascript">for(var j=1;j<32;j++)document.write("<option
value="+j+">"+j+"</option>");
</script></select>
Month<select name="month" size="1">
<script type="text/javascript">for(var i=1;i<13;i++)document.write("<option
value="+i+">"+i+"</option>");
</script></select>
Year<select name="year" size="1">
<script type="text/javascript">for(var k=startyear;k<endyear;k++)document.write("<option
value="+k+">"+k+"</option>");
</script></select>
<input name="start" onclick="calage()" value="Calculate" type="button"><br>
<input name="age" size="40" value="Result"><br>
You have been living for:<br>
<table style="border:solid green 1px"> <tr><td>In months:</td><td><input name="months"
size="30"></td></tr> <tr><td>In days:</td><td><input name="daa" size="30"></td></tr> <tr><td>In
hours:</td><td><input name="hours" size="30"></td></tr> <tr><td>In minutes:</td><td><input
name="min" size="30"></td></tr> <tr><td colspan=2>Your next birthday will be in:</td></tr>
<tr><td colspan=2><input name="nbday" size="40"><a href="#" style="color:#3D366F;text-
decoration:none;cursor:pointer;font-size:10px"></a></td></tr> </table> </form>
</center>
*********************************************************************************************
<script>
function calc()
{
var wt = document.bmi.wg.value;
var ht = document.bmi.ht.value;
var op=document.bmi.opt1.value;
//SI value
var h = ht/100;
var si = Math.round((wt/(h*h))*100)/100;
document.bmi.si.value = si;
642
//US value
var lb = wt*2.2;
var ic = ht*0.39;
var us = Math.round((703*(lb/(ic * ic)))*100)/100;
document.bmi.us.value = us;
//UK value
var uk = Math.round((6.35*si)*100)/100;
document.bmi.uk.value = uk;
643
else if(si>18.5 && si<=25)
{
document.bmi.desc.value= d + "Normal";
}
else if(si>25 && si<=30)
{
document.bmi.desc.value=d + "Overweight";
}
else if(si>30)
{
document.bmi.desc.value=d + "Obese";
}
}
else{
ht = document.bmi.ht.value;
if(ht!="")
{
var cm=Math.round(ht/2.54);
var div=parseInt(cm/12);
var md=cm%12;
document.bmi.opt2.value=div;
document.bmi.opt3.value=md;
}
}
//Kilogram to pounds
if(pp=="pounds")
{
document.bmi.wg.value = Math.round((ww*2.2)*100)/100;
}
//Pounds to kilograms
else
{
document.bmi.wg.value=Math.round(ww/2.2);
644
}
}
</script>
<center>
<form name=bmi>
Weight: <input type=text name=wg size=5 >
<select name=opt1 onChange="unit()" >
<option value="pounds">pounds</option>
<option value="kilograms" selected>kilograms</option>
</select>
Height: <select name=opt2 onChange="conv(1)">
<option value="1">1'</option>
<option value="2">2'</option>
<option value="3">3'</option>
<option value="4">4'</option>
<option value="5">5'</option>
<option value="6">6'</option>
<option name=feet value="7">7'</option>
</select>
<select name=opt3 onChange="conv(2)">
<option value="0">0"</option>
<option value="1">1"</option>
<option value="2">2"</option>
<option value="3">3"</option>
<option value="4">4"</option>
<option value="5">5"</option>
<option value="6">6"</option>
<option value="7">7"</option>
<option value="8">8"</option>
<option value="9">9"</option>
<option value="10">10"</option>
<option value="11">11"</option>
</select>
or cms<input type=text name=ht size=5 onkeyup="conv(3)" class='innerc resform'>
<input type=button name=cc value="Calculate" onClick="calc()">
<table cellspacing=0 cellpadding=3 border=0>
<tr align=center class="abouttabletext"><td>SI Units: <input type=text readonly class=resform
name=si>
<tr align=center class="abouttabletext">
<td>US Units: <input type=text readonly class=resform name=us>
<tr align=center class="abouttabletext"><td>UK Units: <input type=text readonly class=resform
name=uk>
</table>
<table width=100%>
<tr><td colspan=2 align=center>
<input type="text" name=desc size=30 class=content readonly style="border:0px;">
</td>
</tr>
</table>
</form>
<script type="text/javascript" src="hbmi/bmi.js">
</script>
</center>
645
*********************************************************************************************
var a = as.value;
var ff = a[x];
if(isNaN(a))
a = a.substring(0,(a.length-1));
as.value = a;
}
function loanemi_calc()
{
646
if(lamt=="")
document.getElementById("lamt").focus();
else if(inte=="")
document.getElementById("dpay").focus();
else if(term=="")
document.getElementById("inte").focus();
else
if(dpay=="")
dpay = 0;
document.getElementById("term").value=dpay;//$("#dpay").val(dpay);
lamt = parseFloat(lamt);
dpay = parseFloat(dpay);
inte = parseFloat(inte);
term = parseFloat(term);
if(dpay<=lamt)
647
var r = inte/1200;
document.getElementById("emi").value=emi;
document.getElementById("tamt").value=tamt;
document.getElementById("tip").value=tip;
else
document.getElementById("dpay").value="";
document.getElementById("dpay").focus();
}
}
function reset()
{
document.getElementById("lamt").value="";
document.getElementById("dpay").value="";
document.getElementById("inte").value="";
document.getElementById("term").value="";
document.getElementById("emi").value="";
document.getElementById("tip").value="";
document.getElementById("tamt").value="" ;
}
</script>
648
<html>
<head><title>Vehicle Loan EMI Calculation</title>
</head>
<body>
<div id="calculator">
<div align='center'><h3>Vehicle Loan EMI Calculator </h3></div>
<table width="100%" border="0" cellpadding="0" cellspacing="4" ><tr><td colspan=2><table
width=100% height=100%>
<tr><td>
<form name=first><table align=center border=0 cellpadding=1 cellspacing=1 id=emi_calc
style='font-size:12px;'>
<tr><td>Amount (Vehicle Price)
</td> <td> <input type=text id=lamt onkeyup=checnum(this); maxlength=9> </td> </tr>
<tr><td>Down Payment
</td> <td> <input type=text id=dpay onkeyup=checnum(this); maxlength=9> </td> </tr>
<tr><td>Annual Interest Rate
</td> <td> <input type=text id=inte onkeyup=checnum(this); maxlength=9> % </td> </tr>
<tr><td>Term/Period </td> <td> <input type=text id=term onkeyup=checnum(this); maxlength=9>
months </td> </tr>
<tr><td colspan=2>
</td></tr>
<tr><td colspan=2 align=center><input type=button value='Calculate' onclick=loanemi_calc();>
<input type=button value='Reset' onclick="reset();"></td></tr>
<tr><td colspan=2 style="font-size:11px;" align="center" colspan='2' id='dumdiv'> <a href=" "
style="color: #3D366F; font-size:11px; text-decoration:none;" id=dum></a></td></tr>
<tr><td>Monthly Payment </td> <td> <input type=text id=emi readonly> </td> </tr>
<tr><td>Total Interest Payment
</td> <td> <input type=text id=tip readonly> </td> </tr>
<tr><td>Total Amount to Pay
</td> <td> <input type=text id=tamt readonly> </td> </tr></table>
</form></table>
</div>
</body>
</html>
*********************************************************************************************
<script type="text/javascript">
function checnum(as)
var a = as.value;
var ff = a[x];
if(isNaN(a))
649
{
a = a.substring(0,(a.length-1));
as.value = a;
}
function loanemi_calc()
{
if(lamt=="")
document.getElementById("lamt").focus();
else if(inte=="")
document.getElementById("dpay").focus();
else if(term=="")
document.getElementById("inte").focus();
else
650
{
if(dpay=="")
dpay = 0;
document.getElementById("term").value=dpay;//$("#dpay").val(dpay);
lamt = parseFloat(lamt);
dpay = parseFloat(dpay);
inte = parseFloat(inte);
term = parseFloat(term);
if(dpay<=lamt)
var r = inte/1200;
document.getElementById("emi").value=emi;
document.getElementById("tamt").value=tamt;
document.getElementById("tip").value=tip;
else
document.getElementById("dpay").value="";
document.getElementById("dpay").focus();
651
}
}
}
function reset()
{
document.getElementById("lamt").value="";
document.getElementById("dpay").value="";
document.getElementById("inte").value="";
document.getElementById("term").value="";
document.getElementById("emi").value="";
document.getElementById("tip").value="";
document.getElementById("tamt").value="" ;
}
</script>
<html>
<head><title>Vehicle Loan EMI Calculation</title>
</head>
<body>
<div id="calculator">
<div align='center'><h3>Vehicle Loan EMI Calculator </h3></div>
<table width="100%" border="0" cellpadding="0" cellspacing="4" ><tr><td colspan=2><table
width=100% height=100%>
<tr><td>
<form name=first><table align=center border=0 cellpadding=1 cellspacing=1 id=emi_calc
style='font-size:12px;'>
<tr><td>Amount (Vehicle Price)
</td> <td> <input type=text id=lamt onkeyup=checnum(this); maxlength=9> </td> </tr>
<tr><td>Down Payment
</td> <td> <input type=text id=dpay onkeyup=checnum(this); maxlength=9> </td> </tr>
<tr><td>Annual Interest Rate
</td> <td> <input type=text id=inte onkeyup=checnum(this); maxlength=9> % </td> </tr>
<tr><td>Term/Period </td> <td> <input type=text id=term onkeyup=checnum(this); maxlength=9>
months </td> </tr>
<tr><td colspan=2>
</td></tr>
<tr><td colspan=2 align=center><input type=button value='Calculate' onclick=loanemi_calc();>
<input type=button value='Reset' onclick="reset();"></td></tr>
<tr><td colspan=2 style="font-size:11px;" align="center" colspan='2' id='dumdiv'> <a href=" "
style="color: #3D366F; font-size:11px; text-decoration:none;" id=dum></a></td></tr>
<tr><td>Monthly Payment </td> <td> <input type=text id=emi readonly> </td> </tr>
<tr><td>Total Interest Payment
</td> <td> <input type=text id=tip readonly> </td> </tr>
<tr><td>Total Amount to Pay
</td> <td> <input type=text id=tamt readonly> </td> </tr></table>
</form></table>
</div>
</body>
</html>
*********************************************************************************************
652
Background video
<video autoplay loop muted poster="https://s3-us-west-2.amazonaws.com/s.cdpn.io/4273/polina.jpg"
id="background">
<source src="http://thenewcode.com/assets/videos/polina.webm" type="video/webm">
</video>
<style>
#background {
position: fixed;
top: 50%;
left: 50%;
min-width: 100%;
min-height: 100%;
width: auto;
height: auto;
z-index: -100;
-webkit-transform: translateX(-50%) translateY(-50%);
transform: translateX(-50%) translateY(-50%);
background: url(polina.jpg) no-repeat;
background-size: cover;
}
.container h1 {
color: white;
}
</style>
<html lang="en">
<head>
<meta charset="utf-8">
<title>title</title>
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
</head>
<body>
<video autoplay loop muted poster="https://s3-us-west-
2.amazonaws.com/s.cdpn.io/4273/polina.jpg" id="background">
<source src="http://thenewcode.com/assets/videos/polina.webm" type="video/webm">
</video>
<div class="container">
<div class="row">
<div class="col-md-12">
<h1> video</h1>
</div>
</div>
</div>
</body>
</html>
*********************************************************************************************
<style>
body{
background: #FFFF;
padding-top: 10px;
}
p{
color: green;
font-family: "Courier";
font-size: 20px;
margin: 10px 0 0 10px;
white-space: nowrap;
overflow: hidden;
width: 30em;
animation: type 4s steps(60, end);
}
p:nth-child(2){
animation: type2 8s steps(60, end);
}
p a{
color: lime;
text-decoration: none;
}
span{
animation: blink 1s infinite;
}
@keyframes type{
from { width: 0; }
}
@keyframes type2{
0%{width: 0;}
50%{width: 0;}
100%{ width: 100; }
}
@keyframes blink{
to{opacity: .0;}
}
::selection{
background: black;
}
</style>
*********************************************************************************************
654
Picture scroll box
<div style="height:200px;width:200px;overflow:scroll;">
<img src="http://i516.photobucket.com/albums/u323/natural_pics/milford_sound.jpg" border="0"
width="330" height="221" ><br />
<img src="http://i516.photobucket.com/albums/u323/natural_pics/franz_josef_glacier2.jpg"
border="0" width="330" height="221" />
</div>
*********************************************************************************************
</style>
</head>
<body>
<h2 align="center">Hover to Change the Photo </h2>
<a id="myButtonLink"></a>
</body>
</html>
*********************************************************************************************
<html>
<head>
<title>Scroll of Social Media Icon</title>
<style>
.nav
{
655
float:left; width:600px;
}
.social-roll {
height: 48px;
width: 48px;
margin: 10px;
float: left;
border-radius: 50%;
-webkit-transition: all ease 0.3s;
-moz-transition: all ease 0.3s;
-o-transition: all ease 0.3s;
-ms-transition: all ease 0.3s;
transition: all ease 0.3s;
}
.social-roll:hover {
box-shadow: 0px 0px 4px 1px rgba(0,0,0,0.8);
-webkit-transform:rotate(360deg);
-moz-transform:rotate(360deg);
-o-transform:rotate(360deg);
-ms-transform:rotate(360deg);
transform:rotate(360deg);
}
</style>
<body>
<div class="nav">
<div class="social-roll"><style="position: absolute; left: 1175px; top: 50px;"> <img
src="https://www.seeklogo.net/wp-content/uploads/2012/03/linkedin-icon-logo-vector-400x400.png"
width="30" height="30" onclick=
"window.open('http://www.linkedin.com','name','width=200,height=200')" />
</div>
</div>
</body>
</html>
*********************************************************************************************
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Css3 Button</title>
</head>
<style>
h2
{
656
font: bold 1.4em 'Lucida sans', 'Trebuchet MS', Tahoma, Arial;
color: #555;
}
.button
{
display: inline-block;
white-space: nowrap;
background-color: #ddd;
background-image: -webkit-gradient(linear, left top, left bottom, from(#09F), to(#09F));
background-image: -webkit-linear-gradient(top, #0095DD, #ccc);
background-image: -moz-linear-gradient(top, #0095DD, #0052A4);
background-image: -ms-linear-gradient(top, #0095DD, #0052A4);
background-image: -o-linear-gradient(top, #0095DD, #0052A4);
background-image: linear-gradient(top, #0095DD, #0052A4);
border: 1px solid #777;
padding: 0 1.5em;
margin: 0.5em;
font: bold 1em/2em Arial, Helvetica;
text-decoration: none;
color: #FFF;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
border-radius: 5px;
text-align: center;
}
.button:hover
{
background-color: #eee;
background-image: -webkit-gradient(linear, left top, left bottom, from(#fafafa), to(#ddd));
background-image: -webkit-linear-gradient(top, #48A4FF, #006CD9);
background-image: -moz-linear-gradient(top, #48A4FF, #006CD9);
background-image: -ms-linear-gradient(top, #48A4FF, #006CD9);
background-image: -o-linear-gradient(top, #48A4FF, #006CD9);
background-image: linear-gradient(top, #48A4FF, #006CD9);
}
.button:before
{
background: #ccc;
background: rgba(0,0,0,.1);
float: left;
width: 1em;
text-align: center;
font-size: 1.5em;
margin: 0 1em 0 -1em;
padding: 0 .2em;
-moz-box-shadow: 1px 0 0 rgba(0,0,0,.5), 2px 0 0 rgba(255,255,255,.5);
-webkit-box-shadow: 1px 0 0 rgba(0,0,0,.5), 2px 0 0 rgba(255,255,255,.5);
box-shadow: 1px 0 0 rgba(0,0,0,.5), 2px 0 0 rgba(255,255,255,.5);
-moz-border-radius: .15em 0 0 .15em;
-webkit-border-radius: .15em 0 0 .15em;
border-radius: .15em 0 0 .15em;
pointer-events: none;
}
/* Hexadecimal entities for the icons */
.add:before
{
content: "\271A";
657
}
.edit:before
{
content: "\270E";
}
.delete:before
{
content: "\2718";
}
.save:before
{
content: "\2714";
}
.email:before
{
content: "\2709";
}
</style>
<body>
<h2>Button</h2>
<a href="#" class="button">Button</a>
<a href="#" class="button add">Add</a>
<a href="#" class="button edit">Edit</a>
<a href="#" class="button delete">Delete</a>
<a href="#" class="button save">Save</a>
<a href="" class="button email">Send email</a>
<a href="" class="button email"> email</a>
</body>
</html>
*********************************************************************************************
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("#hide").click(function(){
$("p").hide();
});
$("#show").click(function(){
$("p").show();
});
});
</script>
</head>
<body>
658
<p>If you click on the "Hide" button, I will disappear and If you click on "Show" button, I will
appear.</p>
<button id="hide" style="font-face: 'Comic Sans MS'; font-size: smaller; color: teal; background-
color: #FFFFC0; border: 3pt ridge lightgrey">Hide </button>
<button id="show"style="font-face: 'Comic Sans MS'; font-size: larger; color: teal; background-
color: #FFFFC0; border: 3pt ridge lightgrey">Show</button>
</body>
</html>
*********************************************************************************************
<div id="social-share-container">
<div id="custom-tweet-button">
<a id="tweetShare" href="https://twitter.com/share?url="+encodeURIComponent(document.URL);
target="_blank"> <img src="https://www.webceo.com/blog/wp-content/uploads/2015/11/twitter.jpg"
style="width:100x;height:40px; margin-top: 4px; ">
</a>
</div>
</div>
<!-- code for share via facebook begins from here & this code is autogenerated from the
website:https://developers.facebook.com/docs/plugins/share-button-->
<div id="fb-root"></div>
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.7&appId=950274721762534";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
*********************************************************************************************
659
TEXT PLUS IMAGE SLIDER IN CSS
<!DOCTYPE html>
<html>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://www.w3schools.com/lib/w3.css">
<style>
.mySlides {display:none;}
</style>
<body>
</div>
<script>
var slideIndex = 0;
carousel();
function carousel() {
var i;
var x = document.getElementsByClassName("mySlides");
for (i = 0; i < x.length; i++) {
x[i].style.display = "none";
}
slideIndex++;
if (slideIndex > x.length) {slideIndex = 1}
x[slideIndex-1].style.display = "block";
setTimeout(carousel, 2000);
}
</script>
</body>
</html>
660
*********************************************************************************************
<!DOCTYPE html>
<html>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://www.w3schools.com/lib/w3.css">
<body>
<div class="w3-container">
<h2>Slideshow Caption</h2>
<p>Add a caption text for each image slide with the w3-display-* classes (topleft, topmiddle,
topright, bottomleft, bottommiddle, bottomright or middle).</p>
</div>
661
<a class="w3-btn-floating w3-hover-dark-grey" style="position:absolute;top:45%;right:0"
onclick="plusDivs(1)">❯</a>
</div>
<script>
var slideIndex = 1;
showDivs(slideIndex);
function plusDivs(n) {
showDivs(slideIndex += n);
}
function showDivs(n) {
var i;
var x = document.getElementsByClassName("mySlides");
if (n > x.length) {slideIndex = 1}
if (n < 1) {slideIndex = x.length}
for (i = 0; i < x.length; i++) {
x[i].style.display = "none";
}
x[slideIndex-1].style.display = "block";
}
</script>
</body>
</html>
*********************************************************************************************
<div class="w3-container">
<h2>Animated Slides</h2>
<p>Slide or fade in an element from the top, bottom, left or right of the screen with the w3-
animate-* classes.</p>
</div>
<div class="w3-content w3-section" style="max-width:500px">
</div>
<script>
662
var myIndex = 0;
carousel();
function carousel() {
var i;
var x = document.getElementsByClassName("mySlides");
for (i = 0; i < x.length; i++) {
x[i].style.display = "none";
}
myIndex++;
if (myIndex > x.length) {myIndex = 1}
x[myIndex-1].style.display = "block";
setTimeout(carousel, 2500);
}
</script>
</body>
</html>
*********************************************************************************************
<!DOCTYPE html>
<html>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://www.w3schools.com/lib/w3.css">
<body>
<script>
var myIndex = 0;
carousel();
function carousel() {
var i;
var x = document.getElementsByClassName("mySlides");
for (i = 0; i < x.length; i++) {
x[i].style.display = "none";
}
myIndex++;
if (myIndex > x.length) {myIndex = 1}
x[myIndex-1].style.display = "block";
setTimeout(carousel, 9000);
}
</script>
</body>
</html>
663
*********************************************************************************************
<script>
function type_text()
{
contents='';
row=Math.max(0,index-7);
while(row<index)
contents += tl[row++] + '\r\n';
document.forms[0].elements[0].value = contents + tl[index].substring(0,text_pos) + "_";
if(text_pos++==str_length)
{
text_pos=0;
index++;
if(index!=tl.length)
{
str_length=tl[index].length;
setTimeout("type_text()",1500);
}
} else
setTimeout("type_text()",speed);
}
window.onload = function(){
type_text();
}
</script>
*********************************************************************************************
665
Show more or less content using jquery
<HTML>
<HEAD>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<TITLE>Dynamically shortened Text with Show More link using jQuery</TITLE>
<STYLE>
body, input{
font-family: Calibri, Arial;
margin: 0px;
padding: 0px;
}
a {
color: #0254EB
}
a:visited {
color: #0254EB
}
#header h2 {
color: white;
background-color: #00A1E6;
margin:0px;
padding: 5px;
}
.comment {
width: 400px;
background-color: #f0f0f0;
margin: 10px;
}
a.morelink {
text-decoration:none;
outline: none;
}
.morecontent span {
display: none;
}
</STYLE>
</HEAD>
<BODY>
<div id="header">
<H2>
Dynamically shortened Text with Show More link using jQuery
</H2>
</div>
<br/>
<div class="comment more">
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Vestibulum laoreet, nunc eget laoreet sagittis,
quam ligula sodales orci, congue imperdiet eros tortor ac lectus.
Duis eget nisl orci. Aliquam mattis purus non mauris
blandit id luctus felis convallis.
Integer varius egestas vestibulum.
Nullam a dolor arcu, ac tempor elit. Donec.
</div>
666
</BODY>
<SCRIPT>
$(document).ready(function() {
var showChar = 100;
var ellipsestext = "...";
var moretext = "more";
var lesstext = "less";
$('.more').each(function() {
var content = $(this).html();
$(this).html(html);
}
});
$(".morelink").click(function(){
if($(this).hasClass("less")) {
$(this).removeClass("less");
$(this).html(moretext);
} else {
$(this).addClass("less");
$(this).html(lesstext);
}
$(this).parent().prev().toggle();
$(this).prev().toggle();
return false;
});
});
</SCRIPT>
</HTML>
*********************************************************************************************
<style>
#primary_nav_wrap
{
margin-top:15px
#primary_nav_wrap ul
667
{
list-style:none;
position:relative;
float:left;
margin:0;
z-index:1000;
padding:0
#primary_nav_wrap ul a
{
display:block;
color:#333;
text-decoration:none;
font-weight:700;
font-size:12px;
line-height:32px;
padding:0 15px;
font-family:"HelveticaNeue","Helvetica Neue",Helvetica,Arial,sans-serif
#primary_nav_wrap ul li
{
position:relative;
float:left;
margin:0;
padding:0
#primary_nav_wrap ul li.current-menu-item
{
background:#ddd
#primary_nav_wrap ul li:hover
{
background:#f6f6f6
#primary_nav_wrap ul ul
{
display:none;
position:absolute;
top:100%;
left:0;
background:#fff;
padding:0
#primary_nav_wrap ul ul li
{
float:none;
668
width:200px
#primary_nav_wrap ul ul a
{
line-height:120%;
padding:10px 15px
#primary_nav_wrap ul ul ul
{
top:0;
left:100%
}
</style>
669
<ul>
<li class="dir"><a href="#">Sub Menu 1</a></li>
<li class="dir"><a href="#">Sub Menu 2 </a>
<ul>
<li><a href="#">Category 1</a></li>
<li><a href="#">Category 2</a></li>
<li><a href="#">Category 3</a></li>
<li><a href="#">Category 4</a></li>
<li><a href="#">Category 5</a></li>
</ul>
</li>
<li><a href="#">Sub Menu 3</a></li>
<li><a href="#">Sub Menu 4</a></li>
<li><a href="#">Sub Menu 5</a></li>
</ul>
</li>
<li><a href="#">Menu 4</a></li>
<li><a href="#">Menu 5</a></li>
<li><a href="#">Menu 6</a></li>
<li><a href="#">Contact Us</a></li>
</ul>
</nav>
*********************************************************************************************
<frameset cols="25%,*,25%">
<frame src="page1.html">
<frame src="page2.html">
<frame src="page3.html">
</frameset>
*********************************************************************************************
670
Background music
<script>
musi="http://dddproduktionen.weebly.com/files/theme/DDDmusic.mp3"
function mus1()
{
if (t.options.selectedIndex==0){
mus.innerHTML="<embed src="+musi+" loop=-1>"
}
if (t.options.selectedIndex==1){
mus.innerHTML=""
}
}
document.write("<span id='mus' style='position:absolute;top:-90000'><embed src="+musi+" width=0
height=0 loop=-1></span>")
</script>
*********************************************************************************************
Search for text in webpage
<div><h2>Find and highlight text here </h2>
<form action="" method="" id="search" name="search">
<input name="query" id="query" type="text" size="30" maxlength="30">
<input name="searchit" type="button" value="Search" onClick="highlightSearch()">
</form></div>
<div id="searchtext">
<p>JavaScript is the programming language of the Web. The overwhelming majority of
modern websites use JavaScript, and all modern web browsers—on desktops, game
consoles, tablets, and smart phones—include JavaScript interpreters, making Java-
Script the most ubiquitous programming language in history. JavaScript is part of the
triad of technologies that all Web developers must learn: HTML to specify the content
of web pages, CSS to specify the presentation of web pages, and JavaScript to specify
the behavior of web pages. This book will help you master the language.</p>
<p>If you are already familiar with other programming languages, it may help you to know
that JavaScript is a high-level, dynamic, untyped interpreted programming language
that is well-suited to object-oriented and functional programming styles. JavaScript
derives its syntax from Java, its first-class functions from Scheme, and its prototypebased
inheritance from Self. But you do not need to know any of those languages, or
be familiar with those terms, to use this book and learn JavaScript.</p>
<p>The name "JavaScript" is actually somewhat misleading. <span>Except</span> for a superficial
syntactic
resemblance, JavaScript is completely different from the Java programming language.
And JavaScript has long since outgrown its scripting-language roots to become
a robust and efficient general-purpose language. The latest version of the language (see
the sidebar) defines new features for serious large-scale software development.</p>
</div>
<script>
function highlightSearch() {
var text = document.getElementById("query").value;
var query = new RegExp("(\\b" + text + "\\b)", "gim");
var e = document.getElementById("searchtext").innerHTML;
var enew = e.replace(/(<span>|<\/span>)/igm, "");
671
document.getElementById("searchtext").innerHTML = enew;
var newe = enew.replace(query, "<span>$1</span>");
document.getElementById("searchtext").innerHTML = newe;
</script>
<style>
#searchtext span{
background-color:#FF9;
color:#555;
}
div {
padding: 10px;
}
</style>
*********************************************************************************************
Android loan calculator
MainActivity.java
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import java.text.DecimalFormat;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
672
double loanPeriod = Integer.parseInt(mLoanPeriod.getText().toString());
double r = interestRate/1200;
double r1 = Math.pow(r+1,loanPeriod);
mMontlyPaymentResult.setText(new DecimalFormat("##.##").format(monthlyPayment));
mTotalPaymentsResult.setText(new DecimalFormat("##.##").format(totalPayment));
}
}
activity_main.xml
strings.xml
<resources>
<string name="hello_world">Hello world!</string>
<string name="menu_settings">Settings</string>
<string name="loan_amount_prompt">Loan amount:  </string>
<string name="interest_rate_prompt">Interest rate:  </string>
<string name="loan_period_prompt">Months:  </string>
<string name="loan_button_text">Calculate Payments</string>
<string name="monthly_payment_prompt">Monthly payment:  </string>
<string name="total_payments_prompt">Total payments:  </string>
</resources>
*********************************************************************************************
Autotyping of 2 text lines
<script>
674
TypingText.currentIndex = 0;
TypingText.runAll = function() {
for(var i = 0; i < TypingText.all.length; i++) TypingText.all[i].run();
}
TypingText.prototype.run = function() {
if(this.running) return;
if(typeof this.origText == "undefined") {
setTimeout("document.getElementById('" + this.element.id + "').typingText.run()",
this.interval); // We haven't finished loading yet. Have patience.
return;
}
if(this.currentText == "") this.element.innerHTML = "";
// this.origText = this.origText.replace(/<([^<])*>/, ""); // Strip HTML from text.
if(this.currentChar < this.origText.length) {
if(this.origText.charAt(this.currentChar) == "<" && !this.inTag) {
this.tagBuffer = "<";
this.inTag = true;
this.currentChar++;
this.run();
return;
} else if(this.origText.charAt(this.currentChar) == ">" && this.inTag) {
this.tagBuffer += ">";
this.inTag = false;
this.currentText += this.tagBuffer;
this.currentChar++;
this.run();
return;
} else if(this.inTag) {
this.tagBuffer += this.origText.charAt(this.currentChar);
this.currentChar++;
this.run();
return;
} else if(this.origText.charAt(this.currentChar) == "&" && !this.inHTMLEntity) {
this.HTMLEntityBuffer = "&";
this.inHTMLEntity = true;
this.currentChar++;
this.run();
return;
} else if(this.origText.charAt(this.currentChar) == ";" && this.inHTMLEntity) {
this.HTMLEntityBuffer += ";";
this.inHTMLEntity = false;
this.currentText += this.HTMLEntityBuffer;
this.currentChar++;
this.run();
return;
} else if(this.inHTMLEntity) {
this.HTMLEntityBuffer += this.origText.charAt(this.currentChar);
this.currentChar++;
this.run();
return;
} else {
this.currentText += this.origText.charAt(this.currentChar);
}
this.element.innerHTML = this.currentText;
this.element.innerHTML += (this.currentChar < this.origText.length - 1 ? (typeof this.cursor
== "function" ? this.cursor(this.currentText) : this.cursor) : "");
this.currentChar++;
setTimeout("document.getElementById('" + this.element.id + "').typingText.run()",
this.interval);
} else {
this.currentText = "";
this.currentChar = 0;
this.running = false;
this.finishedCallback();
}
}
675
</script>
<p id="example2">This text has a <b>slashing cursor</b> at the end. <br />And this is on a new
line, thanks to the <br> tag.</p>
<script type="text/javascript">
//Define first typing example:
new TypingText(document.getElementById("example1"));
*********************************************************************************************
CSS3 Text Animation Effect
<div class="container">
<div class="header">
<div class="clr"></div>
</div>
<div class="sp-container">
<div class="sp-content">
<div class="sp-globe"></div>
<h2 class="frame-1">It's destroying the planet</h2>
<h2 class="frame-4">Now!</h2>
</div>
</div>
</div>
<style>
@font-face {
font-family: 'Electrolize';
font-style: normal;
font-weight: 400;
676
src: local('Electrolize'), local('Electrolize-Regular'),
url(http://themes.googleusercontent.com/static/fonts/electrolize/v2/DDy9sgU2U7S4xAwH5thnJ4bN6UDyH
WBl620a-IRfuBk.woff) format('woff');
}
body {
background: #310404 url(http://web-sonick.zz.mu/images/sl/red_texture.jpg) repeat top left;
font-family: 'Electrolize';
}
.container{
width: 100%;
position: relative;
overflow:hidden;
}
a {
text-decoration:none;
}
h1.main,p.demos {
-webkit-animation-delay: 18s;
-moz-animation-delay: 18s;
-ms-animation-delay: 18s;
animation-delay: 18s;
}
.sp-container {
position: fixed;
top: 0px;
left: 0px;
width: 100%;
height: 100%;
z-index: 0;
background: -webkit-radial-gradient(rgba(0, 0, 0, 0.1), rgba(0, 0, 0, 0.3) 35%, rgba(0, 0, 0,
0.7));
background: -moz-radial-gradient(rgba(0, 0, 0, 0.1), rgba(0, 0, 0, 0.3) 35%, rgba(0, 0, 0,
0.7));
background: -ms-radial-gradient(rgba(0, 0, 0, 0.1), rgba(0, 0, 0, 0.3) 35%, rgba(0, 0, 0, 0.7));
background: radial-gradient(rgba(0, 0, 0, 0.1), rgba(0, 0, 0, 0.3) 35%, rgba(0, 0, 0, 0.7));
}
.sp-content {
position: absolute;
width: 100%;
height: 100%;
left: 0px;
top: 0px;
z-index: 1000;
}
.sp-container h2 {
position: absolute;
top: 50%;
line-height: 100px;
height: 90px;
margin-top: -50px;
font-size: 90px;
width: 100%;
text-align: center;
color: transparent;
-webkit-animation: blurFadeInOut 3s ease-in backwards;
-moz-animation: blurFadeInOut 3s ease-in backwards;
-ms-animation: blurFadeInOut 3s ease-in backwards;
animation: blurFadeInOut 3s ease-in backwards;
}
.sp-container h2.frame-1 {
-webkit-animation-delay: 0s;
-moz-animation-delay: 0s;
677
-ms-animation-delay: 0s;
animation-delay: 0s;
}
.sp-container h2.frame-2 {
-webkit-animation-delay: 3s;
-moz-animation-delay: 3s;
-ms-animation-delay: 3s;
animation-delay: 3s;
}
.sp-container h2.frame-3 {
-webkit-animation-delay: 6s;
-moz-animation-delay: 6s;
-ms-animation-delay: 6s;
animation-delay: 6s;
}
.sp-container h2.frame-4 {
font-size: 200px;
-webkit-animation-delay: 9s;
-moz-animation-delay: 9s;
-ms-animation-delay: 9s;
animation-delay: 9s;
}
.sp-container h2.frame-5 {
-webkit-animation: none;
-moz-animation: none;
-ms-animation: none;
animation: none;
color: transparent;
text-shadow: 0px 0px 1px #fff;
}
.sp-container h2.frame-5 span {
-webkit-animation: blurFadeIn 3s ease-in 12s backwards;
-moz-animation: blurFadeIn 1s ease-in 12s backwards;
-ms-animation: blurFadeIn 3s ease-in 12s backwards;
animation: blurFadeIn 3s ease-in 12s backwards;
color: transparent;
text-shadow: 0px 0px 1px #fff;
}
.sp-container h2.frame-5 span:nth-child(2) {
-webkit-animation-delay: 13s;
-moz-animation-delay: 13s;
-ms-animation-delay: 13s;
animation-delay: 13s;
}
.sp-container h2.frame-5 span:nth-child(3) {
-webkit-animation-delay: 14s;
-moz-animation-delay: 14s;
-ms-animation-delay: 14s;
animation-delay: 14s;
}
.sp-globe {
position: absolute;
width: 282px;
height: 273px;
left: 50%;
top: 50%;
margin: -137px 0 0 -141px;
background: transparent url(http://web-sonick.zz.mu/images/sl/globe.png) no-repeat top left;
-webkit-animation: fadeInBack 3.6s linear 14s backwards;
-moz-animation: fadeInBack 3.6s linear 14s backwards;
-ms-animation: fadeInBack 3.6s linear 14s backwards;
animation: fadeInBack 3.6s linear 14s backwards;
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=30)";
filter: alpha(opacity=30);
opacity: 0.3;
-webkit-transform: scale(5);
678
-moz-transform: scale(5);
-o-transform: scale(5);
-ms-transform: scale(5);
transform: scale(5);
}
.sp-circle-link {
position: absolute;
left: 50%;
bottom: 100px;
margin-left: -50px;
text-align: center;
line-height: 100px;
width: 100px;
height: 100px;
background: #fff;
color: #3f1616;
font-size: 25px;
-webkit-border-radius: 50%;
-moz-border-radius: 50%;
border-radius: 50%;
-webkit-animation: fadeInRotate 1s linear 16s backwards;
-moz-animation: fadeInRotate 1s linear 16s backwards;
-ms-animation: fadeInRotate 1s linear 16s backwards;
animation: fadeInRotate 1s linear 16s backwards;
-webkit-transform: scale(1) rotate(0deg);
-moz-transform: scale(1) rotate(0deg);
-o-transform: scale(1) rotate(0deg);
-ms-transform: scale(1) rotate(0deg);
transform: scale(1) rotate(0deg);
}
.sp-circle-link:hover {
background: #85373b;
color: #fff;
}
/**/
@-webkit-keyframes blurFadeInOut{
0%{
opacity: 0;
text-shadow: 0px 0px 40px #fff;
-webkit-transform: scale(1.3);
}
20%,75%{
opacity: 1;
text-shadow: 0px 0px 1px #fff;
-webkit-transform: scale(1);
}
100%{
opacity: 0;
text-shadow: 0px 0px 50px #fff;
-webkit-transform: scale(0);
}
}
@-webkit-keyframes blurFadeIn{
0%{
opacity: 0;
text-shadow: 0px 0px 40px #fff;
-webkit-transform: scale(1.3);
}
50%{
opacity: 0.5;
text-shadow: 0px 0px 10px #fff;
-webkit-transform: scale(1.1);
}
100%{
opacity: 1;
text-shadow: 0px 0px 1px #fff;
679
-webkit-transform: scale(1);
}
}
@-webkit-keyframes fadeInBack{
0%{
opacity: 0;
-webkit-transform: scale(0);
}
50%{
opacity: 0.4;
-webkit-transform: scale(2);
}
100%{
opacity: 0.2;
-webkit-transform: scale(5);
}
}
@-webkit-keyframes fadeInRotate{
0%{
opacity: 0;
-webkit-transform: scale(0) rotate(360deg);
}
100%{
opacity: 1;
-webkit-transform: scale(1) rotate(0deg);
}
}
/**/
@-moz-keyframes blurFadeInOut{
0%{
opacity: 0;
text-shadow: 0px 0px 40px #fff;
-moz-transform: scale(1.3);
}
20%,75%{
opacity: 1;
text-shadow: 0px 0px 1px #fff;
-moz-transform: scale(1);
}
100%{
opacity: 0;
text-shadow: 0px 0px 50px #fff;
-moz-transform: scale(0);
}
}
@-moz-keyframes blurFadeIn{
0%{
opacity: 0;
text-shadow: 0px 0px 40px #fff;
-moz-transform: scale(1.3);
}
100%{
opacity: 1;
text-shadow: 0px 0px 1px #fff;
-moz-transform: scale(1);
}
}
@-moz-keyframes fadeInBack{
0%{
opacity: 0;
-moz-transform: scale(0);
}
50%{
opacity: 0.4;
-moz-transform: scale(2);
}
680
100%{
opacity: 0.2;
-moz-transform: scale(5);
}
}
@-moz-keyframes fadeInRotate{
0%{
opacity: 0;
-moz-transform: scale(0) rotate(360deg);
}
100%{
opacity: 1;
-moz-transform: scale(1) rotate(0deg);
}
}
/**/
@keyframes blurFadeInOut{
0%{
opacity: 0;
text-shadow: 0px 0px 40px #fff;
transform: scale(1.3);
}
20%,75%{
opacity: 1;
text-shadow: 0px 0px 1px #fff;
transform: scale(1);
}
100%{
opacity: 0;
text-shadow: 0px 0px 50px #fff;
transform: scale(0);
}
}
@keyframes blurFadeIn{
0%{
opacity: 0;
text-shadow: 0px 0px 40px #fff;
transform: scale(1.3);
}
50%{
opacity: 0.5;
text-shadow: 0px 0px 10px #fff;
transform: scale(1.1);
}
100%{
opacity: 1;
text-shadow: 0px 0px 1px #fff;
transform: scale(1);
}
}
@keyframes fadeInBack{
0%{
opacity: 0;
transform: scale(0);
}
50%{
opacity: 0.4;
transform: scale(2);
}
100%{
opacity: 0.2;
transform: scale(5);
}
}
@keyframes fadeInRotate{
0%{
681
opacity: 0;
transform: scale(0) rotate(360deg);
}
100%{
opacity: 1;
transform: scale(1) rotate(0deg);
}
}
</style>
*********************************************************************************************
682
*********************************************************************************************
*********************************************************************************************
1.
2.
*********************************************************************************************
Scrolling of text
1. scrolling of text in one direction
<marquee> <p><font size="5" face="calibri" color="black" > <div style="margin-top: 19px"> Where
Mc <sup> 2 </sup> = total energy </div> </font> </p> </marquee>
683
<marquee behavior="alternate"> <p><font size="5" face="calibri" color="black" > <div
style="margin-top: 19px"> Where Mc <sup> 2 </sup> = total energy </div> </font> </p></marquee>
*********************************************************************************************
Image Zoom
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<style>
.pic{
width:509px;
height:509px;
}
.picbig{
position: absolute;
width:0px;
-webkit-transition:width 0.3s linear 0s;
transition:width 0.3s linear 0s;
z-index:10;
}
.pic:hover + .picbig{
width:500px;
}
</style>
</head>
<body>
<img class="pic" src="http://static0.therichestimages.com/cdn/1728/905/100/c/wp-
content/uploads/2016/01/2016-fashion-trends.jpg" alt="Adam">
<img class="picbig" src="http://static0.therichestimages.com/cdn/1728/905/100/c/wp-
content/uploads/2016/01/2016-fashion-trends.jpg" alt="Adam">
</body>
</html>
*********************************************************************************************
<!DOCTYPE html> <html > <head> <style type="text/css"> .zoomout img { height: 300px; width:
300px; -webkit-transition: all 2s ease; -moz-transition: all 2s ease; -ms-transition: all 2s
ease; transition: all 2s ease; } .zoomout img:hover { width: 200px; height: 200px; } </style>
</head> <body> <div class="zoomout"> <img src="img/zimage.png" title="Image shrink CSS hover
effect" /> </div> </body>
*********************************************************************************************
684
*, *::before, *::after{
-moz-box-sizing: border-box;
box-sizing: border-box;
html, body{
margin: 0px;
padding: 0px;
font-family: 'Lato',sans-serif;
font-size: 18px;
font-weight: 300;
height: 100%;
color: #fff;
}
.container{
width: 1024px;
max-width: 100%;
margin: auto;
display: block;
text-align: center;
}
.hero{
width: 100%;
height: 40%;
background: #3498db;
display: table;
}
h1{
color: #2c3e50;
text-align: center;
margin: 0;
padding: 0;
display: table-cell;
vertical-align: middle;
text-align: center;
color: #fff;
font-weight: 300;
}
figure{
width: 400px;
height: 300px;
overflow: hidden;
position: relative;
display: inline-block;
vertical-align: top;
border: 5px solid #fff;
box-shadow: 0 0 5px #ddd;
margin: 1em;
}
figcaption{
position: absolute;
left: 0; right: 0;
top: 0; bottom: 0;
text-align: center;
font-weight: bold;
width: 100%;
height: 100%;
display: table;
685
}
figcaption div{
display: table-cell;
vertical-align: middle;
position: relative;
top: 20px;
opacity: 0;
color: #2c3e50;
text-transform: uppercase;
}
figcaption div:after{
position: absolute;
content: "";
left: 0; right: 0;
bottom: 40%;
text-align: center;
margin: auto;
width: 0%;
height: 2px;
background: #2c3e50;
}
figure img{
-webkit-transition: all 0.5s linear;
transition: all 0.5s linear;
-webkit-transform: scale3d(1, 1, 1);
transform: scale3d(1, 1, 1);
}
figure:hover figcaption{
background: rgba(255,255,255,0.3);
}
figcaption:hover div{
opacity: 1;
top: 0;
}
figcaption:hover div:after{
width: 50%;
}
figure:hover img{
-webkit-transform: scale3d(1.2, 1.2, 1);
transform: scale3d(1.2, 1.2, 1);
}
/*font-face*/
@font-face {
font-family: 'Lato';
font-style: normal;
font-weight: 100;
src: local('Lato Hairline'), local('Lato-Hairline'),
url(http://themes.googleusercontent.com/static/fonts/lato/v6/boeCNmOCCh-EWFLSfVffDg.woff)
format('woff');
}
@font-face {
font-family: 'Lato';
font-style: normal;
font-weight: 300;
686
src: local('Lato Light'), local('Lato-Light'),
url(http://themes.googleusercontent.com/static/fonts/lato/v6/KT3KS9Aol4WfR6Vas8kNcg.woff)
format('woff');
}
@font-face {
font-family: 'Lato';
font-style: normal;
font-weight: 400;
src: local('Lato Regular'), local('Lato-Regular'),
url(http://themes.googleusercontent.com/static/fonts/lato/v6/9k-RPmcnxYEPm8CNFsH2gg.woff)
format('woff');
}
@font-face {
font-family: 'Lato';
font-style: normal;
font-weight: 700;
src: local('Lato Bold'), local('Lato-Bold'),
url(http://themes.googleusercontent.com/static/fonts/lato/v6/wkfQbvfT_02e2IWO3yYueQ.woff)
format('woff');
}
</style>
<div class="hero">
<h1>Image Scale <strong>on Hover</strong> </h1>
</div>
<div class="container">
<figure>
<img src="https://d13yacurqjgara.cloudfront.net/users/220419/screenshots/1714518/shot-
codigo.jpg" alt="Thumb" width="400" height="300" />
<figcaption><div>Thumbnail Caption</div></figcation>
</figure>
</div>
*********************************************************************************************
Zoom in and out button
*********************************************************************************************
687
Spell Checker
</textarea>
*********************************************************************************************
<script type="text/javascript">
//<![CDATA[
<!--
function calculate()
{
var itemPrice = document.purchaseData.price.value;
var discountRate = document.purchaseData.pDiscount.value;
var taxRate = document.purchaseData.pSalesTax.value;
}
// -->
//]]>
</script>
</head>
<body style="background-color:#FFFFFF">
<blockquote>
<h1>
Find The Total Cost
</h1>
<form name="purchaseData"
id="purchaseData">
<table width="100%"
border="0"
cellpadding="8">
688
<tr>
<td style="text-align:left">
<p1>Item Price</p1>
<p>
<input type="text"
name="price"
size="20"
maxlength="25" />
</p>
</td>
</tr>
<tr>
<td style="text-align:left">
<p1>Percent Discount</p1>
<p>
<input type="text"
name="pDiscount"
size="20"
maxlength="25"
value="0" />
</p>
</td>
</tr>
<tr>
<td style="text-align:left">
<p1>Percent Sale Tax</p1>
<p>
<input type="text"
name="pSalesTax"
size="20"
maxlength="25"
value="6" />
</p>
</td>
</tr>
<tr>
<td style="text-align:left">
<input type="button"
value="Compute"
onclick="calculate();" />
</td>
</tr>
<tr>
<td style="text-align:left">
<p1>Amount of Discount</p1>
<p>
<input type="text"
name="discount"
size="20"
maxlength="25" />
</p>
</td>
</tr>
<tr>
<td style="text-align:left">
<p>Sales Tax</p>
<p>
<input type="text"
689
name="salesTax"
size="20"
maxlength="25" />
</p>
</td>
</tr>
<tr>
<td style="text-align:left">
<p>Total Cost</p>
<p>
<input type="text"
name="cost"
size="20"
maxlength="25" />
</p>
</td>
</tr>
</table>
</form>
</blockquote>
</body>
</html>
*********************************************************************************************
*********************************************************************************************
<script language="javascript">
<!--//
/*This Script allows people to enter by using a form that asks for a
UserID and Password*/
function pasuser(form) {
if (form.id.value=="JavaScript") {
if (form.pass.value=="Kit") {
location="page2.html"
} else {
alert("Invalid Password")
}
} else { alert("Invalid UserID")
}
}
//-->
</script>
<center>
<table bgcolor="white" cellpadding="12" border="1">
<tr><td colspan="2"><center><h1>
<img src="http://ultimatefbchallenge.com/members/wp-content/uploads/2011/05/keyTosuccess-
300x300.jpg" style="width:323x;height:100px; margin-top: 4px; ">
</h1></center></td></tr>
<tr><td><h1><b>UserID:</b></h1></td><td><form name="login"><input
name="id" type="text"></td></tr>
<tr><td><h1><b>Password:</b></h1></td><td><input name="pass"
type="password"></td></tr>
<tr><td><center><input type="button" value="Login"
onClick="pasuser(this.form)"></center></td><td><center><br><input
type="Reset"></form></td></tr></table></center>
*********************************************************************************************
PHP (Hypertext Preprocessor)
691
PHP / Hypertext Preprocessor (designed by an Greenlandic-Danish programmer “Rasmus Lerdorf” in 1994- as an
efficient alternative to other scripting languages like Ruby, Perl and Microsoft’s ASP) is an relatively free (not
licensed by a major corporation) popular efficient server side programming language (and relatively easy one to
master and quick to learn) that carries out common website duties like accepting passwords, authenticating users,
and managing forum posts and guest books.
<?php
echo "Hello World!";
?>
echo "Hello World!"; → denote the statement that makes provision to print the output:
Hello World!
on the screen.
Even If you replace the statement
echo "Hello World!";
by the statement
print "Hello World!";
i.e.,
<?php
print "Hello World!";
?>
There will be no change in the output on the screen (i.e., echo and print are more or less the same. They are both
used to output data to the console screen).
<?
print "Hello World!";
?>
692
Even if you write the statement
Program 1.1
(a)
<?php
echo "Hello World!";
echo "Hello World!";
?>
Output on the screen:
Hello World!Hello World!
(b)
<?php
echo "\n Hello World!";
echo "\n Hello World!";
?>
(c)
<?php
echo "Hello World!";
echo "\t Hello World!";
?>
693
Output on the screen:
Hello World! Hello World!
Program 1.2
<?php
$num1 =1;
$num2=5;
$sum = $num1 + $num2;
echo "Sum of the two numbers is : $sum";
?>
The statement
echo "Sum of the two numbers is : $sum";
make provision to print the output:
Sum of the two numbers is : 6 (which is 1+5)
on the screen.
Note:
Suppose if you omit the leading $ symbol before a variable name (whose purpose is to make it clear that the word
following the symbol $ is a variable and not something else, like a function name or a constant or a keyword i.e., the
symbol $ distinguishes variables from other things) in the above program i.e., if you rewrite the above program as:
<?php
num1 =1;
num2=5;
sum = num1 + num2;
echo "Sum of the two numbers is : sum";
?>
Then
694
will be displayed on the console screen.
Program 1.3
Javascript program to subtract two numbers:
<?php
$num1 =5;
$num2=1;
$sub = $num1 - $num2;
echo "difference of the two numbers is : $sub";
?>
Program 1.4
PHP program to divide two numbers:
<?php
$num1 =6;
$num2=2;
$div = $num1 / $num2;
echo "the division of two numbers is : $div";
?>
Program 1.5
PHP program to multiply two numbers:
<?php
$num1 =6;
$num2=2;
$mult = $num1 * $num2;
echo "the product of two numbers is : $mult";
?>
Program 1.5
PHP program to find the area of a circle
695
<?php
$radius = 2.0;
$pi = 3.14159;
$area = $pi * $radius * $radius;
echo("\n radius = $radius centimeter");
echo("\n area = $area centimeter square");
?>
Output on the screen:
radius = 2 centimeter
area = 12.56636 centimeter square
Program 1.6
PHP program to find the square root of a number
<?php
$num1 = 4.0;
$num2 = sqrt($num1);
echo("The square root of a number = $num2");
?>
Program 1.7
PHP program to find the square of a number
<?php
$num1 = 2.0;
$num2 = $num1 * $num1;
echo("\n the square of a number = $num2");
?>
If the statement
$num2 = $num1 * $num1;
is replaced by
$num2 = pow(($num1), 2);
i.e., if the above program is rewritten as:
<?php
$num1 = 2.0;
$num2 = pow(($num1), 2);
696
echo("\n the square of a number = $num2");
?>
Program 1.8
PHP program to find the cube root of a number
<?php
$num1 = 6.0;
$num2 = pow(($num1), 1/3);
echo("\n the cube root of a number = $num2");
?>
Program 1.9
PHP program to round off a number
<?php
$num1 = 4.5;
$num2 = round ($num1);
echo("\n the round off of a number = $num2");
?>
Program 2.0
PHP program to find the incremented and decremented values of two numbers.
<?php
$num1 =2;
$num2=3;
$num4 = $num1 - 1;
697
$num5 = $num2 +1;
$num6 = $num2 - 1;
?>
Program 2.0
PHP program to find the greatest of two numbers using if – else statement
<?php
$x = 4.5;
$y=5;
if($x>$y){
} else {
698
?>
<?php
$x = 4.5;
$y=5;
if($x>$y){
} else {
?>
Program 2.1
PHP program to find the greatest of three numbers using if –else if – else statement
699
<?php
$x = 4.5;
$y=5;
$z=6;
else
?>
Program 2.2
PHP program to print the first ten natural numbers using for loop statement
<?php
for ($i=1; $i<=10; $i++)
echo (" \n $i");
?>
1
2
3
4
5
6
700
7
8
9
10
for ($i=1; $i<=10; $i++) denote the for loop statement for PHP and the syntax of the for loop statement is:
for (initialization; condition; increment)
Here:
$i=1 denote initialization (i.e., from where to start)
$i<=10 denote the condition (i.e., stop when the number 10 is reached)
$i++ imply increment (which tells the value of $i to increase by 1 each time the loop is executed) and $i++ is the
same as $i+1.
Since the initialization i.e., $i=1
The statement
echo (" \n $i");
make provision to print the output:
1
on the screen.
After this, the following execution takes place:
value of $i
$i= 1
Is the condition ($i<=10) is true?
Yes because $i=1
Do this
$i= 1+1 = 2
The statement
echo (" \n $i");
make provision to print the output:
2
Now, the value of $i is:
$i= 2
Is the condition ($i<=10) is true?
Yes because $i=2
Do this
$i= 2+1 = 3
The statement
echo (" \n $i");
make provision to print the output:
3
Now, the value of $i is:
$i= 3
Is the condition ($i<=10) is true?
Yes because $i=3
Do this
$i= 3+1 = 4
701
The statement
echo (" \n $i");
make provision to print the output:
4
Now, the value of $i is:
$i= 4
Is the condition ($i<=10) is true?
Yes because $i=4
Do this
$i= 4+1 = 5
The statement
echo (" \n $i");
make provision to print the output:
5
Now, the value of $ i is:
$i= 5
Is the condition ($i<=10) is true?
Yes because $i=5
Do this
$i= 5+1 = 6
The statement
echo (" \n $i");
make provision to print the output:
6
Now, the value of $i is:
$i= 6
Is the condition ($i<=10) is true?
Yes because $i=6
Do this
$i= 6+1 = 7
The statement
echo (" \n $i");
make provision to print the output:
7
Now, the value of $i is:
$i= 7
Is the condition ($i<=10) is true?
Yes because $i=7
Do this
$i= 7+1 = 8
The statement
echo (" \n $i");
make provision to print the output:
8
Now, the value of $i is:
702
$i= 8
Is the condition ($i<=10) is true?
Yes because $i=8
Do this
$i= 8+1 = 9
The statement
echo (" \n $i");
make provision to print the output:
9
Now, the value of $i is:
$i= 9
Is the condition ($i<=10) is true?
Yes because $i=9
Do this
$i= 9+1 = 10
The statement
echo (" \n $i");
make provision to print the output:
10
stop because the condition $i<=10 is achieved.
If the statement
for ($i=1; $i<=10; $i++)
is replaced by the statement
for ($i=1; $i=10; $i++)
703
10
10……………………….
Program 2.3
PHP program to print the first ten natural numbers using while loop statement
<?php
$i = 1;
while($i <= 10) {
echo "\n $i ";
$i++;
}
?>
Program 2.4
PHP program to print the first nine natural numbers using do while loop statement
do
{
execute this statement;
}
while(this is the condition);
704
<?php
$i = 1;
do {
echo "\n $i ";
$i++;
} while($i <= 9);
?>
Program 2.6
PHP program to print the average of the first10 numbers using for loop statement
<?php
$i;
$avg;
$sum = 0;
for( $i=1; $i<=10; $i++)
$sum = $sum + $i;
$avg = $sum/10;
echo "\n sum of the first 10 numbers = $sum ";
echo"\n average of the first 10 numbers = $avg ";
?>
Program 2.7
(a)
705
<?php
$ch ='3';
switch($ch)
{
case '1':
echo "Red";
break;
case '2':
echo "White";
break;
case '3':
echo "Yellow";
break;
case '4':
echo "Green";
break;
default:
echo "Error";
break;
}
?>
(b)
<?php
$ch ='birds';
switch($ch)
{
case 'animal':
echo "elephant";
break;
case 'reptiles':
echo "crocodile";
break;
case 'birds':
echo "parrot";
break;
case 'mammals':
echo "cow";
break;
default:
echo "Error";
706
break;
}
?>
Program 2.8
<?php
function addition($a, $b) {
return $a + $b;
}
$sum = addition(4, 3);
echo "the sum of two numbers = $sum ";
?>
*********************************************************************************************
Public, Private & Protected in JAVA
public class HelloWorld {
Since both the classes are public: content / information within the two classes can be shared
with each other i.e., content within the class HelloWorld can be accessed by the class Java and
content within the class Java can be accessed by the class HelloWorld.
707
public class HelloWorld {
Since one of the classes is public: content within the class HelloWorld can be accessed by the
class Java but the content within the class Java cannot be accessed by the class HelloWorld
because class Java is private.
……………………content / information……………………….
}
Here public class Java extends HelloWorld means: class Java is public but it is the subclass of
protected class HelloWorld -- so class Java can acess the content within the class HelloWorld
even though class HelloWorld is protected.
*********************************************************************************************
Fade in and out of text on button click
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<script type="text/javascript"
src="http://code.jquery.com/jquery-1.4.4.js">
</script>
708
$(function () {
$("#btn").click(function () {
$("#para").fadeToggle("slow", "linear");
});
});
</script>
</head>
<body>
<p id="para">Albert Einstein, in his theory of special relativity, determined that the laws
of physics are the same for all non-accelerating observers, and he showed that the speed of light
within a vacuum is the same no matter the speed at which an observer travels.</p>
</body>
</html>
*********************************************************************************************
Fade in and out of table on button click
<!DOCTYPE html>
<html>
<head>
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script>
$(document).ready(function(){
$(".fadeToggle").click(function(){
$(".table_bg").fadeToggle(2000);
});
709
});
</script>
<style>
.table_bg {
width:40%;
font-family:verdana;
font-size:15px;
color:#fff;
padding: 10px;
text-align:center;
.table_bg th{
background: #4A6F87;
color: #fff;
line-height:35px;
.table_bg td{
background: #C8D7E1;
padding:10px;
color: #000;
</style>
</head>
<body>
<p>
</p>
710
<table class="table_bg">
<tr>
<th>Name</th>
<th>Age</th>
<th>Salary</th>
</tr>
<tr>
<td>Jim</td>
<td>35</td>
<td>$5000.00</td>
</tr>
<tr>
<td>Anna</td>
<td>24</td>
<td>$3500.00</td>
</tr>
<tr>
<td>Adams</td>
<td>31</td>
<td>$4000.00</td>
</tr>
<tr>
<td>Adams</td>
<td>31</td>
<td>$4000.00</td>
</tr>
<tr>
<td>Adams</td>
<td>31</td>
<td>$4000.00</td>
711
</tr>
</table>
</body>
</html>
*********************************************************************************************
Display of section and subsection
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>jQuery UI Accordion - Default functionality</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.0/themes/base/jquery-ui.css">
<link rel="stylesheet" href="/resources/demos/style.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.0/jquery-ui.js"></script>
<script>
$( function() {
$( "#accordion" ).accordion();
} );
</script>
</head>
<body>
<div id="accordion">
<h3>Section 1</h3>
<div>
<p>
Mauris mauris ante, blandit et, ultrices a, suscipit eget, quam. Integer
ut neque. Vivamus nisi metus, molestie vel, gravida in, condimentum sit
amet, nunc. Nam a nibh. Donec suscipit eros. Nam mi. Proin viverra leo ut
odio. Curabitur malesuada. Vestibulum a velit eu ante scelerisque vulputate.
</p>
</div>
<h3>Section 2</h3>
<div>
<p>
Sed non urna. Donec et ante. Phasellus eu ligula. Vestibulum sit amet
purus. Vivamus hendrerit, dolor at aliquet laoreet, mauris turpis porttitor
velit, faucibus interdum tellus libero ac justo. Vivamus non quam. In
suscipit faucibus urna.
</p>
</div>
<h3>Section 3</h3>
<div>
<p>
Nam enim risus, molestie et, porta ac, aliquam ac, risus. Quisque lobortis.
Phasellus pellentesque purus in massa. Aenean in pede. Phasellus ac libero
ac tellus pellentesque semper. Sed ac felis. Sed commodo, magna quis
lacinia ornare, quam ante aliquam nisi, eu iaculis leo purus venenatis dui.
</p>
<ul>
712
<li>List item one</li>
<li>List item two</li>
<li>List item three</li>
</ul>
</div>
<h3>Section 4</h3>
<div>
<p>
Cras dictum. Pellentesque habitant morbi tristique senectus et netus
et malesuada fames ac turpis egestas. Vestibulum ante ipsum primis in
faucibus orci luctus et ultrices posuere cubilia Curae; Aenean lacinia
mauris vel est.
</p>
<p>
Suspendisse eu nisl. Nullam ut libero. Integer dignissim consequat lectus.
Class aptent taciti sociosqu ad litora torquent per conubia nostra, per
inceptos himenaeos.
</p>
</div>
</div>
</body>
</html>
*********************************************************************************************
Animated expandable bar text view
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>jQuery UI Effects - Animate demo</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.0/themes/base/jquery-ui.css">
<link rel="stylesheet" href="/resources/demos/style.css">
<style>
.toggler { width: 500px; height: 200px; position: relative; }
#button { padding: .5em 1em; text-decoration: none; }
#effect { width: 240px; height: 170px; padding: 0.4em; position: relative; background: #fff;
}
#effect h3 { margin: 0; padding: 0.4em; text-align: center; }
</style>
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.0/jquery-ui.js"></script>
<script>
$( function() {
var state = true;
$( "#button" ).on( "click", function() {
if ( state ) {
$( "#effect" ).animate({
backgroundColor: "#228B22",
color: "#fff",
width: 500
}, 1000 );
713
} else {
$( "#effect" ).animate({
backgroundColor: "#fff",
color: "#000",
width: 240
}, 1000 );
}
state = !state;
});
} );
</script>
</head>
<body>
<div class="toggler">
<div id="effect" class="ui-widget-content ui-corner-all">
<h3 class="ui-widget-header ui-corner-all">Einstein</h3>
<p>
Etiam libero neque, luctus a, eleifend nec, semper at, lorem. Sed pede. Nulla lorem metus,
adipiscing ut, luctus sed, hendrerit vitae, mi.
</p>
</div>
</div>
</body>
</html>
*********************************************************************************************
Simple Mortgage Payment Calculator
<div class="smpc-div">
<form name=mortgagecalc method=POST>
<p>How much will you be borrowing?<br>
<input type=text onkeypress="return validNumber(event)" name=loan size=10> <span class="smpc-
error" id="loanError"></span></p>
<p>What will be the term of this mortgage (in years)?<br>
<input type=text onkeypress="return validNumber(event)" name=years size=5> <span class="smpc-
error" id="yearsError"></span></p>
<p>What will be the interest rate?<br>
<input type=text onkeypress="return validNumber(event)" name=rate size=5> <span class="smpc-
error" id="rateError"></span></p>
<input type=button onClick="return myPayment()" value=Calculate> <input type=button
onClick="return myPaymentReset()" value=Reset>
</form>
<small>Instructions: Enter numbers and decimal points. No commas or other characters.</small>
<p class="smpc-monthlypayment" id="monthlyPayment"> </p>
<p class="smpc-friendlyreminder" id="friendlyReminder"> thank you </p>
</div>
<style>
/* START - Simple Mortage Payment Calculator */
.smpc-div {
background-color: #f9f9f9;
714
border:1px solid #cccccc;
padding:15px;
}
.smpc-error {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
color:#ca0000;
}
.smpc-monthlypayment {
margin-top:15px;
font-size:24px;
color:#ca0000;
}
.smpc-friendlyreminder {
display:none;
}
</style>
<script>
function validNumber(fieldinput){
var unicode=fieldinput.charCode? fieldinput.charCode : fieldinput.keyCode;
if ((unicode!=8) && (unicode!=46)) { //if the key isn't the backspace key (which we should allow)
if (unicode<48||unicode>57) //if not a number
return false; //disable key press
}
}
function myPayment()
{
// Reset error messages to blank
document.getElementById('loanError').innerHTML = '';
document.getElementById('yearsError').innerHTML = '';
document.getElementById('rateError').innerHTML = '';
715
document.getElementById('rateError').innerHTML = 'Numeric value required. Example: 5.25';
} else
{
// Set variables from form data
var loanprincipal = document.mortgagecalc.loan.value;
var months = document.mortgagecalc.years.value * 12;
var interest = document.mortgagecalc.rate.value / 1200;
function myPaymentReset()
{
// Reset everything to default/null/blank
document.getElementById('monthlyPayment').innerHTML = 'Values reset';
document.getElementById('friendlyReminder').style.display = 'none';
document.getElementById('loanError').innerHTML = '';
document.getElementById('yearsError').innerHTML = '';
document.getElementById('rateError').innerHTML = '';
document.mortgagecalc.loan.value = null;
document.mortgagecalc.years.value = null;
document.mortgagecalc.rate.value = null;
}
</script>
*********************************************************************************************
Easy Savings Calculator
<div class="esc-div">
<form name=savingscalc method=POST>
<p>What is your starting balance?<br>
<input type=text onkeypress="return onlyNumbers(event)" name=balance size=10> <span class="esc-
error" id="balanceError"></span></p>
<p>What is the interest rate?<br>
<input type=text onkeypress="return onlyNumbers(event)" name=rate size=5> <span class="esc-error"
id="rateError"></span></p>
<p>How many years?<br>
<input type=text onkeypress="return onlyNumbers(event)" name=years size=5> <span class="esc-
error" id="yearsError"></span></p>
<input type=button onClick="return mySavings()" value=Calculate> <input type=button
onClick="return mySavingsReset()" value=Reset>
</form>
<small>* Numbers and decimal points only.</small>
<p class="esc-finalbalance" id="finalBalance"> </p>
</div>
<style>
716
/* START - Easy Savings Calculator */
.esc-div {
width:450px;
background-color: #f9f9f9;
border:1px solid #cccccc;
border-radius: 7px;
padding:15px;
}
.esc-error {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
color:#ca0000;
}
.esc-finalbalance {
margin-top:15px;
font-size:24px;
color:#ca0000;
}
</style>
<script>
function onlyNumbers(keyinput){
var input=keyinput.charCode? keyinput.charCode : keyinput.keyCode
// if key press is not a backspace, a period, or a number, then stop character input
if ((input != 8) && (input != 46)) {
if ((input < 48) || (input > 57)) {
return false;
}
}
}
function mySavings()
{
// Reset error messages to blank
document.getElementById('balanceError').innerHTML = '';
document.getElementById('rateError').innerHTML = '';
document.getElementById('yearsError').innerHTML = '';
717
document.getElementById('finalBalance').innerHTML = 'Please enter the missing information.';
document.getElementById('yearsError').innerHTML = 'Numeric value required. Example: 10';
} else
{
// Set variables from form data
var startingbalance = document.savingscalc.balance.value;
var interestrate = document.savingscalc.rate.value / 100;
var totalyears = document.savingscalc.years.value;
// var totalmonths = document.savingscalc.years.value * 12;
var compoundsperyear = 12;
// A = P(1 + r%/n)^nt
// startingbalance*Math.pow((1+interestrate/compoundsperyear),(compoundsperyear*totalyears))
function mySavingsReset()
{
// Reset everything to default/null/blank
document.getElementById('finalBalance').innerHTML = 'Values reset';
document.getElementById('balanceError').innerHTML = '';
document.getElementById('rateError').innerHTML = '';
document.getElementById('yearsError').innerHTML = '';
document.savingscalc.balance.value = null;
document.savingscalc.rate.value = null;
document.savingscalc.years.value = null;
}
</script>
*********************************************************************************************
Side navigation menu
<!DOCTYPE html>
<html>
<style>
body {
font-family: "Lato", sans-serif;
}
.sidenav {
display: none;
height: 100%;
width: 250px;
position: fixed;
z-index: 1;
top: 0;
left: 0;
background-color: #000;
overflow-x: hidden;
padding-top: 60px;
718
}
.sidenav a {
padding: 8px 8px 8px 32px;
text-decoration: none;
font-size: 25px;
color: #818181;
display: block;
transition: 0.3s
}
.sidenav .closebtn {
position: absolute;
top: 0;
right: 25px;
font-size: 36px;
margin-left: 50px;
}
</div>
<h2>Sidenav Example</h2>
<p>Click on the element below to open the side navigation menu.</p>
<span style="font-size:30px;cursor:pointer" onclick="openNav()">☰ open</span>
<script>
function openNav() {
document.getElementById("mySidenav").style.display = "block";
}
function closeNav() {
document.getElementById("mySidenav").style.display = "none";
}
</script>
719
</body>
</html>
*********************************************************************************************
Full screen navigation menu
<!DOCTYPE html>
<html>
<style>
body {
font-family: "Lato", sans-serif;
}
.sidenav {
height: 100%;
width: 0;
position: fixed;
z-index: 1;
top: 0;
left: 0;
background-color: #111;
overflow-x: hidden;
transition: 0.5s;
padding-top: 60px;
text-align:center;
}
.sidenav a {
padding: 8px 8px 8px 32px;
text-decoration: none;
font-size: 25px;
color: #818181;
display: block;
transition: 0.3s
.sidenav a:hover{
color: #f1f1f1;
}
.sidenav .closebtn {
position: absolute;
top: 0;
right: 25px;
font-size: 36px;
margin-left: 50px;
}
<script>
function openNav() {
document.getElementById("mySidenav").style.width = "100%";
}
function closeNav() {
document.getElementById("mySidenav").style.width = "0";
}
</script>
</body>
</html>
*********************************************************************************************
Side push navigation menu
<!DOCTYPE html>
<html>
<style>
body {
font-family: "Lato", sans-serif;
transition: background-color .5s;
}
.sidenav {
height: 100%;
width: 0;
position: fixed;
z-index: 1;
top: 0;
left: 0;
background-color: #111;
overflow-x: hidden;
transition: 0.5s;
padding-top: 60px;
}
.sidenav a {
padding: 8px 8px 8px 32px;
text-decoration: none;
font-size: 25px;
color: #818181;
display: block;
transition: 0.3s
721
}
.sidenav .closebtn {
position: absolute;
top: 0;
right: 25px;
font-size: 36px;
margin-left: 50px;
}
#main {
transition: margin-left .5s;
padding: 16px;
}
<div id="main">
<h2>Sidenav Push Example</h2>
<p>Click on the element below to open the side navigation menu, and push this content to the
right. Notice that we add a black see-through background-color to body when the sidenav is
opened.</p>
<span style="font-size:30px;cursor:pointer" onclick="openNav()">☰ open</span>
</div>
<script>
function openNav() {
document.getElementById("mySidenav").style.width = "250px";
document.getElementById("main").style.marginLeft = "250px";
document.body.style.backgroundColor = "rgba(0,0,0,0.4)";
}
function closeNav() {
document.getElementById("mySidenav").style.width = "0";
document.getElementById("main").style.marginLeft= "0";
document.body.style.backgroundColor = "white";
}
</script>
*********************************************************************************************
722
Pop up window via TEXT link
<script type="text/javascript">
function openpopup(popurl){
var
winpops=window.open(popurl,"","width=,height=,toolbar,location,status,scrollbars,menubar,resizabl
e")
}
</script>
*********************************************************************************************
*********************************************************************************************
Video slideshow
<figure id="video_player">
<div id="video_container">
<video controls poster="http://thenewcode.com/assets/images/vid-glacier.jpg">
<source src="http://thenewcode.com/assets/videos/glacier.mp4" type="video/mp4">
<source src="http://thenewcode.com/assets/videos/glacier.webm" type="video/webm">
</video>
</div>
<figcaption>
<a href="http://thenewcode.com/assets/videos/glacier.mp4" class="currentvid">
<img src="http://thenewcode.com/assets/images/vid-glacier.jpg" alt="Athabasca Glacier">
</a>
<a href="http://thenewcode.com/assets/videos/lake.mp4">
<img src="http://thenewcode.com/assets/images/vid-lake.jpg" alt="Athabasca Lake">
</a>
<a href="http://thenewcode.com/assets/videos/mountain.mp4">
<img src="http://thenewcode.com/assets/images/vid-mountain.jpg" alt="Mountain">
</a>
</figcaption>
</figure>
<style>
</style>
<script>
(function() {
function playVid(index) {
724
video_links.children[index].classList.add("currentvid");
source[1].src = vidDir + link_list[index] + ".webm";
source[0].src = vidDir + link_list[index] + ".mp4";
currentVid = index;
video.load();
video.play();
}
video.addEventListener('mouseenter', function() {
video.setAttribute("controls","true");
})
video.addEventListener('mouseleave', function() {
video.removeAttribute("controls");
})
document.addEventListener('keydown', function(e) {
if (index) {
var focusedElement = document.activeElement;
if (e.keyCode == 40 || e.keyCode == 39) { // down or right cursor
var nextNode = focusedElement.nextElementSibling;
725
if (nextNode) { nextNode.focus(); } else { video_links.firstElementChild.focus(); }
}
if (e.keyCode == 38 || e.keyCode == 37) { // up or left cursor
var previousNode = focusedElement.previousElementSibling;
if (previousNode) { previousNode.focus(); } else { video_links.lastElementChild.focus(); }
}
}
});
})();
</script>
*********************************************************************************************
Popup video
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>jQuery YouTube Popup Player Plugin</title>
<script type="text/javascript"
src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<link type="text/css"
href="http://ajax.googleapis.com/ajax/libs/jqueryui/1/themes/redmond/jquery-
ui.css" rel="stylesheet" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1/jquery-
ui.min.js"></script>
<script type="text/javascript" src="jquery.youtubepopup.min.js"></script>
<script type="text/javascript">
$(function () {
$("a.youtube").YouTubePopup({ autoplay: 0 });
});
</script>
</head>
<body>
<a class="youtube" href="img/jpg.mp4" title="jQuery YouTube Popup Player Plugin TEST">
</a>
</body>
</html>
*********************************************************************************************
Google Map
API KEY: AIzaSyD2QT8u45jEvEI6g-W_FV2jlOeb9UDOGxo
726
<script src='https://maps.googleapis.com/maps/api/js?v=3.exp&key=AIzaSyD2QT8u45jEvEI6g-
W_FV2jlOeb9UDOGxo'></script><div style='overflow:hidden;height:400px;width:520px;'><div
id='gmap_canvas' style='height:400px;width:520px;'></div><style>#gmap_canvas img{max-
width:none!important;background:none!important}</style></div> <a href='https://www.add-
map.net/'>https://www.add-map.net</a> <script type='text/javascript'
src='https://embedmaps.com/google-maps-
authorization/script.js?id=bfb64d480ad8fcbe90c6ec2ead4d897f6bafe7a5'></script><script
type='text/javascript'>function init_map(){var myOptions = {zoom:13,center:new
google.maps.LatLng(12.9902684,77.54953950000004),mapTypeId: google.maps.MapTypeId.ROADMAP};map =
new google.maps.Map(document.getElementById('gmap_canvas'), myOptions);marker = new
google.maps.Marker({map: map,position: new
google.maps.LatLng(12.9902684,77.54953950000004)});infowindow = new
google.maps.InfoWindow({content:'<strong>Shivanagar Sweets</strong><br> 8th Main Road,
Shivanagar, Basaveshwar Nagar, Bengaluru, Karnataka<br>560010
bangalore<br>'});google.maps.event.addListener(marker, 'click',
function(){infowindow.open(map,marker);});infowindow.open(map,marker);}google.maps.event.addDomLi
stener(window, 'load', init_map);</script>
*********************************************************************************************
Inheritance
Here public class player extends game implies: class player is public and it is the sub class of
the class game. since class player is the subclass of class game-- class player automatically
takes on all the behavior and attributes of its parent class "game" i.e., methods or fields
within the class game will be automatically be included in the class player.
Note:
If public class player extends game and public class game extends ball, then we can say class
player is not only a subclass of class game but also it is a subclass of class ball.
*********************************************************************************************
Video Playlist
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Video Playlist Tutorial</title>
727
<style>
body {font-family:Arial, Helvetica, sans-serif;background:#fff}
.center {text-align:center;width:640px;margin:0 auto;}
#player {background:#000; padding:10px;width:640px;margin:0 auto;border-radius:10px;}
#player video {width:640px;}
#playlist {background:#333;list-style:none;padding:0;margin:0; width:640px;}
#playlist h1 {font: 24px Arial, Helvetica, sans-serif; color:#FFF; font-
weight:bold;padding:5px 2px;margin:0;}
#playlist a {color:#eeeedd;background:#333;padding:10px 5px;display:block;text-
decoration:none;border-bottom:1px solid #222;}
#playlist a:hover {text-decoration:none; background:#999;color:#000}
</style>
</head>
<body>
<div id="player">
<video controls="controls" width="640" height="360" preload="auto" autoplay>
<source src="http://kristibeck.com/wp/wp-content/uploads/2014/02/freeseaturtleswimming.mp4"
type="video/mp4" />
<source src="http://kristibeck.com/wp/wp-content/uploads/2014/02/freeseaturtleswimming.webm"
type="video/webm" />
<source src="http://kristibeck.com/wp/wp-content/uploads/2014/02/freeseaturtleswimming.ogv"
type="video/ogg" />
</video>
<div id="playlist">
<h1>Videos</h1>
<a href="http://kristibeck.com/wp/wp-content/uploads/2014/02/freeseaturtleswimming.mp4">Sea
Turtle</a>
<a href="http://kristibeck.com/wp/wp-content/uploads/2014/02/freedoginrain.mp4">Dog in the
Rain</a>
<a href="http://kristibeck.com/wp/wp-content/uploads/2014/02/freestormcell.mp4">Storm
Cell</a>
</div>
</div>
<div class="center">
<a href="https://www.google.com">Google</a>
</div>
<script>
//Ensure all links in the div "#player" act in the same way:
var video_playlist = document.getElementById("player");
var links = video_playlist.getElementsByTagName('a');
for (var i=0; i<links.length; i++) {
links[i].onclick = handler;
};
//Give functionality to the links:
function handler(e) {
e.preventDefault(); //Prevents default action of links going directly to the source file
videotarget = this.getAttribute("href"); //looks at the filename in the link's href attribute
filename = videotarget.substr(0, videotarget.lastIndexOf('.')) || videotarget; //Splits the
filename and takes everything before the ".", giving us jus tname without the extension
video = document.querySelector("#player video"); //Finds div #player and video
video.removeAttribute("poster"); //Removes the poster attribute in the video tag
source = document.querySelectorAll("#player video source"); //Finds source elements inside
the video tag
source[0].src = filename + ".mp4"; //defines the MP4 source
source[1].src = filename + ".webm"; //defines the WEBM source
source[2].src = filename + ".ogv"; //defines the OGG source
video.load(); //Loads video when video is selected
video.play(); //Plays video automatically
728
};
</script>
</body>
****************************************************************
Note:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Video Playlist Tutorial</title>
<style>
body {font-family:Arial, Helvetica, sans-serif;background:#fff}
.center {text-align:center;width:640px;margin:0 auto;}
#player {background:#000; padding:10px;width:640px;margin:0 auto;border-radius:10px;}
#player video {width:640px;}
#playlist {background:#333;list-style:none;padding:0;margin:0; width:640px;}
#playlist h1 {font: 24px Arial, Helvetica, sans-serif; color:#FFF; font-
weight:bold;padding:5px 2px;margin:0;}
#playlist a {color:#eeeedd;background:#333;padding:10px 5px;display:block;text-
decoration:none;border-bottom:1px solid #222;}
#playlist a:hover {text-decoration:none; background:#999;color:#000}
</style>
</head>
<body>
<div id="player">
<video controls="controls" width="640" height="360" preload="auto" autoplay>
<source src="http://kristibeck.com/wp/wp-content/uploads/2014/02/freeseaturtleswimming.mp4"
type="video/mp4" />
<source src="http://kristibeck.com/wp/wp-content/uploads/2014/02/freeseaturtleswimming.mp4"
type="video/mp4" />
<source src="http://kristibeck.com/wp/wp-content/uploads/2014/02/freeseaturtleswimming.mp4"
type="video/mp4" />
</video>
<div id="playlist">
<h1>Videos</h1>
<a href="http://kristibeck.com/wp/wp-content/uploads/2014/02/freeseaturtleswimming.mp4">Sea
Turtle</a>
<a href="http://kristibeck.com/wp/wp-content/uploads/2014/02/freedoginrain.mp4">Dog in the
Rain</a>
<a href="http://kristibeck.com/wp/wp-content/uploads/2014/02/freestormcell.mp4">Storm
Cell</a>
<a href="http://kristibeck.com/wp/wp-content/uploads/2014/02/freedoginrain.mp4">Dog in the
Rain</a>
<a href="http://kristibeck.com/wp/wp-content/uploads/2014/02/freedoginrain.mp4">Dog in the
Rain</a>
</div>
</div>
<div class="center">
<a href="https://www.google.com">Google</a>
</div>
<script>
//Ensure all links in the div "#player" act in the same way:
var video_playlist = document.getElementById("player");
729
var links = video_playlist.getElementsByTagName('a');
for (var i=0; i<links.length; i++) {
links[i].onclick = handler;
};
//Give functionality to the links:
function handler(e) {
e.preventDefault(); //Prevents default action of links going directly to the source file
videotarget = this.getAttribute("href"); //looks at the filename in the link's href attribute
filename = videotarget.substr(0, videotarget.lastIndexOf('.')) || videotarget; //Splits the
filename and takes everything before the ".", giving us jus tname without the extension
video = document.querySelector("#player video"); //Finds div #player and video
video.removeAttribute("poster"); //Removes the poster attribute in the video tag
source = document.querySelectorAll("#player video source"); //Finds source elements inside
the video tag
source[0].src = filename + ".mp4"; //defines the MP4 source
source[1].src = filename + ".mp4"; //defines the WEBM source
source[2].src = filename + ".mp4"; //defines the OGG source
video.load(); //Loads video when video is selected
video.play(); //Plays video automatically
};
</script>
</body>
****************************************************************
A simple Drawing application
<!DOCTYPE html>
<body background="images/vv1.jpeg">
<h1><h1 style="text-align:center;"><font face="comic sans ms" color="red"><i><b>MY PAINT
APPLICATION</i></b></h1>
<html lang="en">
<head>
<style type="text/css"><!--
#paint {
cursor: pointer;
}
#paint:active {
cursor: crosshair;
}
.menu{display:block;width:40px;height:40px;border-radius:25px;background:#000 }
.menu1{display:block;width:35px;height:35px;border-radius:25px;background:#000}
.menu2{display:block;width:28px;height:28px;border-radius:25px;background:#000}
form {
width: 10em;
height:29.5em;
padding: 1em;
margin: 0 auto;
text-align: center;
background-color: silver;
border: solid gray 2px;
}
.pencil {
background-color: white;
color: black;
730
}
.rectangle {
background-color: white;
color: black;
}
.violet {
background-color: violet;
color: white;
}
.indigo {
background-color: indigo;
color: white;
}
.blue {
background-color: blue;
color: white;
}
.green {
background-color: green;
color: white;
}
.yellow {
background-color: yellow;
color: white;
}
.orange {
background-color: orange;
color: white;
}
.red {
background-color: red;
color: white;
}
.white {
background-color: white;
color: black;
}
.brown {
background-color: brown;
color: white;
}
.clear {
background-color: white;
color: black;
}
731
background:white }
--></style>
</head>
<body>
<table>
<tr>
<td>
<div id="container">
<canvas id="paint" width="400" height="500" ></canvas>
</div>
</td>
<script type="text/javascript">
//------------------------------------------------------------//
var canvas, context, tool,size,pen=1 ;
var drag=false,rect={},rectan=0;
function init () {
canvas = document.getElementById('paint');
context = canvas.getContext('2d');
732
function orange(){
return color='orange';
}
function yellow(){
return color='yellow';
}
function brown(){
return color='brown';
}
//-----------------------------Pencil-----------------------//
function pencil () {
rectan=0;
pen=1;
};
this.mousemove = function (e) {
if (tool.started) {
context.lineTo(e._x, e._y);
if(pen==1&&rectan==0){
context.stroke();
}
}
};
this.mouseup = function (e) {
if (tool.started) {
tool.mousemove(e);
tool.started = false;
}
};
}
function mousepoint (e) {
if (e.layerX || e.layerX == 0) {
e._x = e.layerX;
e._y = e.layerY;
} else if (e.offsetX || e.offsetX == 0) {
e._x = e.offsetX;
e._y = e.offsetY;
}
var func = tool[e.type];
if (func) {
func(e);
}
}
init();
//------------------------end of pencil-----------------//
//-----------------Draw rectangle--------------------//
733
function draw() {
if(rectan==1){
function mouseDownrect(e) {
rect.startX = e.layerX - this.offsetLeft;
rect.startY = e.layerY - this.offsetTop;
drag = true;
function mouseUprect() {
draw();
rect.w=0;
rect.h=0;
drag = false;
}
function mouseMoverect(e) {
if(drag==true){
rect.w = (e.layerX - this.offsetLeft) - rect.startX;
rect.h = (e.layerY - this.offsetTop) - rect.startY ;
}
}
function rectangle() {
color = 'black';
rectan=1;
pen=0;
canvas.addEventListener('mousedown', mouseDownrect, false);
canvas.addEventListener('mouseup', mouseUprect, false);
canvas.addEventListener('mousemove', mouseMoverect, false);
//--------------------------------------------------------//
</script>
</body>
<td>
<form method=post>
<div>
<p><u><b>Choose Tool</b></u></p>
<button type="button" onclick="black()" class=pencil><i><b>pencil</i></b></button>
<button type="button" onclick="eraser()"class=white><i><b>eraser</i></b></button>
<button type="button" onclick="rectangle()"class=rectangle ><i><b>rectangle</i></b></button>
<p><u><b><i>Choose Color</i></b></u></p>
<button type="button" onclick="violet()"class=violet><i><b>violet</i></b></button>
<button type="button" onclick="indigo()"class=indigo><i><b>indigo</i></b></button>
<button type="button" onclick="blue()"class=blue><i><b>blue</i></b></button>
734
<button type="button" onclick="green()"class=green><i><b>green</i></b></button>
<button type="button" onclick="yellow()"class=yellow><i><b>yellow</i></b></button>
<button type="button" onclick="orange()"class=orange><i><b>orange</i></b></button>
<button type="button" onclick="red()"class=red><i><b>red</i></b></button>
<button type="button" onclick="brown()"class=brown><i><b>brown</i></b></button>
</div>
<div>
<table>
<p><u><i><b>Choose Size</i></b></u></p>
<tr>
<td>
<button type="button" onclick="size0()" class="menu"></button>
</td>
<td>
<button type="button" onclick="size1()" class="menu1"></button>
</td>
<td>
<button type="button" onclick="size2()" class="menu2"></button>
</td>
</tr>
</table>
<input type=button value="Clear" onClick="history.go()">
</div>
</form>
</td>
</tr>
</table>
</html>
****************************************************************
Find text
<head>
<script type="text/javascript">
function FindNext () {
var str = document.getElementById ("findInput").value;
if (str == "") {
alert ("Please enter some text to search!");
return;
}
735
<body>
<div>LaLa, Lala, laLa , lala, lalala, tralala, some other text</div>
<br />
<input type="text" id="findInput" value="lala" size="20" />
<button onclick="FindNext ();">Find Next</button>
</body>
****************************************************************
Find and replace text
<div id="haystack">
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut
labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris
nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate
velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</div>
<br>
<table>
<tr><td>Find</td><td><input id="needle" name="needle" type="text"></td></tr>
<tr><td>Replacment</td><td><input id="replacement" name="replacement" type="text"></td></tr>
</table>
<input type="button" value="Find" onClick="findMyText(document.getElementById('needle').value,
document.getElementById('replacement').value);">
<script>
</script>
****************************************************************
Get lon and lat from address
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta name="robots" content="noindex, nofollow">
736
<meta name="googlebot" content="noindex, nofollow">
<script type="text/javascript" src="/js/lib/dummy.js"></script>
<link rel="stylesheet" type="text/css" href="/css/result-light.css">
<script type="text/javascript"
src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>
<style type="text/css">
</style>
<script type='text/javascript'>//<![CDATA[
window.onload=function(){
/* This showResult function is used as the callback function*/
function showResult(result) {
document.getElementById('latitude').value = result.geometry.location.lat();
document.getElementById('longitude').value = result.geometry.location.lng();
}
button.addEventListener("click", function () {
var address = document.getElementById('address').value;
getLatitudeLongitude(showResult, address)
});
}//]]>
</script>
</head>
<body>
<!-- To use Geocoding from Google Maps V3 you need to link
https://maps.googleapis.com/maps/api/js?sensor=false -->
<div>
<h3> Enter an adress and press the button</h3>
737
<input id="address" type="text" placeholder="Enter address here" />
<button id="btn">Get LatLong</button>
<div>
<p>Latitude:
<input type="text" id="latitude" readonly />
</p>
<p>Longitude:
<input type="text" id="longitude" readonly />
</p>
</div>
</div>
</body>
</html>
****************************************************************
Note:
In "1 + 2" the "1" and "2" are the operands and the plus symbol is the operator.
****************************************************************
Polymorphism
In the example:
738
(concatenation means connecting two statements to produce a single statement) – which (here)
concatenates the string "the sum of a and b = " and the string “sum (which is a+b (=3 since a= 1
and b=2)” -- producing a String statement
the sum of a and b = 3 which is displayed on the screen as the result.
The ability of plus symbol to behave both as arithmetic operator and concatenation operator is
known as polymorphism.
****************************************************************
How to play music in list view in android
Java file:
MainActivity.java
import android.app.Activity;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
// variable declaration
private ListView mainList;
private MediaPlayer mp;
private final String[] listContent = { "chimes", "chord", "ding" };
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Initializing variables
mp = new MediaPlayer();
mainList = (ListView) findViewById(R.id.listView1);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, listContent);
mainList.setAdapter(adapter);
mainList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view,
int position, long id) {
playSong(position);
}
});
739
}
@Override
public void onDestroy() {
super.onDestroy();
mp.release();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
XML file:
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.audio.MainActivity" >
<ListView
android:id="@+id/listView1"
android:layout_width="match_parent"
740
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" >
</ListView>
</RelativeLayout>
raw folder
****************************************************************
Encapsulation
public String getName(){ // People can indirectly access the data (variable) via this public
method.
return name;
}
public void setName(String name){ // People can indirectly access the data (variable) via this
public method.
this.name=name;
}
}
Encapsulation is the technique of bringing the data variables and methods in single frame and
declaring data variable private (so it cannot be accessed by anyone outside the class, thereby
hiding/ encapsulating the data variable (String name) within the public class Student) and
providing indirect access to the data variable via public methods.
****************************************************************
Java file:
MainActivity.java
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.app.Activity;
741
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
XML file:
activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#458"
android:orientation="vertical" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="200dp"
android:layout_height="200dp"
/>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:text="First Image "
android:onClick="mess"/>
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
742
android:textSize="20sp"
android:text="Second Image"
android:onClick="mess"/>
</LinearLayout>
****************************************************************
Java file:
MainActivity.java
import android.app.Activity;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
meowBtn = (Button) findViewById(R.id.button1);
mPlayer = MediaPlayer.create(MainActivity.this, R.raw.chimes);
meowBtn.setOnClickListener(new View.OnClickListener() {
});
}
}
}
XML file:
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/image1" />
</LinearLayout>
****************************************************************
XML file:
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tableLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:shrinkColumns="*"
android:stretchColumns="*" >
<TableRow
android:id="@+id/tableRow1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal" >
<TextView
android:id="@+id/textView11"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_span="6"
android:gravity="center"
android:text="Weather Report"
android:textSize="18dp"
android:textStyle="bold" >
</TextView>
744
</TableRow>
<TableRow
android:id="@+id/tableRow2"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/TextView21"
android:text="" >
</TextView>
<TextView
android:id="@+id/TextView22"
android:gravity="center"
android:text="M"
android:textStyle="bold"
android:typeface="serif" >
</TextView>
<TextView
android:id="@+id/TextView23"
android:gravity="center"
android:text="T"
android:textStyle="bold"
android:typeface="serif" >
</TextView>
<TextView
android:id="@+id/TextView24"
android:gravity="center"
android:text="W"
android:textStyle="bold"
android:typeface="serif" >
</TextView>
<TextView
android:id="@+id/TextView25"
android:gravity="center"
android:text="T"
android:textStyle="bold"
android:typeface="serif" >
</TextView>
<TextView
android:id="@+id/textView26"
android:gravity="center"
android:text="F"
android:textStyle="bold"
android:typeface="serif" >
</TextView>
</TableRow>
<TableRow
android:id="@+id/tableRow3"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/textView31"
android:text="Day High"
android:textStyle="bold" >
</TextView>
<TextView
android:id="@+id/textView32"
745
android:gravity="center_horizontal"
android:text="34°C" >
</TextView>
<TextView
android:id="@+id/textView33"
android:gravity="center_horizontal"
android:text="35°C" >
</TextView>
<TextView
android:id="@+id/textView34"
android:gravity="center_horizontal"
android:text="34°C" >
</TextView>
<TextView
android:id="@+id/textView35"
android:gravity="center_horizontal"
android:text="35°C" >
</TextView>
<TextView
android:id="@+id/textView36"
android:gravity="center_horizontal"
android:text="33°C" >
</TextView>
</TableRow>
<TableRow
android:id="@+id/tableRow4"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/textView41"
android:text="Day Low"
android:textStyle="bold" >
</TextView>
<TextView
android:id="@+id/textView42"
android:gravity="center_horizontal"
android:text="28°C" >
</TextView>
<TextView
android:id="@+id/textView43"
android:gravity="center_horizontal"
android:text="27°C" >
</TextView>
<TextView
android:id="@+id/textView44"
android:gravity="center_horizontal"
android:text="29°C" >
</TextView>
<TextView
android:id="@+id/textView45"
android:gravity="center_horizontal"
android:text="26°C" >
</TextView>
<TextView
android:id="@+id/textView46"
746
android:gravity="center_horizontal"
android:text="29°C" >
</TextView>
</TableRow>
<TableRow
android:id="@+id/tableRow5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center" >
<TextView
android:id="@+id/textView8"
android:text="Conditions"
android:textStyle="bold" >
</TextView>
<ImageView
android:id="@+id/imageView1"
android:src="@drawable/monday" >
</ImageView>
<ImageView
android:id="@+id/imageView2"
android:src="@drawable/tuesday" >
</ImageView>
<ImageView
android:id="@+id/imageView3"
android:src="@drawable/wednesday" >
</ImageView>
<ImageView
android:id="@+id/imageView4"
android:src="@drawable/thursday" >
</ImageView>
<ImageView
android:id="@+id/imageView5"
android:src="@drawable/friday" >
</ImageView>
</TableRow>
</TableLayout>
****************************************************************
Java file:
MainActivity.java
747
import android.os.Bundle;
import android.app.Activity;
import android.text.TextUtils;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findViewById(R.id.ib1).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (TextUtils.isEmpty(str1)) {
e1.setError("Please enter your weight");
e1.requestFocus();
return;
}
if (TextUtils.isEmpty(str2)) {
e2.setError("Please enter your height");
e2.requestFocus();
return;
}
}
});
748
private float calculateBMI (float weight, float height) {
return "Underweight";
} else if (bmiValue < 25) {
return "Normal";
} else if (bmiValue < 30) {
return "Overweight";
} else {
return "Obese";
}
XML file:
activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/green_back"
android:fadingEdge="horizontal"
android:orientation="vertical" >
<TextView
android:id="@+id/tv1"
android:layout_width="124dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingLeft="15dp"
android:paddingTop="40dp"
android:shadowColor="@android:color/black"
android:shadowDx="4"
android:shadowDy="4"
android:text="BMI"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@android:color/white"
android:textSize="50sp"
android:typeface="serif" />
<TextView
android:id="@+id/tv2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
749
android:layout_gravity="center"
android:text="Calculator"
android:textColor="@android:color/white"
android:textSize="20dp"
android:textStyle="bold" />
<TextView
android:id="@+id/tv3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingTop="30dp"
android:text="WEIGHT (KG)"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@android:color/white"
android:textStyle="bold|italic"
android:typeface="serif" />
<EditText
android:id="@+id/et1"
android:layout_width="96dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:hint="IN KGs"
android:ems="10"
android:fadingEdgeLength="10dp"
android:inputType="numberDecimal"
android:textAlignment="center" >
<requestFocus />
</EditText>
<TextView
android:id="@+id/tv3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingTop="30dp"
android:text="HEIGHT (CM)"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@android:color/white"
android:textStyle="bold|italic"
android:typeface="serif" />
<EditText
android:id="@+id/et2"
android:layout_width="96dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:hint="IN CMs"
android:ems="10"
android:inputType="numberDecimal"
>
</EditText>
<Button
android:id="@+id/ib1"
android:layout_width="158dp"
android:layout_height="51dp"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:fadingEdge="vertical"
android:longClickable="true"
android:nextFocusRight="@color/colorPrimary"
android:text="Calculate"
android:visibility="visible" />
750
<TextView
android:id="@+id/tv4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingTop="20dp"
android:text=""
android:textSize="20dp"
android:textStyle="bold"
android:textColor="@color/colorPrimary"/>
</LinearLayout>
colors.xml
****************************************************************
p.multiple
{
border-top-style: solid;
border-left-style: dotted;
border-bottom-style: dashed;
border-right-style: double;
padding:58px;
width:458px;
}
</style>
<!DOCTYPE html>
<html>
<head>
<title>CSS Border Style</title>
<!-- Include css file here -->
<link href="css/style.css" rel="stylesheet">
751
</head>
<body>
<p class="multiple">
This is the paragraph with multiple border </p>
</body>
</html>
****************************************************************
<html>
<head>
<script type="text/javascript">
<!--
image01= new Image()
image01.src="img/image1.jpg"
image02= new Image()
image02.src="img/image2.jpg"
//-->
</script>
</head>
<center>
<body>
<a href="whatever.htm" onmouseover=
"document.images['example'].src=image02.src" onmouseout=
"document.images['example'].src=image01.src">
<img src="1.gif" name="example"></a>
</body>
<center>
</html>
****************************************************************
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>Contacts</title>
<style>
a { color: #0068D2; cursor: pointer; }
a:link, a:visited { text-decoration: none; color: #0068D2; }
a:hover, a:active { text-decoration: underline; color: #0068D2; }
body { font: 12px/18px "Lucida Grande", "Lucida Sans Unicode", sans-serif; }
752
#contacts-table, #contacts-table th, #contacts-table td { padding: 8px 16px; text-align: left;
border: 0px solid #B9BABE; }
#contacts-table th { font-weight: bold; font-size: 14px; color: #29344B; }
#contacts-table td { color: #000; }
#contacts-table tr:nth-child(2n) { background: #E8EDFF; }
<form id="contacts-form">
<div class="item text">
<label>First name:</label>
<div class="field"><input type="text" name="first_name" /></div>
</div>
<div class="item text">
<label>Last name:</label>
<div class="field"><input type="text" name="last_name" /></div>
</div>
<div class="item text">
<label>Email:</label>
<div class="field"><input type="text" name="email" /></div>
</div>
<div class="button-wrapper">
<div class="item button">
<div class="field"><input type="button" id="contacts-op-discard" value="Discard" /></div>
</div>
<div class="item button button-default">
<div class="field"><input type="submit" id="contacts-op-save" value="Save" /></div>
</div>
</div>
<input type="hidden" name="id_entry" value="0" />
</form>
753
<script>
var Contacts = {
index: window.localStorage.getItem("Contacts:index"),
$table: document.getElementById("contacts-table"),
$form: document.getElementById("contacts-form"),
$button_save: document.getElementById("contacts-op-save"),
$button_discard: document.getElementById("contacts-op-discard"),
init: function() {
// initialize storage index
if (!Contacts.index) {
window.localStorage.setItem("Contacts:index", Contacts.index = 1);
}
// initialize form
Contacts.$form.reset();
Contacts.$button_discard.addEventListener("click", function(event) {
Contacts.$form.reset();
Contacts.$form.id_entry.value = 0;
}, true);
Contacts.$form.addEventListener("submit", function(event) {
var entry = {
id: parseInt(this.id_entry.value),
first_name: this.first_name.value,
last_name: this.last_name.value,
email: this.email.value
};
if (entry.id == 0) { // add
Contacts.storeAdd(entry);
Contacts.tableAdd(entry);
}
else { // edit
Contacts.storeEdit(entry);
Contacts.tableEdit(entry);
}
this.reset();
this.id_entry.value = 0;
event.preventDefault();
}, true);
// initialize table
if (window.localStorage.length - 1) {
var contacts_list = [], i, key;
for (i = 0; i < window.localStorage.length; i++) {
key = window.localStorage.key(i);
if (/Contacts:\d+/.test(key)) {
contacts_list.push(JSON.parse(window.localStorage.getItem(key)));
}
}
if (contacts_list.length) {
contacts_list
.sort(function(a, b) {
return a.id < b.id ? -1 : (a.id > b.id ? 1 : 0);
})
.forEach(Contacts.tableAdd);
754
}
}
Contacts.$table.addEventListener("click", function(event) {
var op = event.target.getAttribute("data-op");
if (/edit|remove/.test(op)) {
var entry = JSON.parse(window.localStorage.getItem("Contacts:"+ event.target.getAttribute("data-
id")));
if (op == "edit") {
Contacts.$form.first_name.value = entry.first_name;
Contacts.$form.last_name.value = entry.last_name;
Contacts.$form.email.value = entry.email;
Contacts.$form.id_entry.value = entry.id;
}
else if (op == "remove") {
if (confirm('Are you sure you want to remove "'+ entry.first_name +' '+ entry.last_name +'" from
your contacts?')) {
Contacts.storeRemove(entry);
Contacts.tableRemove(entry);
}
}
event.preventDefault();
}
}, true);
},
storeAdd: function(entry) {
entry.id = Contacts.index;
window.localStorage.setItem("Contacts:index", ++Contacts.index);
window.localStorage.setItem("Contacts:"+ entry.id, JSON.stringify(entry));
},
storeEdit: function(entry) {
window.localStorage.setItem("Contacts:"+ entry.id, JSON.stringify(entry));
},
storeRemove: function(entry) {
window.localStorage.removeItem("Contacts:"+ entry.id);
},
tableAdd: function(entry) {
var $tr = document.createElement("tr"), $td, key;
for (key in entry) {
if (entry.hasOwnProperty(key)) {
$td = document.createElement("td");
$td.appendChild(document.createTextNode(entry[key]));
$tr.appendChild($td);
}
}
$td = document.createElement("td");
$td.innerHTML = '<a data-op="edit" data-id="'+ entry.id +'">Edit</a> | <a data-op="remove" data-
id="'+ entry.id +'">Remove</a>';
$tr.appendChild($td);
$tr.setAttribute("id", "entry-"+ entry.id);
Contacts.$table.appendChild($tr);
},
tableEdit: function(entry) {
var $tr = document.getElementById("entry-"+ entry.id), $td, key;
$tr.innerHTML = "";
for (key in entry) {
if (entry.hasOwnProperty(key)) {
755
$td = document.createElement("td");
$td.appendChild(document.createTextNode(entry[key]));
$tr.appendChild($td);
}
}
$td = document.createElement("td");
$td.innerHTML = '<a data-op="edit" data-id="'+ entry.id +'">Edit</a> | <a data-op="remove" data-
id="'+ entry.id +'">Remove</a>';
$tr.appendChild($td);
},
tableRemove: function(entry) {
Contacts.$table.removeChild(document.getElementById("entry-"+ entry.id));
}
};
Contacts.init();
</script>
</body>
</html>
****************************************************************
<style class="cp-pen-styles">
*,
*:before,
*:after {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
-webkit-box-align: center;
-webkit-align-items: center;
-ms-flex-align: center;
align-items: center;
background: -webkit-linear-gradient(315deg, #FFFFFF, #FFFFFF);
background: linear-gradient(135deg,#FFFFFF, #FFFFFF);
background-color:#FFFFFF ;
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-box-pack: center;
-webkit-justify-content: center;
-ms-flex-pack: center;
justify-content: center;
min-height: 50vh;
padding: 14px;
}
body::-webkit-scrollbar {
display: none;
}
756
a {
color: inherit;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
.card {
color: #d4cd96;
font-family: 'Fira Sans', sans-serif;
height: 100%;
left: 0;
position: absolute;
top: 0;
-webkit-transform-origin: 100% 50%;
transform-origin: 100% 50%;
-webkit-transform-style: preserve-3d;
transform-style: preserve-3d;
width: 100%;
-webkit-tap-highlight-color: transparent;
-webkit-transition: -webkit-transform 0.6s cubic-bezier(0.49, 0.23, 0.58, 0.49);
transition: -webkit-transform 0.6s cubic-bezier(0.49, 0.23, 0.58, 0.49);
transition: transform 0.6s cubic-bezier(0.49, 0.23, 0.58, 0.49);
transition: transform 0.6s cubic-bezier(0.49, 0.23, 0.58, 0.49), -webkit-transform 0.6s cubic-
bezier(0.49, 0.23, 0.58, 0.49);
}
.card.flipped {
-webkit-transform: translateX(-100%) rotateY(-180deg);
transform: translateX(-100%) rotateY(-180deg);
}
.card-front,
.card-back {
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
background: -webkit-repeating-linear-gradient(315deg, rgba(0, 0, 0, 0.3), transparent 1px,
rgba(0, 0, 0, 0.3) 2px);
background: repeating-linear-gradient(135deg, rgba(0, 0, 0, 0.3), transparent 1px, rgba(0, 0, 0,
0.3) 2px);
background-size: 3px 3px;
background-color: #302f34;
border-radius: 1px;
box-shadow: 0px -6px 8px 0px rgba(0, 0, 0, 0.1), 0px 6px 8px 0px rgba(0, 0, 0, 0.1), 6px 0px 8px
0px rgba(0, 0, 0, 0.1), -6px 0px 8px 0px rgba(0, 0, 0, 0.1);
cursor: pointer;
height: 100%;
left: 0;
padding: 5%;
position: absolute;
top: 0;
width: 100%;
}
.card-back {
-webkit-transform: rotateY(180deg);
transform: rotateY(180deg);
}
757
.card-back .layer {
background: -webkit-repeating-linear-gradient(315deg, rgba(76, 71, 31, 0.3), transparent 1px,
rgba(76, 71, 31, 0.3) 2px);
background: repeating-linear-gradient(135deg, rgba(76, 71, 31, 0.3), transparent 1px, rgba(76,
71, 31, 0.3) 2px);
background-size: 3px 3px;
background-color: #d4cd96;
color: #302f34;
height: 100%;
position: relative;
width: 100%;
}
.card-back .layer:after {
background: -webkit-linear-gradient(315deg, rgba(0, 0, 0, 0.2), transparent);
background: linear-gradient(135deg, rgba(0, 0, 0, 0.2), transparent);
content: '';
display: block;
height: 100%;
left: 0;
position: absolute;
top: 0;
width: 100%;
}
.card-back .layer .top,
.card-back .layer .bottom {
left: 8%;
position: absolute;
z-index: 1;
}
.card-back .layer .top {
top: 12%;
}
.card-back .layer .bottom {
bottom: 12%;
}
.card-back .layer h2, .card-back .layer h3, .card-back .layer h4 {
font-weight: 400;
margin: 2px 0;
}
.card-back .layer h2 {
font-size: 18px;
font-weight: 500;
text-transform: uppercase;
}
.card-back .layer h3 {
font-size: 16px;
}
.card-back .layer h4 {
font-size: 16px;
font-style: italic;
}
.card-front .layer {
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
758
display: flex;
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
-webkit-flex-direction: column;
-ms-flex-direction: column;
flex-direction: column;
height: 100%;
-webkit-box-pack: center;
-webkit-justify-content: center;
-ms-flex-pack: center;
justify-content: center;
position: relative;
width: 100%;
}
.card-front .layer h1 {
font-size: 32px;
font-weight: 400;
letter-spacing: -2px;
margin: 0 auto;
padding: 6px 18px 4px;
text-align: center;
}
.card-front .layer .corner {
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
border-right: 2px solid #d4cd96;
border-top: 2px solid #d4cd96;
height: 12px;
position: absolute;
width: 12px;
}
.card-front .layer .corner:nth-of-type(1) {
right: 0;
top: 0;
}
.card-front .layer .corner:nth-of-type(2) {
left: 0;
top: 0;
-webkit-transform: rotateZ(-90deg);
transform: rotateZ(-90deg);
}
.card-front .layer .corner:nth-of-type(3) {
bottom: 0;
left: 0;
-webkit-transform: rotateZ(180deg);
transform: rotateZ(180deg);
}
.card-front .layer .corner:nth-of-type(4) {
bottom: 0;
right: 0;
-webkit-transform: rotateZ(90deg);
transform: rotateZ(90deg);
}
.card-wrapper {
height: 271.76471px;
max-width: 420px;
-webkit-perspective: 600px;
759
perspective: 600px;
position: relative;
width: 100%;
-webkit-transition: -webkit-transform 1s;
transition: -webkit-transform 1s;
transition: transform 1s;
transition: transform 1s, -webkit-transform 1s;
}
</style></head><body>
<div class='card-wrapper'>
<div class='card' data-toggle-class='flipped'>
<div class='card-front'>
<div class='layer'>
<h1>Lobos</h1>
<div class='corner'></div>
<div class='corner'></div>
<div class='corner'></div>
<div class='corner'></div>
</div>
</div>
<div class='card-back'>
<div class='layer'>
<div class='top'>
<h2>Web Consultant</h2>
<h4>Your dreams. Realised.</h4>
</div>
<div class='bottom'>
<h3>
Phone:
<a href='tel:+44 7542 20 33 83'>+44 7542 20 33 83</a>
</h3>
<h3>
Email:
<a href='mailto:[email protected]'>[email protected]</a>
</h3>
<h3>
Twitter:
<a href='https://www.twitter.com/lmenus' target='_blank'>lemen</a>
</h3>
<h3>
Web:
<a href='http://www.lmen.us' target='_blank'>lmen.us</a>
</h3>
</div>
</div>
</div>
</div>
</div>
<script>;(function () {
let card = document.getElementsByClassName('card')[0],
moved = 0,
interval;
if (!card) return;
760
card.style.transform = '';
interval = setInterval(function () {
moved = moved ? 0 : 10;
card.style.transform = 'translateY(' + moved + 'px)';
}, 1500);
})();
</script>
****************************************************************
<style class="cp-pen-styles">
body {
background: #808080;
}
body h1 {
position: fixed;
top: 40px;
left: 40px;
z-index: 6;
font-size: 20px;
font-weight: 900;
font-family: sans-serif;
text-transform: uppercase;
}
body h1 > span {
text-transform: none;
opacity: .5;
font-weight: 300;
font-size: 12px;
}
body input + label {
position: fixed;
top: 40px;
right: 40px;
height: 20px;
width: 15px;
z-index: 5;
}
body input + label span {
position: absolute;
761
width: 100%;
height: 2px;
top: 50%;
margin-top: -1px;
left: 0;
display: block;
background: #020304;
transition: .5s;
}
body input + label span:first-child {
top: 3px;
}
body input + label span:last-child {
top: 16px;
}
body label:hover {
cursor: pointer;
}
body input:checked + label span {
opacity: 0;
top: 50%;
}
body input:checked + label span:first-child {
opacity: 1;
transform: rotate(405deg);
}
body input:checked + label span:last-child {
opacity: 1;
transform: rotate(-405deg);
}
body input ~ nav {
background: white;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100px;
z-index: 3;
transition: .5s;
transition-delay: .5s;
overflow: hidden;
}
body input ~ nav > ul {
text-align: center;
position: absolute;
top: 35%;
left: 20%;
right: 20%;
}
body input ~ nav > ul > li {
opacity: 0;
transition: .5s;
transition-delay: 0s;
}
body input ~ nav > ul > li > a {
text-decoration: none;
text-transform: uppercase;
color: #020304;
762
font-weight: 700;
font-family: sans-serif;
display: block;
padding: 30px;
}
body input:checked ~ nav {
height: 100%;
transition-delay: 0s;
}
body input:checked ~ nav > ul > li {
opacity: 1;
transition-delay: .5s;
}
</style></head><body>
<h1>Burger Menu <span>by JLNLJN</span></h1>
<label for="burger">
<span></span>
<span></span>
<span></span>
</label>
<nav>
<ul>
<li><a href="#">Link #1</a></li>
<li><a href="#">Link #2</a></li>
<li><a href="#">Link #3</a></li>
</ul>
</nav>
****************************************************************
Breadcrumbs
<style class="cp-pen-styles">
body{
margin:0;
color:#444;
background:#cecece;
font:300 18px/18px Roboto, sans-serif;
}
*,:after,:before{box-sizing:border-box}
.pull-left{float:left}
.pull-right{float:right}
.clearfix:after,.clearfix:before{content:'';display:table}
.clearfix:after{clear:both;display:block}
.wrap{
width:100%;
overflow:hidden;
max-width:650px;
border-radius:4px;
margin:30px auto 0;
box-shadow:0 4px 6px #000;
763
}
.wrap .tab{opacity:0;position:absolute}
.content{
overflow:hidden;
min-height:330px;
position:relative;
background-color:#fff;
}
.content .htm{
top:0;
left:0;
right:0;
bottom:0;
opacity:0;
width:100%;
height:100%;
padding:30px;
overflow-y:auto;
visibility:hidden;
position:absolute;
-webkit-transform:translateX(50%) skew(-50deg);
transform:translateX(50%) skew(-50deg);
-webkit-transition:all .6s ease-in-out 0s;
transition:all .6s ease-in-out 0s;
}
.content .htm h1{
margin-top:0;
font-size:42px;
line-height:42px;
font-weight:normal;
font-family:'Denk One','Roboto','Open Sans',sans-serif;
}
.content .htm p{
line-height:24px;
}
.content .htm .list{
counter-reset:credits;
}
.content .htm .list .item{
position:relative;
padding-left:30px;
margin-bottom:10px;
}
.content .htm .list .item:before{
left:0;
top:50%;
color:#fff;
width:20px;
height:20px;
font-size:14px;
margin-top:-10px;
line-height:20px;
border-radius:50%;
text-align:center;
position:absolute;
background:#5C6BC0;
content:counter(credits);
counter-increment:credits;
764
}
.content .htm .list .item a{
font-size:18px;
font-weight:500;
color:currentColor;
text-decoration:none;
}
.content .htm .text{margin-top:20px;font-style:italic}
.content .grd>.col{
float:left;
width:33.3333%;
}
.content .work-item{
margin:15px;
padding:10px;
min-height:70px;
overflow:hidden;
position:relative;
box-shadow:0 2px 10px 0 rgba(0,0,0,.16),0 2px 5px 0 rgba(0,0,0,.26);
}
.content .work-item a{
top:0;
left:0;
right:0;
bottom:0;
width:100%;
height:100%;
position:absolute;
color:currentColor;
}
.content .work-item a:before{
top:15px;
z-index:1;
left:-20px;
color:#fff;
padding:0 4px;
min-width:88px;
font-size:12px;
position:absolute;
white-space:nowrap;
text-align:center;
content:attr(data-type);
background-color:#BA68C8;
-webkit-transition:all .4s ease-in-out 0s;
transition:all .4s ease-in-out 0s;
-webkit-transform:rotate(-45deg) rotateX(90deg);
transform:rotate(-45deg) rotateX(90deg);
}
.content .work-item .more{
top:50%;
left:50%;
color:#fff;
width:30px;
height:30px;
margin-top:-20px;
margin-left:-15px;
line-height:30px;
position:absolute;
765
border-radius:50%;
text-align:center;
background-color:#3F51B5;
-webkit-transition:all .4s ease-in-out 0s;
transition:all .4s ease-in-out 0s;
}
.content .work-item .title{
left:0;
right:0;
bottom:0;
width:100%;
padding:5px;
font-size:13px;
position:absolute;
text-align:center;
-webkit-transition:all .4s ease-in-out 0s;
transition:all .4s ease-in-out 0s;
}
.content .work-item:hover a:before{
-webkit-transform:rotate(-45deg);
transform:rotate(-45deg);
}
.content .work-item:hover .title{
color:#fff;
font-size:10px;
text-transform:uppercase;
-webkit-transform:translateY(-20px);
transform:translateY(-20px);
}
.content .work-item:hover .more{
color:transparent;
-webkit-transform:scale(7);
transform:scale(7);
}
.nav{
color:rgba(255,255,255,.75);
text-align:center;
background-color:#6c17ff;
}
.links{
position:relative;
vertical-align:middle;
display:inline-block;
}
.links:before{
left:0;
top:-4px;
height:4px;
content:'';
width:100px;
position:absolute;
background-color:#6c17ff;
-webkit-transition:all .4s ease-in-out 0s;
transition:all .4s ease-in-out 0s;
}
.links label{
float:left;
766
cursor:pointer;
font-size:22px;
min-width:100px;
font-weight:700;
text-align:center;
padding:20px 10px;
color:currentColor;
text-decoration:none;
overflow:hidden;
max-width:100px;
white-space:nowrap;
display:inline-block;
text-overflow:ellipsis;
-webkit-transition:color .4s ease-in-out 0s;
transition:color .4s ease-in-out 0s;
}
.wrap .tab:nth-child(2):checked ~ .nav .links:before{left:100px}
.wrap .tab:nth-child(3):checked ~ .nav .links:before{left:200px}
.wrap .tab:nth-child(4):checked ~ .nav .links:before{left:300px}
767
<p>This design is based on dribbble shot that was create by <a
href="https://dribbble.com/hansjan_nl">Hansjan Kamerling</a>. You can find stuff information
inside credits tab.</p>
</div>
<div class="htm">
<h1>about</h1>
<p>Hi, It's me Mohan from <b>Nepal</b>. I'm a web and graphics designer. Designing is my passion
and I am still learning and developing my skills on graphics designing and coding. I have been
working on various designing projects.</p>
</div>
<div class="htm">
<h1>work</h1>
<div class="grd clearfix">
<div class="col">
<div class="work-item">
<a href="https://codecanyon.net/user/khadkamhn/portfolio" target="_blank" data-type="code">
<span class="more">+</span>
<span class="title">Envato</span>
</a>
</div>
</div>
<div class="col">
<div class="work-item">
<a href="https://codepen.io/khadkamhn/" target="_blank" data-type="profile">
<span class="more">+</span>
<span class="title">Codepen</span>
</a>
</div>
</div>
<div class="col">
<div class="work-item">
<a href="http://codepen.io/khadkamhn/full/BNwxEa/" target="_blank" data-type="codepen">
<span class="more">+</span>
<span class="title">Secret UI</span>
</a>
</div>
</div>
<div class="col">
<div class="work-item">
<a href="http://codepen.io/khadkamhn/full/KrJBGP/" target="_blank" data-type="codepen">
<span class="more">+</span>
<span class="title">Bee</span>
</a>
</div>
</div>
<div class="col">
<div class="work-item">
<a href="http://codepen.io/khadkamhn/full/EVaJLy" target="_blank" data-type="codepen">
<span class="more">+</span>
<span class="title">Lock Screen</span>
</a>
</div>
</div>
<div class="col">
<div class="work-item">
<a href="http://codepen.io/khadkamhn/full/oXORGZ" target="_blank" data-type="codepen">
<span class="more">+</span>
<span class="title">Accordion Profile</span>
768
</a>
</div>
</div>
</div>
</div>
<div class="htm">
<h1>credits</h1>
<p>I have been using the following assets to build this design.</p>
<div class="list">
<div class="item"><a href="https://fonts.google.com/specimen/Roboto" target="_blank">roboto</a>
font <span>for typography</span></div>
<div class="item"><a href="https://dribbble.com/shots/2474526-Day-55-Breadcrumbs"
target="_blank">concept of design</a> <span>for layout</span></div>
<div class="item"><a href="https://fonts.google.com/specimen/Denk+One" target="_blank">denk
one</a> font <span>for heading</span></div>
</div>
<div class="text">I'm glad for using these resources and expecting same as time ahead</div>
</div>
</div>
<div class="nav">
<div class="links">
<label for="tab-1">home</label>
<label for="tab-2">about</label>
<label for="tab-3">work</label>
<label for="tab-4">credits</label>
</div>
</div>
</div>
****************************************************************
Ball Game
<style class="cp-pen-styles">
body {
background: cornflowerblue;
margin: 0;
overflow-y: overlay;
font-family: Helvetica, sans-serif;
}
.bg {
width: 300vw;
height: 1px;
}
.ball {
position: fixed;
top: 100px;
left: 20vw;
width: 25px;
height: 25px;
border: 2px solid black;
border-radius: 50%;
background: white;
769
}
::-webkit-scrollbar {
width: 40px;
height: 40px;
}
/* Track */
::-webkit-scrollbar-track {
background: cornflowerblue;
}
/* Thumb */
::-webkit-scrollbar-thumb {
border-radius: 18px;
border: 2px solid black;
background: crimson;
}
.blocks {
position: fixed;
width: 80vw;
left: calc(50% - 40vw);
top: 100px;
display: flex;
flex-wrap: wrap;
justify-content: center;
}
.block {
background: turquoise;
width: 10%;
height: 25px;
margin: 3px;
border: 2px solid black;
animation: go-down 1s cubic-bezier(0.25, 0.1, 0.15, 1) forwards;
}
.block:nth-child(1) {
transform: translateY(-215vh);
}
.block:nth-child(2) {
transform: translateY(-324vh);
}
.block:nth-child(3) {
transform: translateY(-300vh);
}
.block:nth-child(4) {
transform: translateY(-347vh);
}
.block:nth-child(5) {
transform: translateY(-312vh);
}
770
.block:nth-child(6) {
transform: translateY(-287vh);
}
.block:nth-child(7) {
transform: translateY(-242vh);
}
.block:nth-child(8) {
transform: translateY(-223vh);
}
.block:nth-child(9) {
transform: translateY(-166vh);
}
.block:nth-child(10) {
transform: translateY(-130vh);
}
.block:nth-child(11) {
transform: translateY(-323vh);
}
.block:nth-child(12) {
transform: translateY(-241vh);
}
.block:nth-child(13) {
transform: translateY(-51vh);
}
.block:nth-child(14) {
transform: translateY(-53vh);
}
.block:nth-child(15) {
transform: translateY(-54vh);
}
.block:nth-child(16) {
transform: translateY(-132vh);
}
.block:nth-child(17) {
transform: translateY(-188vh);
}
.block:nth-child(18) {
transform: translateY(-95vh);
}
.block:nth-child(19) {
transform: translateY(-208vh);
}
.block:nth-child(20) {
transform: translateY(-191vh);
771
}
.block:nth-child(21) {
transform: translateY(-79vh);
}
.block:nth-child(22) {
transform: translateY(-173vh);
}
.block:nth-child(23) {
transform: translateY(-311vh);
}
.block:nth-child(24) {
transform: translateY(-272vh);
}
.block:nth-child(25) {
transform: translateY(-193vh);
}
.block:nth-child(26) {
transform: translateY(-177vh);
}
.block:nth-child(27) {
transform: translateY(-253vh);
}
.block:nth-child(28) {
transform: translateY(-184vh);
}
.block:nth-child(29) {
transform: translateY(-310vh);
}
.block:nth-child(30) {
transform: translateY(-84vh);
}
.block:nth-child(31) {
transform: translateY(-270vh);
}
.block:nth-child(32) {
transform: translateY(-317vh);
}
.block:nth-child(33) {
transform: translateY(-137vh);
}
.block:nth-child(34) {
transform: translateY(-344vh);
}
772
.block:nth-child(35) {
transform: translateY(-245vh);
}
.block:nth-child(36) {
transform: translateY(-302vh);
}
@keyframes go-down {
to {
transform: translateY(0);
}
}
a {
color: rgba(255, 255, 255, 0.5);
}
.msg {
color: rgba(255, 255, 255, 0.3);
position: fixed;
left: 0;
right: 0;
text-align: center;
font-size: 40px;
}
#msg1 {
bottom: 50px;
}
#msg2 {
bottom: auto;
top: 10px;
}
</style></head><body>
<div class="bg"></div>
<div id="blocks" class="blocks">
<div class="block"></div>
<div class="block"></div>
<div class="block"></div>
<div class="block"></div>
<div class="block"></div>
<div class="block"></div>
<div class="block"></div>
<div class="block"></div>
<div class="block"></div>
<div class="block"></div>
<div class="block"></div>
<div class="block"></div>
<div class="block"></div>
<div class="block"></div>
<div class="block"></div>
<div class="block"></div>
<div class="block"></div>
<div class="block"></div>
<div class="block"></div>
<div class="block"></div>
773
<div class="block"></div>
<div class="block"></div>
<div class="block"></div>
<div class="block"></div>
<div class="block"></div>
<div class="block"></div>
<div class="block"></div>
<div class="block"></div>
<div class="block"></div>
<div class="block"></div>
<div class="block"></div>
<div class="block"></div>
<div class="block"></div>
<div class="block"></div>
<div class="block"></div>
</div>
<div id="ball" class="ball"></div>
<script>
function myFunction() {
location.reload();
}
</script>
function isTouchingPaddle() {
scrollLeft = window.scrollX / xScale;
scaledPosX = pos.x * xScale;
return !(pos.x + ballWidth/2 < scrollLeft || pos.x + ballWidth/2 > scrollLeft +
scrollbarWidth);
}
function checkCollision() {
var block;
if (!blocks.children[0].x) return;
for (var i = blocks.children.length; i--;) {
block = blocks.children[i];
if (!(pos.x > block.x + block.width ||
pos.x + ballWidth < block.x ||
pos.y > block.y + block.height ||
pos.y + ballHeight < block.y)) {
block.remove();
774
v.y = 6;
updateBlockProps();
return;
}
}
}
// Store each block's properties on itself
function updateBlockProps() {
var bounds, block;
for (var i = blocks.children.length; i--;) {
block = blocks.children[i];
bounds = block.getBoundingClientRect();
block.x = bounds.left;
block.y = bounds.top;
block.width = bounds.width;
block.height = bounds.height;
}
}
function reset() {
window.scrollTo((W - scrollbarWidth) * xScale / 2, 0);
v.x = 0; v.y = 0;
pos.x = W/2;
pos.y = H - scrollbarThickness - ballHeight - 4;
setTimeout(function () {
v.x = 10; v.y = -6;
}, 1000);
}
function random(a, b) {
return a + ~~(Math.random() * (b - a));
}
function update() {
pos.x += v.x;
pos.y += v.y;
if ((pos.x + ballWidth) > (W-scrollbarThickness) || pos.x < 0) {
v.x *= -1;
}
if ((pos.y + ballHeight) > (H-scrollbarThickness) || pos.y < 0) {
if (pos.y < H/2 || isTouchingPaddle()) {
v.y *= -1;
} else {
reset();
}
}
checkCollision();
ball.style.left = pos.x + 'px';
ball.style.top = pos.y + 'px';
}
function loop() {
update();
requestAnimationFrame(loop);
}
reset();
loop();
setTimeout(updateBlockProps, 1000);
</script>
775
****************************************************************
h1 {
margin: 0;
padding: 0;
}
p {
margin: 0;
padding: 0 0 25px 0;
}
.title {
776
color: #fff;
text-align: center;
font-size: 40px;
font-weight: 600;
}
section {
width: 600px;
max-width: 100%;
padding: 225px 20px 20px 20px;
margin: 0 auto;
display: block;
line-height: 150%;
}
</style></head><body>
<div id='app'>
</div>
<script src='//assets.codepen.io/assets/common/stopExecutionOnTimeout-
53beeb1a007ec32040abaf4c9385ebfc.js'></script><script
src='https://npmcdn.com/[email protected]/dist/react.min.js'></script><script
src='https://npmcdn.com/[email protected]/dist/react-dom.min.js'></script>
<script>'use strict';
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !==
null) { throw new TypeError("Super expression must either be null or a function, not " + typeof
superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if
(superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) :
subClass.__proto__ = superClass; }
function HeroHeader() {
_classCallCheck(this, HeroHeader);
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
777
window.addEventListener('scroll', this.onScroll);
};
return React.createElement(
'header',
{
className: 'heroHeader',
ref: function ref(n) {
return _this2._containerDOM = n;
},
style: { height: this.state.height } },
React.createElement(
'div',
{ className: 'heroHeader-content' },
this.props.children
)
);
};
return HeroHeader;
}(React.Component);
HeroHeader.propTypes = {
scrollAction: React.PropTypes.string
};
HeroHeader.defaultProps = {
scrollAction: 250
};
function DummyContent() {
return React.createElement(
'section',
null,
React.createElement(
'p',
null,
'In 1905, Albert Einstein determined that the laws of physics are the same for all non-
accelerating observers, and that the speed of light in a vacuum was independent of the motion of
all observers. This was the theory of special relativity. It introduced a new framework for all
of physics and proposed new concepts of space and time.'
),
React.createElement(
'p',
778
null,
'Einstein then spent ten years trying to include acceleration in the theory and published
his theory of general relativity in 1915. In it, he determined that massive objects cause a
distortion in space-time, which is felt as gravity.'
),
React.createElement(
'p',
null,
'Two objects exert a force of attraction on one another known as "gravity." Sir Isaac
Newton quantified the gravity between two objects when he formulated his three laws of motion.
The force tugging between two bodies depends on how massive each one is and how far apart the two
lie. Even as the center of the Earth is pulling you toward it (keeping you firmly lodged on the
ground), your center of mass is pulling back at the Earth. But the more massive body barely feels
the tug from you, while with your much smaller mass you find yourself firmly rooted thanks to
that same force. Yet Newtons laws assume that gravity is an innate force of an object that can
act over a distance.'
),
React.createElement(
'p',
null,
'Albert Einstein, in his theory of special relativity, determined that the laws of physics
are the same for all non-accelerating observers, and he showed that the speed of light within a
vacuum is the same no matter the speed at which an observer travels. As a result, he found that
space and time were interwoven into a single continuum known as space-time. Events that occur at
the same time for one observer could occur at different times for another.'
),
React.createElement(
'p',
null,
'As he worked out the equations for his general theory of relativity, Einstein realized
that massive objects caused a distortion in space-time. Imagine setting a large body in the
center of a trampoline. The body would press down into the fabric, causing it to dimple. A marble
rolled around the edge would spiral inward toward the body, pulled in much the same way that the
gravity of a planet pulls at rocks in space.'
),
React.createElement(
'p',
null,
'Although instruments can neither see nor measure space-time, several of the phenomena
predicted by its warping have been confirmed.'
),
React.createElement(
'p',
null,
'Gravitational lensing: Light around a massive object, such as a black hole, is bent,
causing it to act as a lens for the things that lie behind it. Astronomers routinely use this
method to study stars and galaxies behind massive objects.'
),
React.createElement(
'p',
null,
'Einsteins Cross, a quasar in the Pegasus constellation, is an excellent example of
gravitational lensing. The quasar is about 8 billion light-years from Earth, and sits behind a
galaxy that is 400 million light-years away. Four images of the quasar appear around the galaxy
because the intense gravity of the galaxy bends the light coming from the quasar.'
),
React.createElement(
'p',
779
null,
'Gravitational lensing can allow scientists to see some pretty cool things, but until
recently, what they spotted around the lens has remained fairly static. However, since the light
traveling around the lens takes a different path, each traveling over a different amount of time,
scientists were able to observe a supernova occur four different times as it was magnified by a
massive galaxy.'
),
React.createElement(
'p',
null,
'In another interesting observation, NASAs Kepler telescope spotted a dead star, known as a
white dwarf, orbiting a red dwarf in a binary system. Although the white dwarf is more massive,
it has a far smaller radius than its companion.'
),
React.createElement(
'p',
null,
'The technique is equivalent to spotting a flea on a light bulb 3,000 miles away, roughly
the distance from Los Angeles to New York City," Avi Shporer of the California Institute of
Technology said in a statement.'
)
);
}
function App() {
return React.createElement(
'div',
null,
React.createElement(
HeroHeader,
null,
React.createElement(
'h1',
{ className: 'title' },
'Einsteins Theory of General Relativity'
)
),
React.createElement(DummyContent, null)
);
}
</script>
****************************************************************
JS Typing Effect
<style class="cp-pen-styles">
@import url(https://fonts.googleapis.com/css?family=Prompt:900);
html {
font-family: 'Prompt', sans-serif;
background-color: #000;
color: #fff;
780
font-size: 5vw;
}
container {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-box-align: center;
-webkit-align-items: center;
-ms-flex-align: center;
align-items: center;
-webkit-box-pack: center;
-webkit-justify-content: center;
-ms-flex-pack: center;
justify-content: center;
height: 100vh;
}
#app {
letter-spacing: 0.25em;
text-transform: uppercase;
}
</style></head><body>
<container>
<div id="app"></div>
</container>
<script>const items = [
'Albert Einstein',
'is a',
'Great',
'Scientist',
'of all time'
];
const app = document.getElementById('app');
let count = 0;
let index = 0;
let typingEffect = () => {
let text = items[index];
if (count < text.length) {
setTimeout(() => {
app.innerHTML += text[count];
count++;
typingEffect();
}, Math.floor(Math.random(10) * 100));
} else {
count = 0;
index = index + 1 < items.length ? index + 1 : 0;
setTimeout(() => {
app.innerHTML = '';
typingEffect();
}, 1500);
}
};
typingEffect();
</script>
781
****************************************************************
<style class="cp-pen-styles">
@import url(https://fonts.googleapis.com/css?family=Open+Sans:300,400,700);
* {
box-sizing: border-box;
}
body {
background-image: -webkit-linear-gradient(left, #034378, #2d4e68);
background-image: linear-gradient(to right, #034378, #2d4e68);
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
height: 100vh;
font-family: "Open Sans", sans-serif;
}
a {
text-decoration: none;
}
h1 {
font-family: "Open Sans", sans-serif;
font-weight: 300;
}
.row {
max-width: 900px;
margin: 50px auto 0;
}
.card {
float: left;
padding: 0 1.7rem;
width: 50%;
}
.card .menu-content {
margin: 0;
padding: 0;
list-style-type: none;
}
.card .menu-content::before, .card .menu-content::after {
content: '';
display: table;
}
.card .menu-content::after {
clear: both;
}
.card .menu-content li {
display: inline-block;
}
.card .menu-content a {
782
color: #fff;
}
.card .menu-content span {
position: absolute;
left: 50%;
top: 0;
font-size: 10px;
font-weight: 700;
font-family: 'Open Sans';
-webkit-transform: translate(-50%, 0);
transform: translate(-50%, 0);
}
.card .wrapper {
background-color: #fff;
min-height: 540px;
position: relative;
overflow: hidden;
box-shadow: 0 19px 38px rgba(0, 0, 0, 0.3), 0 15px 12px rgba(0, 0, 0, 0.2);
}
.card .wrapper:hover .data {
-webkit-transform: translateY(0);
transform: translateY(0);
}
.card .data {
position: absolute;
bottom: 0;
width: 100%;
-webkit-transform: translateY(calc(70px + 1em));
transform: translateY(calc(70px + 1em));
-webkit-transition: -webkit-transform 0.3s;
transition: -webkit-transform 0.3s;
transition: transform 0.3s;
transition: transform 0.3s, -webkit-transform 0.3s;
}
.card .data .content {
padding: 1em;
position: relative;
z-index: 1;
}
.card .author {
font-size: 12px;
}
.card .title {
margin-top: 10px;
}
.card .text {
height: 70px;
margin: 0;
}
.card input[type='checkbox'] {
display: none;
}
.card input[type='checkbox']:checked + .menu-content {
-webkit-transform: translateY(-60px);
transform: translateY(-60px);
}
.example-1 .wrapper {
783
background: url(https://hd.unsplash.com/photo-1463415268136-e52a5af54519) center/cover no-repeat;
}
.example-1 .date {
position: absolute;
top: 0;
left: 0;
background-color: #77d7b9;
color: #fff;
padding: 0.8em;
}
.example-1 .date span {
display: block;
text-align: center;
}
.example-1 .date .day {
font-weight: 700;
font-size: 24px;
text-shadow: 2px 3px 2px rgba(0, 0, 0, 0.18);
}
.example-1 .date .month {
text-transform: uppercase;
}
.example-1 .date .month,
.example-1 .date .year {
font-size: 12px;
}
.example-1 .content {
background-color: #fff;
box-shadow: 0 5px 30px 10px rgba(0, 0, 0, 0.3);
}
.example-1 .title a {
color: gray;
}
.example-1 .menu-button {
position: absolute;
z-index: 999;
top: 16px;
right: 16px;
width: 25px;
text-align: center;
cursor: pointer;
}
.example-1 .menu-button span {
width: 5px;
height: 5px;
background-color: gray;
color: gray;
position: relative;
display: inline-block;
border-radius: 50%;
}
.example-1 .menu-button span::after, .example-1 .menu-button span::before {
content: '';
display: block;
width: 5px;
height: 5px;
background-color: currentColor;
position: absolute;
784
border-radius: 50%;
}
.example-1 .menu-button span::before {
left: -10px;
}
.example-1 .menu-button span::after {
right: -10px;
}
.example-1 .menu-content {
text-align: center;
position: absolute;
top: 0;
left: 0;
width: 100%;
z-index: -1;
-webkit-transition: -webkit-transform 0.3s;
transition: -webkit-transform 0.3s;
transition: transform 0.3s;
transition: transform 0.3s, -webkit-transform 0.3s;
-webkit-transform: translateY(0);
transform: translateY(0);
}
.example-1 .menu-content li {
width: 33.333333%;
float: left;
background-color: #77d7b9;
height: 60px;
position: relative;
}
.example-1 .menu-content a {
position: absolute;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
font-size: 24px;
}
.example-1 .menu-content span {
top: -10px;
}
.example-2 .wrapper {
background: url(https://hd.unsplash.com/photo-1463415268136-e52a5af54519) center/cover no-repeat;
}
.example-2 .wrapper:hover .menu-content span {
-webkit-transform: translate(-50%, -10px);
transform: translate(-50%, -10px);
opacity: 1;
}
.example-2 .header {
color: #fff;
padding: 1em;
}
.example-2 .header::before, .example-2 .header::after {
content: '';
display: table;
}
.example-2 .header::after {
785
clear: both;
}
.example-2 .header .date {
float: left;
font-size: 12px;
}
.example-2 .menu-content {
float: right;
}
.example-2 .menu-content li {
margin: 0 5px;
position: relative;
}
.example-2 .menu-content span {
-webkit-transition: all 0.3s;
transition: all 0.3s;
opacity: 0;
}
.example-2 .data {
color: #fff;
-webkit-transform: translateY(calc(70px + 4em));
transform: translateY(calc(70px + 4em));
}
.example-2 .title a {
color: #fff;
}
.example-2 .button {
display: block;
width: 100px;
margin: 2em auto 1em;
text-align: center;
font-size: 12px;
color: #fff;
line-height: 1;
position: relative;
font-weight: 700;
}
.example-2 .button::after {
content: '\2192';
opacity: 0;
position: absolute;
right: 0;
top: 50%;
-webkit-transform: translate(0, -50%);
transform: translate(0, -50%);
-webkit-transition: all 0.3s;
transition: all 0.3s;
}
.example-2 .button:hover::after {
-webkit-transform: translate(5px, -50%);
transform: translate(5px, -50%);
opacity: 1;
}
</style></head><body>
<div class="row">
<div class="example-1 card">
<div class="wrapper">
<div class="date">
786
<span class="day">12</span>
<span class="month">Aug</span>
<span class="year">2016</span>
</div>
<div class="data">
<div class="content">
<span class="author">Jane Doe</span>
<h1 class="title"><a href="#">Everything You Need to Know About Gold Medals</a></h1>
<p class="text">Olympic gold medals contain only about 1.34 percent gold, with the rest composed
of sterling silver.</p>
<label for="show-menu" class="menu-button"><span></span></label>
</div>
<input type="checkbox" id="show-menu" />
<ul class="menu-content">
<li>
<a href="#" class="fa fa-bookmark-o"></a>
</li>
<li><a href="#" class="fa fa-heart-o"><span>47</span></a></li>
<li><a href="#" class="fa fa-comment-o"><span>8</span></a></li>
</ul>
</div>
</div>
</div>
<div class="example-2 card">
<div class="wrapper">
<div class="header">
<div class="date">
<span class="day">12</span>
<span class="month">Aug</span>
<span class="year">2016</span>
</div>
<ul class="menu-content">
<li>
<a href="#" class="fa fa-bookmark-o"></a>
</li>
<li><a href="#" class="fa fa-heart-o"><span>18</span></a></li>
<li><a href="#" class="fa fa-comment-o"><span>3</span></a></li>
</ul>
</div>
<div class="data">
<div class="content">
<span class="author">Jane Doe</span>
<h1 class="title"><a href="#">Stranger Things: The sound of the Upside Down</a></h1>
<p class="text">The antsy bingers of Netflix will eagerly anticipate the digital release of the
Survive soundtrack, out today.</p>
<a href="#" class="button">Read more</a>
</div>
</div>
</div>
</div>
</div>
****************************************************************
787
Burger menu transformation
<style class="cp-pen-styles">
*,
*:before,
*:after {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
font-family: "Open Sans", sans-serif;
font-size: 1em;
background-color: #e2e2e2;
}
#menu--toggle[type="checkbox"]:not(:checked),
#menu--toggle[type="checkbox"]:checked {
display: none;
}
.menu--toggle__trigger,
.menu--toggle__burger,
.menu--toggle__burger:before,
.menu--toggle__burger:after {
position: absolute;
top: 1.6em;
left: 1.6em;
width: 2em;
height: 5px;
background-color: #282828;
border-radius: 2px;
cursor: pointer;
z-index: 100;
-webkit-transition: 0.35s cubic-bezier(0.25, 0.1, 0.25, 1);
transition: 0.35s cubic-bezier(0.25, 0.1, 0.25, 1);
}
.menu--toggle__trigger {
height: 2em;
background: none;
}
.menu--toggle__burger:before {
content: "";
top: 10px;
left: 0;
}
.menu--toggle__burger:after {
content: "";
top: 20px;
left: 0;
}
.menu__body {
788
position: absolute;
width: 7em;
height: 7em;
margin: 0;
padding: 0;
background-color: #fcfcfc;
border-bottom-right-radius: 100%;
box-shadow: 3px 3px 7px rgba(40, 40, 40, 0.2);
z-index: 10;
-webkit-animation: checkboxUncheckedAnimation 0.35s both;
animation: checkboxUncheckedAnimation 0.35s both;
}
.menu__body-element,
.menu__body-link {
display: none;
margin: 4.4em 0 -3.3em -.1em;
font-weight: normal;
color: #282828;
text-decoration: none;
text-transform: none;
list-style: none;
outline: 0;
}
.menu__body-element {
text-indent: 2em;
}
.menu__body-link:hover {
display: block;
width: 0;
color: #282828;
background-color: #e2e2e2;
-webkit-animation: changeWidthOfElementAnimation 0.35s both;
animation: changeWidthOfElementAnimation 0.35s both;
}
789
#menu--toggle:checked + .menu--toggle__trigger + .menu--toggle__burger:after {
top: 0;
-webkit-transform: rotate(90deg);
transform: rotate(90deg);
-webkit-transition: -webkit-transform 0.35s cubic-bezier(0.68, -0.55, 0.265, 1.55);
transition: -webkit-transform 0.35s cubic-bezier(0.68, -0.55, 0.265, 1.55);
transition: transform 0.35s cubic-bezier(0.68, -0.55, 0.265, 1.55);
transition: transform 0.35s cubic-bezier(0.68, -0.55, 0.265, 1.55), -webkit-transform 0.35s
cubic-bezier(0.68, -0.55, 0.265, 1.55);
}
#menu--toggle:checked + .menu--toggle__trigger + .menu--toggle__burger + .menu__body {
-webkit-animation: checkboxCheckedAnimation 1s cubic-bezier(0.25, 0.1, 0.25, 1) both;
animation: checkboxCheckedAnimation 1s cubic-bezier(0.25, 0.1, 0.25, 1) both;
}
#menu--toggle:checked + .menu--toggle__trigger ~ .menu__body .menu__body-element, #menu--
toggle:checked + .menu--toggle__trigger ~ .menu__body .menu__body-link {
display: block;
}
.promotion {
width: 100vw;
height: 100vh;
background-image: url("http://upload.wikimedia.org/wikipedia/commons/thumb/1/18/Gooseberry-
spring.jpg/1280px-Gooseberry-spring.jpg");
background-size: cover;
}
/**
* Animations
*/
@-webkit-keyframes checkboxCheckedAnimation {
50%, 100% {
width: 100vw;
height: 100vh;
}
100% {
border-radius: 0;
}
}
@keyframes checkboxCheckedAnimation {
50%, 100% {
width: 100vw;
height: 100vh;
}
100% {
border-radius: 0;
}
}
@-webkit-keyframes checkboxUncheckedAnimation {
0% {
width: 100vw;
height: 100vh;
}
}
@keyframes checkboxUncheckedAnimation {
0% {
width: 100vw;
height: 100vh;
790
}
}
@-webkit-keyframes changeWidthOfElementAnimation {
50% {
width: 0;
}
100% {
width: 100%;
}
}
@keyframes changeWidthOfElementAnimation {
50% {
width: 0;
}
100% {
width: 100%;
}
}
</style></head><body>
<section>
<article>
<div class="menu">
<input id="menu--toggle"
type="checkbox" />
<label class="menu--toggle__trigger"
for="menu--toggle"></label>
<label class="menu--toggle__burger"
for="menu--toggle"></label>
<ul class="menu__body">
<li class="menu__body-element">
<a class="menu__body-link"
href="http://codepen.io/VictorBelozyorov/pens/public"
target="_blank">
Works
</a>
</li>
<li class="menu__body-element">
<a class="menu__body-link"
href="https://twitter.com/WispProxy"
target="_blank">
Twitter
</a>
</li>
<li class="menu__body-element">
<a class="menu__body-link"
href="mailto:[email protected]">
Mail
</a>
791
</li>
</ul>
</div>
</article>
<article>
<div class="promotion">
</div>
</article>
</section>
*********************************************************************************************
<style class="cp-pen-styles">
html, body {
height: 100%;
}
body {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
-webkit-flex-direction: column;
-ms-flex-direction: column;
flex-direction: column;
-webkit-box-align: center;
-webkit-align-items: center;
-ms-flex-align: center;
align-items: center;
-webkit-box-pack: center;
-webkit-justify-content: center;
-ms-flex-pack: center;
justify-content: center;
width: 100%;
background: #668bcb;
}
.speech-bubble {
-webkit-filter: drop-shadow(-1px -1px 2px rgba(0, 0, 0, 0.1)) drop-shadow(1px 2px 2px rgba(0,
0, 0, 0.15));
filter: drop-shadow(-1px -1px 2px rgba(0, 0, 0, 0.1)) drop-shadow(1px 2px 2px rgba(0,
0, 0, 0.15));
margin: 1rem;
792
margin-bottom: 40px;
padding: 1.5rem 2rem;
position: relative;
font-family: 'Source Sans Pro', sans-serif;
font-size: 1.2rem;
font-weight: 400;
background: #8CA8D8;
color: white;
}
.speech-bubble::before {
border: 12.5px solid transparent;
border-top: 12.5px solid #8CA8D8;
border-bottom: 0;
height: 0;
width: 0;
border-top-width: 25px;
content: '';
display: block;
position: absolute;
left: 3rem;
bottom: -25px;
-webkit-transform-origin: center;
transform-origin: center;
-webkit-transform: rotate(90deg) skew(-25deg) translateY(16.66667px);
transform: rotate(90deg) skew(-25deg) translateY(16.66667px);
}
.speech-bubble cite {
position: absolute;
bottom: -2rem;
left: 4.5rem;
font-size: 1rem;
font-style: normal;
font-weight: 300;
letter-spacing: 0.5px;
color: white;
}
</style></head><body>
<blockquote class="speech-bubble">
<p>Do you think we will find a cure for any major disease in the future?</p>
<cite>Dirk Diggler M.D.</cite>
</blockquote>
*********************************************************************************************
Image Hover
<figure class="snip1543">
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/331810/sample108.jpg" alt="sample108" />
<figcaption>
<h3>Inverness McKenzie</h3>
<p>The only skills I have the patience to learn are those that have no real application in
life.</p>
</figcaption>
<a href="#"></a>
</figure>
793
<figure class="snip1543 hover"><img src="https://s3-us-west-
2.amazonaws.com/s.cdpn.io/331810/sample100.jpg" alt="sample100" />
<figcaption>
<h3>Alan Fresco</h3>
<p>The real fun of living wisely is that you get to be smug about it.</p>
</figcaption>
<a href="http://www.w3schools.com/html/tryit.asp?filename=tryhtml_default"></a>
</figure>
<figure class="snip1543"><img src="https://s3-us-west-
2.amazonaws.com/s.cdpn.io/331810/sample101.jpg" alt="sample101" />
<figcaption>
<h3>Indigo Violet</h3>
<p>But Calvin is no kind and loving god! He's one of the old gods! He demands sacrifice! </p>
</figcaption>
<a href="#"></a>
</figure>
<style>
@import url(https://fonts.googleapis.com/css?family=Source+Sans+Pro);
@import url(https://fonts.googleapis.com/css?family=Teko:700);
.snip1543 {
background-color: #fff;
color: #ffffff;
display: inline-block;
font-family: 'Source Sans Pro', sans-serif;
font-size: 16px;
margin: 10px 5px;
max-width: 315px;
min-width: 230px;
overflow: hidden;
position: relative;
text-align: left;
width: 100%;
-webkit-transform: translateZ(0);
transform: translateZ(0);
}
.snip1543 *,
.snip1543 *:before,
.snip1543 *:after {
-webkit-box-sizing: border-box;
box-sizing: border-box;
-webkit-transition: all 0.45s ease;
transition: all 0.45s ease;
}
.snip1543 img {
backface-visibility: hidden;
max-width: 100%;
vertical-align: top;
}
.snip1543:before,
.snip1543:after {
position: absolute;
top: 0;
794
bottom: 0;
left: 0;
right: 0;
content: '';
background-color: #b81212;
opacity: 0.5;
-webkit-transition: all 0.45s ease;
transition: all 0.45s ease;
}
.snip1543:before {
-webkit-transform: skew(30deg) translateX(-80%);
transform: skew(30deg) translateX(-80%);
}
.snip1543:after {
-webkit-transform: skew(-30deg) translateX(-70%);
transform: skew(-30deg) translateX(-70%);
}
.snip1543 figcaption {
position: absolute;
top: 0px;
bottom: 0px;
left: 0px;
right: 0px;
z-index: 1;
bottom: 0;
padding: 25px 40% 25px 20px;
}
.snip1543 figcaption:before,
.snip1543 figcaption:after {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
background-color: #b81212;
box-shadow: 0 0 20px rgba(0, 0, 0, 0.7);
content: '';
opacity: 0.5;
z-index: -1;
}
.snip1543 figcaption:before {
-webkit-transform: skew(30deg) translateX(-100%);
transform: skew(30deg) translateX(-100%);
}
.snip1543 figcaption:after {
-webkit-transform: skew(-30deg) translateX(-90%);
transform: skew(-30deg) translateX(-90%);
}
.snip1543 h3,
.snip1543 p {
margin: 0;
795
opacity: 0;
letter-spacing: 1px;
}
.snip1543 h3 {
font-family: 'Teko', sans-serif;
font-size: 36px;
font-weight: 700;
line-height: 1em;
text-transform: uppercase;
}
.snip1543 p {
font-size: 0.9em;
}
.snip1543 a {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
z-index: 1;
}
.snip1543:hover h3,
.snip1543.hover h3,
.snip1543:hover p,
.snip1543.hover p {
-webkit-transform: translateY(0);
transform: translateY(0);
opacity: 0.9;
-webkit-transition-delay: 0.2s;
transition-delay: 0.2s;
}
.snip1543:hover:before,
.snip1543.hover:before {
-webkit-transform: skew(30deg) translateX(-20%);
transform: skew(30deg) translateX(-20%);
-webkit-transition-delay: 0.05s;
transition-delay: 0.05s;
}
.snip1543:hover:after,
.snip1543.hover:after {
-webkit-transform: skew(-30deg) translateX(-10%);
transform: skew(-30deg) translateX(-10%);
}
.snip1543:hover figcaption:before,
.snip1543.hover figcaption:before {
-webkit-transform: skew(30deg) translateX(-40%);
transform: skew(30deg) translateX(-40%);
-webkit-transition-delay: 0.15s;
transition-delay: 0.15s;
}
796
.snip1543:hover figcaption:after,
.snip1543.hover figcaption:after {
-webkit-transform: skew(-30deg) translateX(-30%);
transform: skew(-30deg) translateX(-30%);
-webkit-transition-delay: 0.1s;
transition-delay: 0.1s;
}
body {
background-color: #212121;
text-align: center;
}
</style>
<script>
</script>
*********************************************************************************************
<style class="cp-pen-styles">
@import url(https://fonts.googleapis.com/css?family=Lato:400,900);
body {
background: #ebebeb;
font-family: 'Lato', sans-serif;
font-size: 62.5%;
}
p {
font-size: 1.15em;
line-height: 1.6em;
}
a {
text-decoration: none;
}
.c-title-page {
text-align: center;
font-size: 3em;
margin: 60px 0 0;
font-weight: 100;
797
letter-spacing: 8px;
color: #888888;
}
.c-card {
position: relative;
width: 660px;
height: 660px;
transform: translate(50vw, 50px);
margin-left: -330px;
}
.c-card__item {
position: absolute;
width: 320px;
height: 320px;
background: #FFF;
box-shadow: 0 0 2px rgba(0, 0, 0, 0.2);
transition: all 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}
.c-card__item p {
color: #e1e1e1;
transition: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}
.c-card__item:hover p {
color: #646464;
transition: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55) 0.3s;
}
.c-card__item[data-item="1"] {
top: 0;
left: 0;
}
.c-card__item[data-item="2"] {
top: 0;
left: 330px;
}
.c-card__item[data-item="3"] {
top: 330px;
left: 0;
}
.c-card__item[data-item="4"] {
top: 330px;
left: 330px;
}
.c-card__item:hover {
transform: scale(1.3);
transform-origin: center;
z-index: 2;
box-shadow: 0 0 26px rgba(0, 0, 0, 0.1);
transition: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}
798
.c-card__item:before {
content: attr(data-title);
position: absolute;
display: block;
top: 20px;
left: 20px;
opacity: 1;
font-size: 1em;
color: #FFF;
transition: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}
.c-card__item:hover:before {
opacity: 1;
font-size: 2em;
transition: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55) 0.3s;
}
.c-button {
position: absolute;
bottom: -14px;
border-radius: 50%;
height: 40px;
width: 40px;
z-index: 3;
opacity: 0;
transform: scale(0);
transform-origin: center right;
box-shadow: 0 0 2px rgba(0, 0, 0, 0.2);
font-size: .5em;
text-align: center;
transition: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}
.c-button.c-button__social {
right: 98px;
transition-delay: .0s;
}
.c-button.c-button__mail {
right: 54px;
transition-delay: .05s;
}
.c-button.c-button__plus {
right: 10px;
transition-delay: .1s;
}
.c-card__item:hover .c-button {
opacity: 1;
font-size: 2em;
transform: scale(1);
}
.c-card__item:hover .c-button.c-button__social {
transition-delay: 1s;
799
}
.c-card__item:hover .c-button.c-button__mail {
transition-delay: .9s;
}
.c-card__item:hover .c-button.c-button__plus {
transition-delay: .8s;
}
.fa:before {
font-size: 12px;
line-height: 40px;
color: #FFF;
}
.c-card__item__inner {
position: relative;
overflow: hidden;
width: 100%;
height: calc(100% - 6px);
margin: 6px 0 0 0;
background: #FFF;
transition: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}
.c-card__item:hover .c-card__item__inner {
width: 100%;
height: calc(100% - 50px);
margin: 50px 0 0 0;
transition: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55) 0.3s;
}
.c-card__content-box {
width: 100%;
height: calc(100% - 20px);
padding-top: 220px;
overflow: hidden;
transition: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}
.c-card__item:hover .c-card__content-box {
padding-top: 20px;
overflow: scroll;
transition: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55) 0.3s;
}
.c-card__content-box p {
margin: 0 10px 30px 20px;
}
.c-card__img {
position: realtive;
overflow: hidden;
}
.c-card__img img {
width: 320px;
800
}
.c-card__img:after {
content: '';
position: absolute;
display: block;
height: 200px;
width: 100%;
top: 0;
background: linear-gradient(to bottom, rgba(28, 5, 27, 0.5) 0%, rgba(255, 255, 255, 0) 100%);
transition: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}
.c-card__img h1 {
position: absolute;
top: 0;
left: 20px;
color: #FFF;
font-size: 3em;
font-weight: 900;
z-index: 1;
text-transform: uppercase;
}
.c-card__img__inner {
position: absolute;
top: 0;
left: 0;
height: 200px;
overflow: hidden;
transition: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}
.o-background--blu {
background: #3e6df3;
}
.o-background--red {
background: #e43f3f;
}
.o-background--orange {
background: #e4aa57;
}
.o-background--green {
background: #a9dd82;
}
</style></head><body>
<h1 class="c-title-page">MINI ARTICLE BOX</h1>
<div class="c-card">
<div class="c-card__item o-background--blu" data-item="1" data-title="title example">
<div class="c-button__content-box">
801
<a href="" class="c-button c-button__social o-background--blu fa fa-share-alt"></a>
<a href="" class="c-button c-button__mail o-background--blu fa fa-envelope-o"></a>
<a href="" class="c-button c-button__plus o-background--blu fa fa-plus"></a>
</div>
<div class="c-card__item__inner">
<div class="c-card__content-box">
<div class="c-card__img"><div class="c-card__img__inner"><h1>Title example</h1><img
src="http://bit.ly/2aLr0Tx" alt="" /></div></div>
<p>Quid securi etiam tamquam eu fugiat nulla pariatur. Quo usque tandem abutere,
Catilina, patientia nostra? Cum sociis natoque penatibus et magnis dis parturient. Plura mihi
bona sunt, inclinet, amari petere vellent.
Curabitur est gravida et libero vitae dictum. Fictum, deserunt mollit anim laborum astutumque!
Cras mattis iudicium purus sit amet fermentum. Tityre, tu patulae recubans sub tegmine fagi
dolor. Ut enim ad minim veniam, quis nostrud exercitation. Nihilne te nocturnum praesidium
Palati, nihil urbis vigiliae.
Paullum deliquit, ponderibus modulisque suis ratio utitur. Magna pars studiorum, prodita
quaerimus. Lorem ipsum dolor sit amet, consectetur adipisici elit, sed eiusmod tempor incidunt ut
labore et dolore magna aliqua. Fabio vel iudice vincam, sunt in culpa qui officia.Quid securi
etiam tamquam eu fugiat nulla pariatur. Quo usque tandem abutere, Catilina, patientia nostra? Cum
sociis natoque penatibus et magnis dis parturient. Plura mihi bona sunt, inclinet, amari petere
vellent.
Curabitur est gravida et libero vitae dictum. Fictum, deserunt mollit anim laborum astutumque!
Cras mattis iudicium purus sit amet fermentum. Tityre, tu patulae recubans sub tegmine fagi
dolor. Ut enim ad minim veniam, quis nostrud exercitation. Nihilne te nocturnum praesidium
Palati, nihil urbis vigiliae.
Paullum deliquit, ponderibus modulisque suis ratio utitur. Magna pars studiorum, prodita
quaerimus. Lorem ipsum dolor sit amet, consectetur adipisici elit, sed eiusmod tempor incidunt ut
labore et dolore magna aliqua. Fabio vel iudice vincam, sunt in culpa qui officia.</p></div>
</div>
</div>
<div class="c-card__item o-background--red" data-item="2" data-title="title example">
<div class="c-button__content-box">
<a href="" class="c-button c-button__social o-background--red fa fa-share-alt"></a>
<a href="" class="c-button c-button__mail o-background--red fa fa-envelope-o"></a>
<a href="" class="c-button c-button__plus o-background--red fa fa-plus"></a>
</div>
<div class="c-card__item__inner">
<div class="c-card__content-box">
<div class="c-card__img"><div class="c-card__img__inner"><h1>Title example</h1><img
src="http://bit.ly/2biB562" alt="" /></div></div>
<p>Petierunt uti sibi concilium totius Galliae in diem certam indicere. Quo usque tandem
abutere, Catilina, patientia nostra? Quisque placerat facilisis egestas cillum dolore. Quid
securi etiam tamquam eu fugiat nulla pariatur.
Unam incolunt Belgae, aliam Aquitani, tertiam. Curabitur est gravida et libero vitae dictum. Ab
illo tempore, ab est sed immemorabili.
Curabitur blandit tempus ardua ridiculus sed magna. Quam diu etiam furor iste tuus nos eludet?
Pellentesque habitant morbi tristique senectus et netus. Hi omnes lingua, institutis, legibus
inter se differunt.Quid securi etiam tamquam eu fugiat nulla pariatur. Quo usque tandem abutere,
Catilina, patientia nostra? Cum sociis natoque penatibus et magnis dis parturient. Plura mihi
bona sunt, inclinet, amari petere vellent.
Curabitur est gravida et libero vitae dictum. Fictum, deserunt mollit anim laborum astutumque!
Cras mattis iudicium purus sit amet fermentum. Tityre, tu patulae recubans sub tegmine fagi
dolor. Ut enim ad minim veniam, quis nostrud exercitation. Nihilne te nocturnum praesidium
Palati, nihil urbis vigiliae.
Paullum deliquit, ponderibus modulisque suis ratio utitur. Magna pars studiorum, prodita
quaerimus. Lorem ipsum dolor sit amet, consectetur adipisici elit, sed eiusmod tempor incidunt ut
labore et dolore magna aliqua. Fabio vel iudice vincam, sunt in culpa qui
officia.</p></div></div>
802
</div>
<div class="c-card__item o-background--green" data-item="3" data-title="title example">
<div class="c-button__content-box">
<a href="" class="c-button c-button__social o-background--green fa fa-share-alt"></a>
<a href="" class="c-button c-button__mail o-background--green fa fa-envelope-o"></a>
<a href="" class="c-button c-button__plus o-background--green fa fa-plus"></a>
</div>
<div class="c-card__item__inner">
<div class="c-card__content-box">
<div class="c-card__img"><div class="c-card__img__inner"><h1>Title example</h1><img
src="http://bit.ly/2bfzAIx" alt="" /></div></div>
<p>Quid securi etiam tamquam eu fugiat nulla pariatur. Quo usque tandem abutere,
Catilina, patientia nostra? Cum sociis natoque penatibus et magnis dis parturient. Plura mihi
bona sunt, inclinet, amari petere vellent.
Curabitur est gravida et libero vitae dictum. Fictum, deserunt mollit anim laborum astutumque!
Cras mattis iudicium purus sit amet fermentum. Tityre, tu patulae recubans sub tegmine fagi
dolor. Ut enim ad minim veniam, quis nostrud exercitation. Nihilne te nocturnum praesidium
Palati, nihil urbis vigiliae.
Paullum deliquit, ponderibus modulisque suis ratio utitur. Magna pars studiorum, prodita
quaerimus. Lorem ipsum dolor sit amet, consectetur adipisici elit, sed eiusmod tempor incidunt ut
labore et dolore magna aliqua. Fabio vel iudice vincam, sunt in culpa qui officia. Fabio vel
iudice vincam, sunt in culpa qui officia. Cum ceteris in veneratione tui montes, nascetur mus.
Cras mattis iudicium purus sit amet fermentum. Praeterea iter est quasdam res quas ex communi.
Quis aute iure reprehenderit in voluptate velit esse. Curabitur blandit tempus ardua ridiculus
sed magna.
Vivamus sagittis lacus vel augue laoreet rutrum faucibus. Fictum, deserunt mollit anim laborum
astutumque! Magna pars studiorum, prodita quaerimus. Nec dubitamus multa iter quae et nos
invenerat. Donec sed odio operae, eu vulputate felis rhoncus.</p></div></div>
</div>
<div class="c-card__item o-background--orange" data-item="4" data-title="title example">
<div class="c-button__content-box">
<a href="" class="c-button c-button__social o-background--orange fa fa-share-alt"></a>
<a href="" class="c-button c-button__mail o-background--orange fa fa-envelope-o"></a>
<a href="" class="c-button c-button__plus o-background--orange fa fa-plus"></a>
</div>
<div class="c-card__item__inner">
<div class="c-card__content-box">
<div class="c-card__img"><div class="c-card__img__inner"><h1>Title example</h1><img
src="http://bit.ly/2bizOfp" alt="" /></div></div>
<p>Fabio vel iudice vincam, sunt in culpa qui officia. Cum ceteris in veneratione tui
montes, nascetur mus. Cras mattis iudicium purus sit amet fermentum. Praeterea iter est quasdam
res quas ex communi. Quis aute iure reprehenderit in voluptate velit esse. Curabitur blandit
tempus ardua ridiculus sed magna.
Vivamus sagittis lacus vel augue laoreet rutrum faucibus. Fictum, deserunt mollit anim laborum
astutumque! Magna pars studiorum, prodita quaerimus. Nec dubitamus multa iter quae et nos
invenerat. Donec sed odio operae, eu vulputate felis rhoncus. Quid securi etiam tamquam eu fugiat
nulla pariatur. Quo usque tandem abutere, Catilina, patientia nostra? Cum sociis natoque
penatibus et magnis dis parturient. Plura mihi bona sunt, inclinet, amari petere vellent.
Curabitur est gravida et libero vitae dictum. Fictum, deserunt mollit anim laborum astutumque!
Cras mattis iudicium purus sit amet fermentum. Tityre, tu patulae recubans sub tegmine fagi
dolor. Ut enim ad minim veniam, quis nostrud exercitation. Nihilne te nocturnum praesidium
Palati, nihil urbis vigiliae.
Paullum deliquit, ponderibus modulisque suis ratio utitur. Magna pars studiorum, prodita
quaerimus. Lorem ipsum dolor sit amet, consectetur adipisici elit, sed eiusmod tempor incidunt ut
labore et dolore magna aliqua. Fabio vel iudice vincam, sunt in culpa qui
officia.</p></div></div>
</div>
</div>
803
<script>$('.c-card__item').mouseleave(function () {
$(this).find('.c-card__content-box').animate({ scrollTop: 0 }, 400);
});
</script>
*********************************************************************************************
*********************************************************************************************
Article Tiles
<div class="wrap">
<div class="tile">
<img src='https://images.unsplash.com/photo-1464054313797-
e27fb58e90a9?dpr=1&auto=format&crop=entropy&fit=crop&w=1500&h=996&q=80'/>
<div class="text">
<h1>Lorem ipsum.</h1>
<h2 class="animate-text">More lorem ipsum bacon ipsum.</h2>
<p class="animate-text">Bacon ipsum dolor amet pork belly tri-tip turducken, pancetta bresaola
pork chicken meatloaf. Flank sirloin strip steak prosciutto kevin turducken.<a
href="http://www.google.com/">Google</a> </p>
<div class="dots">
<span></span>
<span></span>
<span></span>
</div>
</div>
</div>
804
<div class="tile">
<img src='https://images.unsplash.com/photo-1458668383970-
8ddd3927deed?dpr=1&auto=format&crop=entropy&fit=crop&w=1500&h=1004&q=80'/>
<div class="text">
<h1>Lorem ipsum.</h1>
<h2 class="animate-text">More lorem ipsum bacon ipsum.</h2>
<p class="animate-text">Bacon ipsum dolor amet pork belly tri-tip turducken, pancetta bresaola
pork chicken meatloaf. Flank sirloin strip steak prosciutto kevin turducken. </p>
<div class="dots">
<span></span>
<span></span>
<span></span>
</div>
</div>
</div>
<div class="tile">
<img src='https://images.unsplash.com/photo-1422393462206-
207b0fbd8d6b?dpr=1&auto=format&crop=entropy&fit=crop&w=1500&h=1000&q=80'/>
<div class="text">
<h1>Lorem ipsum.</h1>
<h2 class="animate-text">More lorem ipsum bacon ipsum.</h2>
<p class="animate-text">Bacon ipsum dolor amet pork belly tri-tip turducken, pancetta bresaola
pork chicken meatloaf. Flank sirloin strip steak prosciutto kevin turducken. </p>
<div class="dots">
<span></span>
<span></span>
<span></span>
</div>
</div>
</div>
</div>
</div>
<style>
body
{
background-color:#eee
}
.wrap
{
margin:50px auto 0 auto;
width:100%;
display:flex;
align-items:space-around;
max-width:1200px;
}
.tile
{
width:380px;
height:380px;
margin:10px;
background-color:#99aeff;
display:inline-block;
805
background-size:cover;
position:relative;
cursor:pointer;
transition: all 0.4s ease-out;
box-shadow: 0px 35px 77px -17px rgba(0,0,0,0.44);
overflow:hidden;
color:white;
font-family:'Roboto';
}
.tile img
{
height:100%;
width:100%;
position:absolute;
top:0;
left:0;
z-index:0;
transition: all 0.4s ease-out;
}
.tile .text
{
/* z-index:99; */
position:absolute;
padding:30px;
height:calc(100% - 60px);
height:calc(100% - 60px);
}
.tile h1
{
font-weight:300;
margin:0;
text-shadow: 2px 2px 10px rgba(0,0,0,0.3);
}
.tile h2
{
font-weight:100;
margin:20px 0 0 0;
font-style:italic;
transform: translateX(200px);
}
.tile p
{
font-weight:300;
margin:20px 0 0 0;
line-height: 25px;
/* opacity:0; */
transform: translateX(-200px);
transition-delay: 0.2s;
}
.animate-text
{
opacity:0;
transition: all 0.6s ease-in-out;
}
.tile:hover
{
806
/* background-color:#99aeff; */
box-shadow: 0px 35px 77px -17px rgba(0,0,0,0.64);
transform:scale(1.05);
}
.tile:hover img
{
opacity: 0.2;
}
.tile:hover .animate-text
{
transform:translateX(0);
opacity:1;
}
.dots
{
position:absolute;
bottom:20px;
right:30px;
margin: 0 auto;
width:30px;
height:30px;
color:currentColor;
display:flex;
flex-direction:column;
align-items:center;
justify-content:space-around;
.dots span
{
width: 5px;
height:5px;
background-color: currentColor;
border-radius: 50%;
display:block;
opacity:0;
transition: transform 0.4s ease-out, opacity 0.5s ease;
transform: translateY(30px);
.tile:hover span
{
opacity:1;
transform:translateY(0px);
}
.dots span:nth-child(1)
{
transition-delay: 0.05s;
}
.dots span:nth-child(2)
{
transition-delay: 0.1s;
}
.dots span:nth-child(3)
{
807
transition-delay: 0.15s;
}
*********************************************************************************************
<style class="cp-pen-styles">
body {
margin: 0;
}
#bridge {
display: block;
margin: 0 auto;
background-image: url("https://i.ytimg.com/vi/0Yq39PLnikE/maxresdefault.jpg");
background-image: -webkit-image-set(url("https://i.ytimg.com/vi/0Yq39PLnikE/maxresdefault.jpg")
1x, url("https://i.ytimg.com/vi/0Yq39PLnikE/maxresdefault-2x.jpg") 2x);
background-size: cover;
width: 100%;
max-width: 750px;
height: auto;
cursor: crosshair;
cursor: url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/4273/circular-cursor.png) 53 53,
crosshair;
}
#bridgeContainer {
text-align: center;
font-family: Avenir, sans-serif;
}
#bridgeContainer figcaption {
margin-top: 2rem;
}
</style></head><body>
<figure id="bridgeContainer">
<canvas id="bridge" width="750" height="465"></canvas>
<figcaption> touch on photo to reveal</figcaption>
</figure>
</script>
809
*********************************************************************************************
Glowing text
<style class="cp-pen-styles">
@import "https://fonts.googleapis.com/css?family=Permanent+Marker";
body {
font: 15vw/1 Permanent Marker;
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-box-align: center;
-webkit-align-items: center;
-ms-flex-align: center;
align-items: center;
-webkit-box-pack: center;
-webkit-justify-content: center;
-ms-flex-pack: center;
justify-content: center;
height: 100vh;
text-align: center;
background: #111;
color: snow;
}
span {
-webkit-animation: glow 2s ease-in-out both infinite;
animation: glow 2s ease-in-out both infinite;
}
span:nth-child(1) {
-webkit-animation-delay: -0.28571s;
animation-delay: -0.28571s;
}
span:nth-child(2) {
-webkit-animation-delay: -0.57143s;
animation-delay: -0.57143s;
}
span:nth-child(3) {
-webkit-animation-delay: -0.85714s;
animation-delay: -0.85714s;
}
span:nth-child(4) {
-webkit-animation-delay: -1.14286s;
animation-delay: -1.14286s;
}
span:nth-child(5) {
-webkit-animation-delay: -1.42857s;
animation-delay: -1.42857s;
}
span:nth-child(6) {
-webkit-animation-delay: -1.71429s;
animation-delay: -1.71429s;
}
span:nth-child(7) {
-webkit-animation-delay: -2s;
810
animation-delay: -2s;
}
@-webkit-keyframes glow {
0%, 100% {
text-shadow: 0 0 8.33333px snow, 0 -25px 50px tomato, -25px 25px 50px yellow, 25px 25px 50px
tomato;
}
33% {
text-shadow: 0 0 8.33333px snow, 0 -25px 50px cyan, -25px 25px 50px tomato, 25px 25px 50px
cyan;
}
66% {
text-shadow: 0 0 8.33333px snow, 0 -25px 50px yellow, -25px 25px 50px cyan, 25px 25px 50px
yellow;
}
}
@keyframes glow {
0%, 100% {
text-shadow: 0 0 8.33333px snow, 0 -25px 50px tomato, -25px 25px 50px yellow, 25px 25px 50px
tomato;
}
33% {
text-shadow: 0 0 8.33333px snow, 0 -25px 50px cyan, -25px 25px 50px tomato, 25px 25px 50px
cyan;
}
66% {
text-shadow: 0 0 8.33333px snow, 0 -25px 50px yellow, -25px 25px 50px cyan, 25px 25px 50px
yellow;
}
}
</style></head><body>
<span>E</span><span>I</span><span>N</span><span>S</span><span>T</span><span>E</span><span>I</span
><span>N</span>
*********************************************************************************************
<style class="cp-pen-styles">
.sm_download_cssload_loader {
width: 344px;
height: 69px;
line-height: 69px;
text-align: center;
position: absolute;
left: 50%;
transform: translate(-50%, -50%);
-o-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
-webkit-transform: translate(-50%, -50%);
-moz-transform: translate(-50%, -50%);
font-family: helvetica, arial, sans-serif;
text-transform: uppercase;
811
font-weight: 900;
font-size:25px;
color: rgb(6,97,16);
letter-spacing: 0.2em;
}
.sm_download_cssload_loader::before, .sm_download_cssload_loader::after {
content: "";
display: block;
width: 21px;
height: 21px;
background: rgb(83,207,41);
position: absolute;
animation: sm_download_cssload_load 1.23s infinite alternate ease-in-out;
-o-animation: sm_download_cssload_load 1.23s infinite alternate ease-in-out;
-ms-animation: sm_download_cssload_load 1.23s infinite alternate ease-in-out;
-webkit-animation: sm_download_cssload_load 1.23s infinite alternate ease-in-out;
-moz-animation: sm_download_cssload_load 1.23s infinite alternate ease-in-out;
}
.sm_download_cssload_loader::before {top:0;}
.sm_download_cssload_loader::after {bottom:0;}
@keyframes sm_download_cssload_load {
0%{left:0;height:41px;width:21px;}
50%{height:11px;width:55px;}
100%{left:323px;height:41px;width:21px;}
}
@-o-keyframes sm_download_cssload_load {
0% {left:0;height:41px;width:21px;}
50% {height:11px;width:55px;}
100% {left:323px;height:41px;width:21px;}
}
@-ms-keyframes sm_download_cssload_load {
0% {left:0;height:41px;width:21px;}
50% {height:11px;width:55px;}
100% {left:323px;height:41px;width:21px;}
}
@-webkit-keyframes sm_download_cssload_load {
0% {left:0;height:41px;width:21px;}
50% {height:11px;width:55px;}
100% {left:323px;height:41px;width:21px;}
}
@-moz-keyframes sm_download_cssload_load {
0% {left:0;height:41px;width:21px;}
50% {height:11px;width:55px;}
100% {left:323px;height:41px;width:21px;}
}</style></head><body>
<div class="sm_download_cssload_loader" style="top:40%">Computer ...</div>
*********************************************************************************************
Stitching effect
812
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
preserveAspectRatio="xMidYMid" width="500px" height="400px" viewBox="0 0 500 400">
<defs>
<style>
.stitching {
fill: none;
stroke: #333;
stroke-width: 3;
stroke-linecap: round;
stroke-dasharray: 45790 45790;
animation: run_stitches 47.5s linear infinite alternate 0.5s;
}
#thread {
stroke: #333;
stroke-width: 2;
stroke-linecap: round;
transition: all;
}
.message {
font-family: Lato;
font-weight: 900;
font-size: 80px;
alignment-baseline: middle;
text-anchor: middle;
fill: #333;
}
@keyframes run_stitches {
0% { stroke-dashoffset: 0; }
100% { stroke-dashoffset: 45790; }
}
</style>
</defs>
<text class="message" x="250" y="95">Computer is a </text>
<text class="message" x="250" y="175">Machine</text>
<polyline class="stitching"
points="10 10,490 10,490 12,10 12,10 14,490 14,490 16,10 16,10 18,490 18,490 20,10 20,10 22,490
22,490 24,10 24,10 26,490 26,490 28,10 28,10 30,490 30,490 32,10 32,10 34,490 34,490 36,10 36,10
38,490 38,490 40,10 40,10 42,490 42,490 44,10 44,10 46,490 46,490 48,10 48,10 50,490 50,490 52,10
52,10 54,490 54,490 56,10 56,10 58,490 58,490 60,10 60,10 62,490 62,490 64,10 64,10 66,490 66,490
68,10 68,10 70,490 70,490 72,10 72,10 74,490 74,490 76,10 76,10 78,490 78,490 80,10 80,10 82,490
82,490 84,10 84,10 86,490 86,490 88,10 88,10 90,490 90,490 92,10 92,10 94,490 94,490 96,10 96,10
98,490 98,490 100,10 100,10 102,490 102,490 104,10 104,10 106,490 106,490 108,10 108,10 110,490
110,490 112,10 112,10 114,490 114,490 116,10 116,10 118,490 118,490 120,10 120,10 122,490 122,490
124,10 124,10 126,490 126,490 128,10 128,10 130,490 130,490 132,10 132,10 134,490 134,490 136,10
136,10 138,490 138,490 140,10 140,10 142,490 142,490 144,10 144,10 146,490 146,490 148,10 148,10
150,490 150,490 152,10 152,10 154,490 154,490 156,10 156,10 158,490 158,490 160,10 160,10 162,490
162,490 164,10 164,10 166,490 166,490 168,10 168,10 170,490 170,490 172,10 172,10 174,490 174,490
176,10 176,10 178,490 178,490 180,10 180,10 182,490 182,490 184,10 184,10 186,490 186,490 188,10
188,10 190,490 190,490 192,10 192,10 194,490 194,490 196,10 196,10 198,490 198,490 200,10 200" />
<line id="thread" x1="10" y1="200" x2="250" y2="300" />
</svg>
<script src='//assets.codepen.io/assets/common/stopExecutionOnTimeout-
53beeb1a007ec32040abaf4c9385ebfc.js'></script>
<script>window.onload = function() {
813
var thread = document.getElementById("thread"),
t_height = thread.getAttribute("y1"),
t_direction = 1,
w_direction = 1,
i = 0,
w = 0,
x_pos = 10,
raf;
/*
* There are 95 rows of "stitching", which takes 95s to animate,
* which means 1 second per row
*/
setInterval(function() {
t_height -= (2 * t_direction);
thread.setAttribute("y1", t_height)
}, 500)
setInterval(function() {
w++;
if (w > 25) {
w = 1;
w_direction *= -1;
}
x_pos += (19.2 * w_direction);
thread.setAttribute("x1", x_pos);
}, 20)
}
</script>
*********************************************************************************************
<!DOCTYPE html>
<html>
<body onload="myFunction()">
<p id="demo"></p>
<script>
function myFunction(){
var x = document.getElementById("myFile");
var txt = "";
814
if ('files' in x) {
if (x.files.length == 0) {
txt = "Select the file.";
} else {
for (var i = 0; i < x.files.length; i++) {
txt += "<br><strong>" + (i+1) + ". file</strong><br>";
var file = x.files[i];
if ('name' in file) {
txt += "name: " + file.name + "<br>";
}
if ('size' in file) {
txt += "size: " + file.size + " bytes <br>";
}
}
}
}
else {
if (x.value == "") {
txt += "Select one or more files.";
} else {
txt += "The files property is not supported by your browser!";
txt += "<br>The path of the selected file: " + x.value; // If the browser does not
support the files property, it will return the path of the selected file instead.
}
}
document.getElementById("demo").innerHTML = txt;
}
</script>
</body>
</html>
*********************************************************************************************
<style class="cp-pen-styles">html {
height: 100%;
}
body {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
-webkit-flex-direction: column;
-ms-flex-direction: column;
flex-direction: column;
-webkit-box-align: center;
-webkit-align-items: center;
-ms-flex-align: center;
align-items: center;
-webkit-box-pack: center;
815
-webkit-justify-content: center;
-ms-flex-pack: center;
justify-content: center;
height: 100%;
}
.spinner-container {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-box-orient: horizontal;
-webkit-box-direction: normal;
-webkit-flex-direction: row;
-ms-flex-direction: row;
flex-direction: row;
}
.spinner {
-webkit-box-flex: 0;
-webkit-flex-grow: 0;
-ms-flex-positive: 0;
flex-grow: 0;
-webkit-flex-shrink: 0;
-ms-flex-negative: 0;
flex-shrink: 0;
width: 80px;
height: 80px;
margin-left: -36px;
background: none;
border-radius: 50%;
border: 6px solid currentColor;
box-sizing: border-box;
-webkit-animation-name: spin;
animation-name: spin;
-webkit-animation-duration: 1.2s;
animation-duration: 1.2s;
-webkit-animation-fill-mode: backwards;
animation-fill-mode: backwards;
-webkit-animation-iteration-count: infinite;
animation-iteration-count: infinite;
-webkit-animation-timing-function: linear;
animation-timing-function: linear;
}
.spinner:first-child {
margin-left: 0;
color: rgba(0, 41, 140, 0.2);
border-top-color: #00298C;
}
.spinner:nth-child(2) {
color: rgba(255, 239, 8, 0.2);
border-top-color: #FFEF08;
}
.spinner:nth-child(3) {
color: rgba(0, 0, 0, 0.2);
border-top-color: #000000;
}
.spinner:nth-child(4) {
816
color: rgba(8, 123, 57, 0.2);
border-top-color: #087B39;
}
.spinner:nth-child(5) {
color: rgba(222, 24, 24, 0.2);
border-top-color: #DE1818;
}
.spinner:nth-child(2n) {
margin-top: 40px;
}
@-webkit-keyframes spin {
0% {
-webkit-transform: rotate(0);
transform: rotate(0);
}
100% {
-webkit-transform: rotate(360deg);
transform: rotate(360deg);
}
}
@keyframes spin {
0% {
-webkit-transform: rotate(0);
transform: rotate(0);
}
100% {
-webkit-transform: rotate(360deg);
transform: rotate(360deg);
}
}
</style></head><body>
<div class="spinner-container">
<div class="spinner"></div>
<div class="spinner"></div>
<div class="spinner"></div>
<div class="spinner"></div>
<div class="spinner"></div>
</div>
<script>$(document).ready(function () {
$('.spinner-container').children('.spinner').each(function (index) {
var delay = index * 0.3;
});
});
</script>
*********************************************************************************************
817
<style class="cp-pen-styles">
body {
-webkit-text-size-adjust: 100%;
-webkit-font-feature-settings: "kern" 1;
-moz-font-feature-settings: "kern" 1;
-o-font-feature-settings: "kern" 1;
font-feature-settings: "kern" 1;
font-kerning: normal;
}
main {
position: relative;
}
.triangle {
position: absolute;
width: 0;
height: 0;
border-top: 28vh solid #ff4081;
border-right: 40vw solid transparent;
opacity: 0.90;
z-index: -1;
transition: all 0.3s cubic-bezier(.17,.67,.83,.67);
}
.triangle-2 {
position: absolute;
width: 0;
height: 0;
border-top: 25vh solid #cecdfe;
border-right: 75vw solid transparent;
opacity: 0.90;
z-index: -2;
transition: all 0.3s cubic-bezier(.17,.67,.83,.67);
}
.triangle-3 {
position: absolute;
display: block;
right: 0;
width: 0;
height: 0;
border-top: 25vh solid #4b007d;
border-left: 75vw solid transparent;
opacity: 0.90;
z-index: -3;
transition: all 0.3s cubic-bezier(.17,.67,.83,.67);
}
.container {
position: relative;
top: 20vh;
padding: 50px 1em;
max-width: 1000px;
margin: 0 auto;
z-index: 100;
}
818
@media only screen and (min-width: 768px) {
.triangle {
border-top: 120vh solid #ff4081;
border-right: 35vw solid transparent;
}
.triangle-2 {
border-top: 120vh solid #cecdfe;
border-right: 40vw solid transparent;
}
.triangle-3 {
display: none;
}
.container {
top: 10vh;
}
}
article {
max-width: 700px;
margin: 0 auto;
z-index: 100;
}
article h1 {
font-family: 'Merriweather';
font-weight: 700;
font-size: 3.5rem;
color: #202020;
margin-bottom: 0.25em;
text-align: center;
}
article .metadata {
margin-bottom: 1em;
}
article span {
font-family: Merriweather;
font-size: 1em;
font-weight: 400;
display: block;
color: #828385;
text-align: center;
margin-bottom: 0.250em
}
article p {
font-family: 'PT Sans';
font-weight: 400;
font-size: 1.050em;
line-height: 1.635;
color: #444;
margin-bottom: 1.1635em;
padding: 0.50em;
}
819
}</style></head><body>
<main>
<div class="triangle"></div>
<div class="triangle-2"></div>
<div class="triangle-3"></div>
<div class="container">
<article>
<h1>Title</h1>
<div class="metadata">
<span class="author">by Albert Einstein</span>
<span class="date">August 2nd, 1939</span>
</div>
<p>Some recent work by E. Fermi and L. Szilard, which has been communicated to me in
manuscript, leads me to expect that the element uranium may be turned into a new and important
source of energy in the immediate future. Certain aspects of the situation which has arisen seem
to call for watchfulness and if necessary, quick action on the part of the Administration. I
believe therefore that it is my duty to bring to your attention the following facts and
recommendations.</p>
<p>
In the course of the last four months it has been made probable through the work of Joliot in
France as well as Fermi and Szilard in America--that it may be possible to set up a nuclear chain
reaction in a large mass of uranium, by which vast amounts of power and large quantities of new
radium-like elements would be generated. Now it appears almost certain that this could be
achieved in the immediate future.
This new phenomenon would also lead to the construction of bombs, and it is conceivable--though
much less certain--that extremely powerful bombs of this type may thus be constructed. A single
bomb of this type, carried by boat and exploded in a port, might very well destroy the whole port
together with some of the surrounding territory. However, such bombs might very well prove too
heavy for transportation by air.
The United States has only very poor ores of uranium in moderate quantities. There is some good
ore in Canada and former Czechoslovakia, while the most important source of uranium is in the
Belgian Congo.</p>
<p>In view of this situation you may think it desirable to have some permanent contact maintained
between the Administration and the group of physicists working on chain reactions in America. One
possible way of achieving this might be for you to entrust the task with a person who has your
confidence and who could perhaps serve in an unofficial capacity. His task might comprise the
following:
a) to approach Government Departments, keep them informed of the further development, and put
forward recommendations for Government action, giving particular attention to the problem of
securing a supply of uranium ore for the United States.
b) to speed up the experimental work, which is at present being carried on within the limits of
the budgets of University laboratories, by providing funds, if such funds be required, through
his contacts with private persons who are willing to make contributions for this cause, and
perhaps also by obtaining co-operation of industrial laboratories which have necessary equipment.
I understand that Germany has actually stopped the sale of uranium from the Czechoslovakian mines
which she has taken over. That she should have taken such early action might perhaps be
820
understood on the ground that the son of the German Under-Secretary of State, von Weizsacker, is
attached to the Kaiser-Wilhelm Institute in Berlin, where some of the American work on uranium is
now being repeated.</p>
<p>Yours very truly,</p>
<p class="meh">Albert Einstein</p>
</article>
</div>
</main>
*********************************************************************************************
<style class="cp-pen-styles">
body {
font-size: calc(100% + .25vw);
line-height: 1.4em;
}
main {
max-width: 100%;
margin: 0 auto;
}
article {
max-width: 85%;
padding: 0 .5rem 0 15%;
}
h2 {
font-size: 1.6em;
line-height: 1;
-webkit-writing-mode: vertical-lr;
-ms-writing-mode: tb-lr;
writing-mode: vertical-lr;
float: left;
margin: 0 0 0 -5%;
padding: .1em .5em .5em .1em;
max-height: 500px;
}
article {
max-width: 35rem;
padding-left: 5rem;
}
h2 {
font-size: 2.6em;
margin-left: -2.6rem;
821
}
}
</style></head><body>
<main>
<article>
<center> <h1>Einstein's Special Theory of Relativity </h> </center>
<p>It's a fact of life: Some things are absolute, and some are relative. For me, the teapot
on the table is to the left of my cup. From the point of view of an observer sitting directly
opposite, it's the other way around: My cup is to the left of the teapot. "Left" and "right" are
relative. Whether or not an object is located to the left or to the right of another depends on
the observer. On the other hand, if the cup is filled to the brim with coffee, all observers
should agree to the fact, regardless of where they sit. That, it would seem, is an absolute
statement, independent of who makes the observation.</p>
<p>Einstein's special theory of relativity (special relativity) is all about what's relative
and what's absolute about time, space, and motion. Some of Einstein's conclusions are rather
surprising. They are nonetheless correct, as numerous physics experiments have shown. And they
have forced physicists to revise the way they think about some of their science's most basic
concepts.</p>
<p>"Everything is relative," as the pop version of Einstein's theory goes. Not so. That
statement, for instance, is absolutely wrong. The scope of special relativity is rather more
narrow. It concerns only very special situations, very special observers, very special questions
of relativity and absoluteness.</p>
<p>The prime example of a situation governed by special relativity is a region far, far away
in the depths of space, far away from all stars and planets (and their gravitational influence).
Imagine that, in this dark void, there are freely moving space stations, drifting along without
any acceleration or rotation.</p>
<p>On each of these stations sits an observer, with his own clocks and his own measuring
rods, measuring times and distances. In addition, each such observer has a fully equipped physics
lab on board, where he or she can perform a variety of experiments to explore the laws of
physics. This is the kind of observer Einstein talks about, an observer in a free, unaccelerated
frame of reference. Such frames of reference (and such observers) are commonly called inertial
frames of reference (and inertial observers).</p>
</article>
</main>
*********************************************************************************************
* {
outline: none;
}
body {
background: #343436;
font-family: 'Lato';
}
822
/*👇 for preload play/pause svg 😎*/
body:after {
position: absolute;
width: 0;
height: 0;
overflow: hidden;
z-index: -1;
content: url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/163884/play.svg)
url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/163884/pause.svg);
}
article{
position: absolute;
width: 50%;
height: 300px;
top: 40px;
left: 0;
bottom: 0;
right: 0;
margin: auto;
text-align: center;
padding: 50px 5%;
box-sizing: border-box;
box-shadow: 0 0 21px 0px rgba(0,0,0,0.3);
border-radius: 10px;
}
.cont{
margin-bottom: 28px;
}
.cont h3{
font-family: 'Lato';
font-size: 50px;
margin: 0 0 10px 0;
color: #ccc;
}
.cont time{
font-family: 'Lato';
font-size: 12px;
color: #999;
/*
*style audio tag
*/
.mejs-container {
background: #000;
font-family: Helvetica, Arial;
text-align: left;
vertical-align: top;
text-indent: 0;
width: 100% !important;
height: 50px !important;
823
border-radius: 5px;
}
.mejs-container .mejs-controls {
height: 100%;
background: transparent;
display: flex;
}
.mejs-controls div.mejs-time-rail {
padding-top: initial;
height: 100%;
}
824
position: absolute;
background: #000;
width: 46px;
height: 20px;
border: none;
top: -25px;
margin-left: -18px;
text-align: center;
color: #fff;
border-radius: 3px;
}
.mejs-controls .mejs-play:after {
position: absolute;
content: "";
background: url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/163884/play.svg) no-repeat;
width: 17px;
height: 22px;
top: 0;
left: 0;
bottom: 0;
right: 0;
margin: auto;
transition: all 100ms linear;
pointer-events: none;
}
.mejs-controls .mejs-pause:after {
position: absolute;
content: "";
background: url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/163884/pause.svg) no-repeat;
width: 13px;
825
height: 22px;
top: 0;
left: 0;
bottom: 0;
right: 0;
margin: auto;
transition: all 100ms linear;
pointer-events: none;
}
@-webkit-keyframes move {
0% {
background-position: 0 0;
}
100% {
background-position: 50px 50px;
}
}</style></head><body>
<article>
<div class="cont">
<h3>100: Big Ones</h3>
<time>June 26, 2016</time>
</div>
<audio class="audio" controls="controls">
<source type="audio/mpeg" src="http://media.blubrry.com/codepen_radio/p/codepen-
podcast.s3.amazonaws.com/100.mp3?_=1">
</audio>
</article>
<script>$('audio').mediaelementplayer({
features: [
'playpause',
'progress',
826
'current',
'tracks',
'fullscreen'
]
});
</script>
*********************************************************************************************
body {
margin: 0;
}
#poster {
-webkit-perspective: 800px;
perspective: 800px;
background: -webkit-linear-gradient(#115695, #fff 50%);
background: linear-gradient(#115695, #fff 50%);
width: 1000px;
position: relative;
height: 1300px;
margin: 0 auto;
}
#banner {
text-transform: uppercase;
text-align: center;
font-size: 2rem;
width: 28rem;
line-height: .9;
-webkit-transform-origin: top left;
transform-origin: top left;
-webkit-transform: rotateX(15deg) skewX(15deg) translateX(100px);
transform: rotateX(15deg) skewX(15deg) translateX(100px);
background: #fff;
827
padding: 1rem;
position: relative;
height: 100%;
}
#banner h1 {
font-family: AeroMatics Display, sans-serif;
color: red;
font-size: 7rem;
letter-spacing: -.2rem;
}
#banner span {
font-family: AeroMatics Light, sans-serif;
letter-spacing: .2rem;
line-height: 1.2;
}
#plan9 {
position: absolute;
bottom: 0;
}
#spaceship {
position: absolute;
top: 120px;
right: 70px;
width: 25%;
}
#credits {
width: 50%;
margin-top: 18rem;
margin-left: 15rem;
text-align: center;
}
#credits span:first-of-type {
font-size: 1rem;
margin-top: 0;
}
.actor {
text-transform: uppercase;
font-size: 1.4rem;
display: block;
}
.production {
font-size: .7rem;
font-family: AeroMatics Light;
letter-spacing: .1rem;
line-height: 1.2;
}
</style></head><body>
<div id="poster">
<div id="banner">
828
<span>Plan 9 From Outer Space: Unspeakable horrors from outer space paralyze the living and
resurrect the dead!</span>
<h1>Tom and Jerry</h1>
<div id="credits">
<span>with</span>
<span class="actor"> William Hanna </span>
<span class="actor"> Rudolf Ising</span>
<span class="actor">Lyle Talbot</span>
<p class="production">A J. Reynolds Production</p>
<p class="production">Produced and Directed by Edward D. Wood, Jr.</p>
</div>
</div>
<right><img src="http://www.vector-eps.com/wp-content/gallery/classic-cartoon-characters/classic-
cartoon-vector18.jpg" id="spaceship"> </right>
<img src="http://wallpaperspicturesphotos.com/wp-content/uploads/2015/01/Funny-Cartoons-Pictures-
Of-Tom-And-Jerry-8.jpg" id="plan9">
</div>
*********************************************************************************************
<style class="cp-pen-styles">
html, body {
height: 100%;
margin: 0;
}
p {
width: 100%;
margin: 0;
padding: 1em;
color: white;
font-family: sans-serif;
text-transform: uppercase;
background: rgba(255, 0, 0, 0.8);
}
/* scene wrapper */
.wrapper {
width: 100vw;
height: 100vh;
margin-top: 0;
position: absolute;
right: 0;
top: 0;
perspective-origin: top center;
overflow: hidden;
}
/* cube wrapper */
.parent {
position: relative;
width: 100vw;
829
height: 100vh;
animation: spin 4s infinite linear;
transition: all 1s linear;
perspective: 1000px;
text-align: center;
font-weight: 900;
letter-spacing: 0.5em;
font-size: 2em;
}
.parent:hover {
transform: translateX(-100vw);
}
/* outer cube */
.child {
position: absolute;
width: 100%;
height: 90vh;
margin-top: 5vh;
display: flex;
align-items: center;
color: rgba(0, 0, 0, 0.5);
font-family: sans-serif;
text-transform: uppercase;
transition: all 1s linear;
transform-origin: 100% 0;
}
.details {
background: url("https://unsplash.it/g/1500/1500") center center;
background-size: cover;
transform: rotateY(90deg) translateX(100vw);
z-index: 1;
}
.parent:hover .details {
z-index: 2;
transform: rotateY(0deg) translateX(100vw);
}
.home {
background: url("https://unsplash.it/g/1600/1600") center center;
background-size: cover;
z-index: 2;
}
.parent:hover .home {
transform: rotateY(-135deg);
}
</style></head><body>
<div class="wrapper">
<div class="parent">
<div class="child home"><p> Home </p></div>
<div class="child details"> <p><a href="http://www.w3schools.com/html/">Home</a></p></div>
</div>
</div>
830
*********************************************************************************************
<style class="cp-pen-styles">
html,
body {
margin: 0;
padding: 0;
height: 100vh;
width: 100vw;
overflow: hidden;
.container {
width: 100%;
height: 100%;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-pack: center;
-ms-flex-pack: center;
justify-content: center;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
background-color: #2196F3;
831
/* for background beginning */
background-color: #F5F3F3;
position: absolute;
z-index: 2;
width: 100%;
height: 200px;
min-height: 200px;
max-height: auto;
-webkit-box-pack: center;
-ms-flex-pack: center;
justify-content: center;
-ms-flex-line-pack: center;
align-content: center;
position: absolute;
left: 0px;
z-index: 10;
color: #0D47A1;
832
-ms-flex-item-align: center;
align-self: center;
text-transform: uppercase;
font-size: 13px;
color: #0D47A1;
height: auto;
text-align: center;
text-transform: uppercase;
-webkit-box-pack: center;
-ms-flex-pack: center;
justify-content: center;
-ms-flex-item-align: center;
align-self: center;
color: #BDBDBD;
display: inline-block;
color: #0D47A1;
833
content: "send";
position: relative;
top: 0px;
left: 23px;
z-index: 1;
.container > .banner > a.active > i:before, .container > .banner > a:hover > i:before,
/* animation beginning */
@-webkit-keyframes paper-plane {
0% {
left: 23px;
top: 0px;
-webkit-transform: rotate(0deg);
20% {
left: 125px;
-webkit-transform: rotate(-90deg);
40% {
top: -60px;
834
-webkit-transform: rotate(-180deg);
60% {
left: -225px;
-webkit-transform: rotate(-270deg);
80% {
top: 0px;
-webkit-transform: rotate(-360deg);
100% {
left: 23px;
-webkit-transform: rotate(-360deg);
@keyframes paper-plane {
0% {
left: 23px;
top: 0px;
-webkit-transform: rotate(0deg);
transform: rotate(0deg);
20% {
left: 125px;
-webkit-transform: rotate(-90deg);
transform: rotate(-90deg);
40% {
top: -60px;
835
-webkit-transform: rotate(-180deg);
transform: rotate(-180deg);
60% {
left: -225px;
-webkit-transform: rotate(-270deg);
transform: rotate(-270deg);
80% {
top: 0px;
-webkit-transform: rotate(-360deg);
transform: rotate(-360deg);
100% {
left: 23px;
-webkit-transform: rotate(-360deg);
transform: rotate(-360deg)
/* animation end */
.heading {
color: #222;
836
.text {
-ms-user-select: none;
-moz-user-select: none;
-webkit-user-select: none;
cursor: default;
.text.nodecoration {
text-decoration: none;
cursor: pointer;
.text.black {
color: #444;
.text.white {
color: #F5F3F3;
.text.outline {
-webkit-text-fill-color: transparent;
-webkit-text-stroke-width: 2px;
.text.outline.white {
-webkit-text-stroke-color: #FCFCFC;
837
.text.outline.black {
-webkit-text-stroke-color: #444;
.offwhite-light {
background-color: #FCFCFC;
.offwhite-dark {
background-color: #F5F3F3;
.uppercase {
text-transform: uppercase;
.shadow {
.shadow.bottom {
.shadow.top {
.shadow.tobo {
box-shadow: 0px -2px 5px rgba(0, 0, 0, 0.26), 0px 2px 5px rgba(0, 0, 0, 0.26);
838
}
.flex {
display: -webkit-inline-box;
display: -ms-inline-flexbox;
display: inline-flex;
.flex.vertical {
.flex.horizontal {
</div>
</div>
839
<script>var timeOut;
document.getElementById('contact-link').addEventListener('mouseover', function () {
clearTimeout(timeOut);
timeOut = setTimeout(function () {
}, 4000);
});
</script>
*********************************************************************************************
Border Animation
<style class="cp-pen-styles">
@-webkit-keyframes bg {
0% {
background-size: 0 3px,
3px 0,
0 3px,
3px 0;
}
25% {
background-size: 100% 3px,
3px 0,
0 3px,
3px 0;
}
50% {
background-size: 100% 3px,
3px 100%,
0 3px,
3px 0;
}
75% {
background-size: 100% 3px,
3px 100%,
100% 3px,
3px 0;
}
100% {
background-size: 100% 3px,
3px 100%,
100% 3px,
3px 100%;
840
}
}
@keyframes bg {
0% {
background-size: 0 3px,
3px 0,
0 3px,
3px 0;
}
25% {
background-size: 100% 3px,
3px 0,
0 3px,
3px 0;
}
50% {
background-size: 100% 3px,
3px 100%,
0 3px,
3px 0;
}
75% {
background-size: 100% 3px,
3px 100%,
100% 3px,
3px 0;
}
100% {
background-size: 100% 3px,
3px 100%,
100% 3px,
3px 100%;
}
}
div {
width: 25%;
margin: 2rem auto;
padding: 2em;
background-repeat: no-repeat;
background-image: -webkit-linear-gradient(left, #C9C9C9 100%, #C9C9C9 100%),
-webkit-linear-gradient(top, #C9C9C9 100%, #C9C9C9 100%),
-webkit-linear-gradient(left, #C9C9C9 100%, #C9C9C9 100%),
-webkit-linear-gradient(top, #C9C9C9 100%, #C9C9C9 100%);
background-image: linear-gradient(to right, #C9C9C9 100%, #C9C9C9 100%),
linear-gradient(to bottom, #C9C9C9 100%, #C9C9C9 100%),
linear-gradient(to right, #C9C9C9 100%, #C9C9C9 100%),
linear-gradient(to bottom, #C9C9C9 100%, #C9C9C9 100%);
background-size: 100% 3px,
3px 100%,
100% 3px,
3px 100%;
background-position: 0 0,
100% 0,
100% 100%,
0 100%;
841
-webkit-animation: bg 1.25s cubic-bezier(0.19, 1, 0.22, 1) 1;
animation: bg 1.25s cubic-bezier(0.19, 1, 0.22, 1) 1;
-webkit-animation-play-state: paused;
animation-play-state: paused;
}
div:hover {
-webkit-animation-play-state: running;
animation-play-state: running;
}</style></head><body>
<div>
<h1>Hover me!</h1>
<p>Planck's law describes the spectral density of electromagnetic radiation emitted by a black
body in thermal equilibrium at a given temperature T. The law is named after Max Planck, who
proposed it in 1900. It is a pioneering result of modern physics and quantum theory</p>
</div>
*********************************************************************************************
<style class="cp-pen-styles">
@import url(https://fonts.googleapis.com/css?family=Oswald|Roboto);
body {
margin: 0;
height: 100vh;
font-family: "Roboto", sans-serif;
background: linear-gradient(5deg, #0e0f12, #198ada);
-moz-background-size: cover;
-o-background-size: cover;
-webkit-background-size: cover;
background-size: cover;
background-repeat: no-repeat;
background-position: center center;
}
body .overlay {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.1);
}
.container {
height: 100vh;
}
h1 {
position: fixed;
bottom: -7px;
right: 93px;
color: #ffffff;
font-size: 34px;
}
842
.container-header {
position: fixed;
width: 70px;
height: 100%;
background: #0e0f12;
z-index: 2;
}
.container-header .btn-close {
position: absolute;
top: 0;
right: 0;
margin: 20px;
width: 40px;
height: 40px;
background-color: #198ada;
border-radius: 50%;
display: none;
}
.container-header .btn-close:before {
content: "";
position: absolute;
display: block;
top: -20px;
right: -20px;
width: 90px;
height: 80px;
}
.container-header .btn-close .icon-item {
display: block;
width: 23px;
height: 2px;
background-color: #fff;
position: absolute;
top: 13px;
right: 9px;
}
.container-header .btn-close .icon-item:nth-child(2) {
top: 19px;
}
.container-header .btn-close .icon-item:nth-child(3) {
top: 25px;
}
.container-header a {
color: #fff;
}
.container-header .logo {
cursor: pointer;
position: relative;
display: block;
height: 80px;
background: #198ada;
}
.container-header .logo .box-icon-logo {
position: absolute;
top: 30px;
left: 14px;
right: 14px;
843
height: 22px;
width: 42px;
}
.container-header .logo .box-icon-logo .item-logo {
display: block;
height: 8px;
background-color: #fff;
float: right;
}
.container-header .logo .box-icon-logo .item-logo:nth-child(1) {
width: 19px;
}
.container-header .logo .box-icon-logo .item-logo:nth-child(2) {
width: 32px;
}
.container-header .logo .box-icon-logo .item-logo:nth-child(3) {
width: 42px;
}
.container-header .menu-item {
cursor: pointer;
position: relative;
display: block;
width: 100%;
height: 70px;
text-align: center;
line-height: 80px;
-moz-transition: all 0.3s;
-o-transition: all 0.3s;
-webkit-transition: all 0.3s;
transition: all 0.3s;
}
.container-header .menu-item .icon {
fill: #878789;
-moz-transition: all 0.3s;
-o-transition: all 0.3s;
-webkit-transition: all 0.3s;
transition: all 0.3s;
}
.container-header .menu-item .menu-text {
position: absolute;
top: 0;
left: -170px;
height: 70px;
width: 170px;
background-color: #198ada;
font-size: 24px;
text-align: center;
line-height: 70px;
color: transparent;
-moz-transition: all 0.3s;
-o-transition: all 0.3s;
-webkit-transition: all 0.3s;
transition: all 0.3s;
}
.container-header .menu-item:hover {
background: #198ada;
}
.container-header .menu-item:hover .icon {
844
fill: #fff;
}
.container-header .menu-item:hover .menu-text {
color: #124268;
left: 70px;
}
.container-header .menu-item:focus {
color: #198ada;
}
.container-header .item.active .menu-item {
background: #198ada;
}
.container-header .item.active .menu-item .icon {
fill: #fff;
}
.icon-info {
width: 24px;
height: 24px;
}
.icon-fly {
width: 22px;
height: 21px;
}
.icon-man {
width: 21px;
height: 22px;
}
.icon-star {
width: 24px;
height: 23px;
}
.icon-doc-menu {
width: 28px;
height: 19px;
}
.icon-email-menu {
width: 27px;
height: 21px;
}
.rabbit {
width: 50px;
height: 50px;
position: absolute;
bottom: 20px;
right: 20px;
z-index: 3;
fill: #fff;
}
</style></head><body>
<div class="container">
<h1>
845
Vertical menu
</h1>
<div class="overlay"></div>
<div class="container-header">
<div class="container-header-items">
<div class="container-items">
<div class="logo">
<div class="box-icon-logo">
<div class="item-logo"></div>
<div class="item-logo"></div>
<div class="item-logo"></div>
</div>
</div>
<div class="btn-close">
<div class="icon-item"></div>
<div class="icon-item"></div>
<div class="icon-item"></div>
</div>
<div class="item">
<div class="menu-item">
<svg class="icon icon-fly"><use xlink:href="#icon-fly"></use></svg>
<div class="menu-text">
<a href="http://www.w3schools.com/html/">Home</a>
</div>
</div>
</div>
<div class="item">
<a class="menu-item" href="#team"><svg class="icon icon-man"><use xlink:href="#icon-
man"></use></svg>
<div class="menu-text">
Team
</div>
</a>
</div>
<div class="item">
<div class="menu-item">
<svg class="icon icon-info"><use xlink:href="#icon-info"></use></svg>
<div class="menu-text">
About
</div>
</div>
</div>
<div class="item">
<div class="menu-item">
<svg class="icon icon-star"><use xlink:href="#icon-star"></use></svg>
<div class="menu-text">
Testimonials
</div>
</div>
</div>
<div class="item">
<div class="menu-item">
<svg class="icon icon-doc-menu"><use xlink:href="#icon-doc-menu"></use></svg>
<div class="menu-text">
Odd Ends
</div>
</div>
</div>
846
<div class="item item-footer">
<div class="menu-item">
<svg class="icon icon-email-menu"><use xlink:href="#icon-email"></use></svg>
<div class="menu-text">
Info
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<svg data-duration="10" data-delay="45" display="none" width="0" height="0" version="1.1"
xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<defs>
847
3.71l43.3,17.18A2,2,0,0,1,1898.79,1321.49Zm0,17.76a2.111,2.111,0,0,1-.74-0.14l-43.29-
17.18a2,2,0,0,1,1.47-3.72l43.3,17.18A2,2,0,0,1,1898.79,1339.25Z" transform="translate(-1844 -
1238)"></path></symbol>
848
<path class="cls-1" d="M2477.49,1702c-13.67,0-24.87-22.23-27.25-54.05a2,2,0,1,1,3.99-
.3c2.15,28.7,12.15,50.35,23.26,50.35,12.84,0,23.69-28.39,23.69-62s-10.85-62-23.69-62c-7.63,0-
15.14,10.56-19.59,27.56a2,2,0,1,1-3.87-1.02c5.01-19.12,13.78-30.54,23.46-
30.54,15.53,0,27.69,28.99,27.69,66S2493.02,1702,2477.49,1702Zm-48.77-24.33c-7.31,0-12.58-1.78-
15.3-5.33a10.638,10.638,0,0,1-1.69-8.98c2.63-12.85,23-31.94,50.68-47.5,31.45-17.68,69.66-
28.58,79.15-16.2a10.441,10.441,0,0,1,1.78,8.51c-1.91,10.96-17.05,26.75-39.5,41.19a2,2,0,0,1-2.17-
3.37c21.22-13.64,36.03-28.76,37.73-38.51a6.579,6.579,0,0,0-1.02-5.39c-6.3-8.22-37.54-3.24-
74.01,17.26-26.31,14.79-46.34,33.22-
48.72,44.81a6.77,6.77,0,0,0,.95,5.75c4.17,5.44,19.32,4.88,38.59-
1.43a2,2,0,1,1,1.25,3.8C2445.47,1675.87,2436.06,1677.67,2428.72,1677.67Zm97.65,0.19c-16.46.01-
41.96-9.21-64.09-21.8-27.56-15.68-47.81-34.85-50.38-47.71-0.71-3.56-.12-6.58,1.75-8.99,5.49-
7.07,21.1-7,42.84.2a189.115,189.115,0,0,1,21.86,8.88,2,2,0,0,1-1.73,3.61,187.216,187.216,0,0,0-
21.39-8.7c-19.15-6.33-34.22-6.94-38.42-1.54a6.771,6.771,0,0,0-
.98,5.75c2.32,11.61,22.23,30.12,48.43,45.03,36.34,20.67,67.55,25.79,73.9,17.6,3.23-4.16-.26-
12.44-9.34-22.14a2,2,0,1,1,2.93-
2.73c10.84,11.6,14.25,21.3,9.58,27.32C2538.52,1676.26,2533.23,1677.86,2526.37,1677.86Zm-48.66-
32.31a9.555,9.555,0,1,1,9.56-9.55A9.566,9.566,0,0,1,2477.71,1645.55Zm0-
15.11a5.555,5.555,0,1,0,5.56,5.56A5.567,5.567,0,0,0,2477.71,1630.44Z" transform="translate(-
2411.44 -1570)"></path>
</symbol>
849
<symbol id="icon-man" width="21" height="22" viewBox="0 0 21 22">
<path class="cls-1" d="M3141.5,290a5.5,5.5,0,1,1,5.51-5.5A5.517,5.517,0,0,1,3141.5,290Zm0-
8.967a3.469,3.469,0,1,0,3.48,3.469A3.478,3.478,0,0,0,3141.5,281.03ZM3151.99,301h-20.98v-0.957c0-
3.89,4.7-7.055,10.49-7.055s10.49,3.165,10.49,7.055V301ZM3133,299h17c-0.76-2.348-4.44-4.1-8.5-
4.1S3133.76,296.652,3133,299Z" transform="translate(-3131 -279)"></path></symbol>
850
<path id="Logo_copy" data-name="Logo copy" class="cls-1"
d="M1750,949V916h59V880l87,0v100H1705V949h45Z" transform="translate(-1703.5 -
878.5)"></path></symbol>
<filter id="goo">
<feGaussianBlur in="SourceGraphic" result="blur" stdDeviation="10"></feGaussianBlur>
<feColorMatrix in="blur" mode="matrix" values="1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 18 -7"
result="goo"></feColorMatrix>
<feBlend in2="goo" in="SourceGraphic" result="mix"></feBlend>
</filter>
851
*********************************************************************************************
.field {
position: absolute;
top: 50%;
left: 50%;
-webkit-transform-style: preserve-3d;
transform-style: preserve-3d;
-webkit-transform: translateY(-35px) rotateX(-35deg);
transform: translateY(-35px) rotateX(-35deg);
}
@-webkit-keyframes forward {
from {
-webkit-transform: rotateY(0deg);
transform: rotateY(0deg);
}
to {
-webkit-transform: rotateY(360deg);
transform: rotateY(360deg);
}
}
@keyframes forward {
from {
-webkit-transform: rotateY(0deg);
transform: rotateY(0deg);
}
to {
-webkit-transform: rotateY(360deg);
transform: rotateY(360deg);
}
}
@-webkit-keyframes backward {
from {
-webkit-transform: rotateY(0deg);
transform: rotateY(0deg);
}
to {
-webkit-transform: rotateY(-360deg);
transform: rotateY(-360deg);
}
}
@keyframes backward {
from {
-webkit-transform: rotateY(0deg);
transform: rotateY(0deg);
852
}
to {
-webkit-transform: rotateY(-360deg);
transform: rotateY(-360deg);
}
}
.gear {
position: absolute;
-webkit-transform-style: preserve-3d;
transform-style: preserve-3d;
}
.spinner-1 .turntable,
.spinner-4 .turntable,
.spinner-5 .turntable {
-webkit-transform-style: preserve-3d;
transform-style: preserve-3d;
-webkit-animation: forward 12s linear infinite;
animation: forward 12s linear infinite;
}
.spinner-2 .turntable,
.spinner-3 .turntable,
.spinner-6 .turntable {
-webkit-transform-style: preserve-3d;
transform-style: preserve-3d;
-webkit-animation: backward 12s linear infinite;
animation: backward 12s linear infinite;
}
.spinner-2 {
-webkit-transform: translateZ(105px) translateX(-181.86px) rotateY(15deg);
transform: translateZ(105px) translateX(-181.86px) rotateY(15deg);
}
.spinner-3 {
-webkit-transform: translateZ(105px) translateX(181.86px) rotateY(15deg);
transform: translateZ(105px) translateX(181.86px) rotateY(15deg);
}
.spinner-4 {
-webkit-transform: translateZ(315px) translateX(-181.86px);
transform: translateZ(315px) translateX(-181.86px);
}
.spinner-5 {
-webkit-transform: translateZ(315px) translateX(181.86px);
transform: translateZ(315px) translateX(181.86px);
}
.spinner-6 {
-webkit-transform: translateZ(420px) rotateY(15deg);
transform: translateZ(420px) rotateY(15deg);
}
.tooth-holder {
position: absolute;
left: -70px;
853
-webkit-transform-style: preserve-3d;
transform-style: preserve-3d;
}
.spinner-1 .tooth {
background: -webkit-linear-gradient(left, black 0%, #0b686f 0%, #14bfcc 66%);
background: linear-gradient(to right, black 0%, #0b686f 0%, #14bfcc 66%);
-webkit-animation: tooth-1 12s linear infinite;
animation: tooth-1 12s linear infinite;
}
@-webkit-keyframes tooth-1 {
50% {
-webkit-filter: brightness(40%);
filter: brightness(40%);
}
}
@keyframes tooth-1 {
50% {
-webkit-filter: brightness(40%);
filter: brightness(40%);
}
}
.spinner-2 .tooth {
background: -webkit-linear-gradient(left, black 0%, #99005c 0%, #ff0099 66%);
background: linear-gradient(to right, black 0%, #99005c 0%, #ff0099 66%);
-webkit-animation: tooth-2 12s linear infinite;
animation: tooth-2 12s linear infinite;
}
@-webkit-keyframes tooth-2 {
50% {
-webkit-filter: brightness(40%);
filter: brightness(40%);
}
}
@keyframes tooth-2 {
50% {
-webkit-filter: brightness(40%);
filter: brightness(40%);
}
}
.spinner-3 .tooth {
background: -webkit-linear-gradient(left, black 0%, #b29a00 0%, #ffe019 66%);
background: linear-gradient(to right, black 0%, #b29a00 0%, #ffe019 66%);
-webkit-animation: tooth-3 12s linear infinite;
animation: tooth-3 12s linear infinite;
}
@-webkit-keyframes tooth-3 {
50% {
-webkit-filter: brightness(40%);
filter: brightness(40%);
}
}
854
@keyframes tooth-3 {
50% {
-webkit-filter: brightness(40%);
filter: brightness(40%);
}
}
.tooth {
position: absolute;
width: 140px;
height: 70px;
border-bottom-right-radius: 35px;
border-top-right-radius: 35px;
}
.tooth-holder:nth-child(1) .tooth {
-webkit-transform: rotateY(30deg) translateX(70px);
transform: rotateY(30deg) translateX(70px);
}
.tooth-holder:nth-child(2) .tooth {
-webkit-transform: rotateY(60deg) translateX(70px);
transform: rotateY(60deg) translateX(70px);
}
.tooth-holder:nth-child(3) .tooth {
-webkit-transform: rotateY(90deg) translateX(70px);
transform: rotateY(90deg) translateX(70px);
}
.tooth-holder:nth-child(4) .tooth {
-webkit-transform: rotateY(120deg) translateX(70px);
transform: rotateY(120deg) translateX(70px);
}
.tooth-holder:nth-child(5) .tooth {
-webkit-transform: rotateY(150deg) translateX(70px);
transform: rotateY(150deg) translateX(70px);
}
.tooth-holder:nth-child(6) .tooth {
-webkit-transform: rotateY(180deg) translateX(70px);
transform: rotateY(180deg) translateX(70px);
}
.tooth-holder:nth-child(7) .tooth {
-webkit-transform: rotateY(210deg) translateX(70px);
transform: rotateY(210deg) translateX(70px);
}
.tooth-holder:nth-child(8) .tooth {
-webkit-transform: rotateY(240deg) translateX(70px);
transform: rotateY(240deg) translateX(70px);
}
.tooth-holder:nth-child(9) .tooth {
-webkit-transform: rotateY(270deg) translateX(70px);
transform: rotateY(270deg) translateX(70px);
}
855
.tooth-holder:nth-child(10) .tooth {
-webkit-transform: rotateY(300deg) translateX(70px);
transform: rotateY(300deg) translateX(70px);
}
.tooth-holder:nth-child(11) .tooth {
-webkit-transform: rotateY(330deg) translateX(70px);
transform: rotateY(330deg) translateX(70px);
}
.tooth-holder:nth-child(12) .tooth {
-webkit-transform: rotateY(360deg) translateX(70px);
transform: rotateY(360deg) translateX(70px);
}
856
.spinner-2 .tooth-holder:nth-child(3) .tooth,
.spinner-3 .tooth-holder:nth-child(3) .tooth, .spinner-6 .tooth-holder:nth-child(3) .tooth {
-webkit-transform: rotateY(90deg) translateX(70px);
transform: rotateY(90deg) translateX(70px);
-webkit-animation-delay: -6s;
animation-delay: -6s;
}
857
}
858
-webkit-animation-delay: -13s;
animation-delay: -13s;
}
<div class="field">
<div class="gear spinner-1">
<div class="turntable">
<div class="teeth">
<div class="tooth-holder">
<div class="tooth"></div>
</div>
<div class="tooth-holder">
<div class="tooth"></div>
</div>
<div class="tooth-holder">
859
<div class="tooth"></div>
</div>
<div class="tooth-holder">
<div class="tooth"></div>
</div>
<div class="tooth-holder">
<div class="tooth"></div>
</div>
<div class="tooth-holder">
<div class="tooth"></div>
</div>
<div class="tooth-holder">
<div class="tooth"></div>
</div>
<div class="tooth-holder">
<div class="tooth"></div>
</div>
<div class="tooth-holder">
<div class="tooth"></div>
</div>
<div class="tooth-holder">
<div class="tooth"></div>
</div>
<div class="tooth-holder">
<div class="tooth"></div>
</div>
<div class="tooth-holder">
<div class="tooth"></div>
</div>
</div>
</div>
</div>
<div class="gear spinner-2">
<div class="turntable">
<div class="teeth">
<div class="tooth-holder">
<div class="tooth"></div>
</div>
<div class="tooth-holder">
<div class="tooth"></div>
</div>
<div class="tooth-holder">
<div class="tooth"></div>
</div>
<div class="tooth-holder">
<div class="tooth"></div>
</div>
<div class="tooth-holder">
<div class="tooth"></div>
</div>
<div class="tooth-holder">
<div class="tooth"></div>
</div>
<div class="tooth-holder">
<div class="tooth"></div>
</div>
<div class="tooth-holder">
<div class="tooth"></div>
860
</div>
<div class="tooth-holder">
<div class="tooth"></div>
</div>
<div class="tooth-holder">
<div class="tooth"></div>
</div>
<div class="tooth-holder">
<div class="tooth"></div>
</div>
<div class="tooth-holder">
<div class="tooth"></div>
</div>
</div>
</div>
</div>
<div class="gear spinner-3">
<div class="turntable">
<div class="teeth">
<div class="tooth-holder">
<div class="tooth"></div>
</div>
<div class="tooth-holder">
<div class="tooth"></div>
</div>
<div class="tooth-holder">
<div class="tooth"></div>
</div>
<div class="tooth-holder">
<div class="tooth"></div>
</div>
<div class="tooth-holder">
<div class="tooth"></div>
</div>
<div class="tooth-holder">
<div class="tooth"></div>
</div>
<div class="tooth-holder">
<div class="tooth"></div>
</div>
<div class="tooth-holder">
<div class="tooth"></div>
</div>
<div class="tooth-holder">
<div class="tooth"></div>
</div>
<div class="tooth-holder">
<div class="tooth"></div>
</div>
<div class="tooth-holder">
<div class="tooth"></div>
</div>
<div class="tooth-holder">
<div class="tooth"></div>
</div>
</div>
</div>
</div>
861
</div>
*****************************************************************************
HTML PAGE
<style class="cp-pen-styles">
body {
background-color: #DBE2EC;
}
.container {
display: flex;
flex-wrap: wrap;
flex-direction: row;
}
.block {
width: 300px;
height: auto;
margin: 10% auto;
margin-left: 30px;
}
/* title block */
.title {
background-image: url('https://static.pexels.com/photos/110238/pexels-photo-110238-
large.jpeg');
background-size: cover;
background-repeat: no-repeat;
color: #fff;
}
.author {
font-size: 12px;
margin-top: 136px;
margin-left: 20px;
font-family: "Droid Sans Mono";
}
.post-title {
margin: 0 20px;
font-family:
}
.tag {
margin: 30px 20px;
padding: 8px 10px;
background: #fff;
border: none;
font-size: 12px;
font-family: "Droid Sans Mono";
}
.t-footer {
width 100%;
height: 40px;
background-color: #fff;
862
color: #000;
flex-direction: row;
}
.t-footer p {
padding: 13px 20px;
font-family: "Droid Sans Mono";
font-size: 11px;
}
.black {
color: #000;
margin-left: 70px;
}
span {
color: #BFC1C3;
}
.t-footer img {
width: 15px;
float: right;
}
.post-title {
font-family: Oswald;
}
/* text block */
.text {
background-color: #F8F9FA;
}
.text .black {
margin: 0;
}
.txt {
margin: 0 20px;
line-height: 1.5;
margin-top: 35px;
text-align: justify;
}
.text .t-footer {
margin-top: 164px;
}
.txt:first-letter {
font-size: 90px;
float: left;
margin: -24px 20px -20px 0;
}
863
/* comments block */
.comments {
background-color: #fff;
}
.top p {
font-family: "Droid Sans Mono";
font-weight: bold;
font-size: 13px;
margin-top: 20px;
margin-left: 90px;
}
.close {
color: #000;
float: right;
margin-right: 20px;
}
.comment-box img {
width: 57px;
float: left;
margin: 0 20px;
margin-top: 5px;
}
.name {
padding-top: 15px;
font-weight: bold;
}
.hour {
font-size: 11px;
margin-left: 3px;
}
.c-txt {
margin-left: 100px;
margin-right: 20px;
text-align: justify;
}</style></head><body>
<div class="container">
<div class="title block">
<h5 class="author">MARK MANSON</h3>
<h1 class="post-title">THE<br> DARK SIDE<br> OF THE DIGITAL NOMAD</h1>
<button class="tag"><a href="http://www.w3schools.com/html/"> Travel</a></button>
<div class="t-footer">
<p>CLOSE <span class="black">•</span> <span>• • •</span><img
src="https://cdn0.iconfinder.com/data/icons/thin-communication-messaging/57/thin-
036_bubble_comment_chat_message-512.png"></p>
</div>
</div>
<div class="text block">
<p class="txt">Arrhenius theory, theory, introduced in 1887 by the Swedish scientist Svante
Arrhenius, that acids are substances that dissociate in water to yield electrically charged atoms
or molecules, called ions, one of which is a hydrogen ion (H +), and that bases ionize in water
to yield hydroxide ions (OH −).
864
<div class="t-footer">
<p>CLOSE <span>• <span class="black">•</span> • •</span><img
src="https://cdn0.iconfinder.com/data/icons/thin-communication-messaging/57/thin-
036_bubble_comment_chat_message-512.png"></p>
</div>
</div>
<div class="comments block">
<div class="top"><p>COMMENTS (48) <span class="close">X</span<</p></div>
<div class="comment-box">
<img src="https://www.renault.com.br/etc/designs/renault_v2/5.4.1-65/common-
assets/img/avatar/avatar.png"><p class="name">jonathandunn <span class="hour">• 1 hours
ago</span></p>
<p class="c-txt">Lorem ipsum dolor sit amet, consectetur elit. </p>
<div class="comment-box">
<img src="https://www.renault.com.br/etc/designs/renault_v2/5.4.1-65/common-
assets/img/avatar/avatar.png"><p class="name">jonathandunn <span class="hour">• 1 hours
ago</span></p>
<p class="c-txt">Lorem ipsum dolor sit amet, consectetur elit. </p>
<div class="comment-box">
<img src="https://www.renault.com.br/etc/designs/renault_v2/5.4.1-65/common-
assets/img/avatar/avatar.png"><p class="name">jonathandunn <span class="hour">• 1 hours
ago</span></p>
<p class="c-txt">Lorem ipsum dolor sit amet, consectetur elit. </p>
<div class="comment-box">
<img src="https://www.renault.com.br/etc/designs/renault_v2/5.4.1-65/common-
assets/img/avatar/avatar.png"><p class="name">jonathandunn <span class="hour">• 1 hours
ago</span></p>
<p class="c-txt">Lorem ipsum dolor sit amet, consectetur elit. </p>
</div>
</div>
</div>
*****************************************************************************
Skewered Heading
<style class="cp-pen-styles">
body {
margin: 10% 5%;
text-align: center;
font-family: sans-serif;
color: #666;
}
h1 {
margin: 2em 0;
color: #00a99d;
}
p {
max-width: 30em;
margin: 2em auto;
}
h1 {
text-align: center;
865
overflow: hidden;
}
h1 span {
display: inline-block;
position: relative;
}
h1 span:before, h1 span:after {
content: "";
border-bottom: 2px solid #00a99d;
width: 3em;
margin: 0 1.5em;
position: absolute;
bottom: .5em;
}
h1 span:before {
right: 100%;
}
h1 span:after {
left: 100%;
}
</style></head><body>
<h1><span>Skewered Heading</span></h1>
<p>Skewer ends will be shown when space permits. Things don't get awkward if text wraps, the
effect just dissapears. No additional padding or margin is applied to the text so the effect
doesn't limit the natural width of the heading.</p>
<h1><span>Here is a Slightly Longer Skewered Heading</span></h1>
*****************************************************************************
HTML PAGE
<style class="cp-pen-styles">
:root {
font-size: calc(1vw + 1vh + .25vmin);
}
body {
background-image: url("http://www.highpayingaffiliateprograms.com/wp-
content/uploads/2013/02/software.png");
background-position: center center;
background-size: cover;
background-repeat: no-repeat;
background-attachment: fixed;
font: 1em/1 "Roboto", sans-serif;
margin: 5.5em;
}
.heading {
border-bottom: 1px solid #fff;
padding: 0 0 10px;;
width: 18.75em;
}
.heading h1 {
color: #fff;
line-height: 1.5;
margin: 0 0 .45em;
text-align: center;
}
866
.heading .logo {
text-align: center;
}
.heading .logo img {
margin: -3.0em 0 0;
width: 6.25em;
}
.split-border {
line-height: 0.5;
text-align: center;
}
.split-border span {
display: inline-block;
position: relative;
}
.split-border span:before,
.split-border span:after {
border-top: 1px solid #fff;
content: "";
position: absolute;
width: 5.625em;
}
.split-border span:before {
margin-right: 3.75em;
right: 100%;
}
.split-border span:after {
left: 100%;
margin-left: 3.75em;
}</style></head><body>
<div class="heading" role="banner">
<div class="split-border"><span></span></div>
<div class="logo">
<img src="http://www.littleblue.com/wp-content/uploads/2014/08/sales-block.png"
alt="salesforce logo image">
</div>
<h1>The World’s No. 1<br>CRM Solution</h1>
</div>
*****************************************************************************
<p style="width:80%;"> He is an Honorary Fellow of the Royal Society of Arts, a lifetime member
of the Pontifical Academy of Sciences, and a recipient of the Presidential Medal of Freedom, the
highest civilian award in the United States. Hawking was the Lucasian Professor of Mathematics at
the University of Cambridge between 1979 and 2009 and has achieved commercial success with works
of popular science in which he discusses his own theories and cosmology in general; his book A
Brief History of Time appeared on the British Sunday Times best-seller list for a record-breaking
237 weeks.</p>
*****************************************************************************
867
Fading text paragraph
<style class="cp-pen-styles">
body {
background: #f8fafc;
font-size: 20px;
font-family: "Crimson Text", serif;
color: 444;
}
h1 {
padding-top: 100px;
font-weight: 600;
}
h4 {
color: #666;
}
div.blur {
position: fixed;
width: 100%;
height: auto;
left: 0;
top: 0;
}
div.blur.bottom {
top: auto;
bottom: 0;
}
div.blur div {
width: 100%;
height: 1px;
}
div.blur div.itm_1 {
background: rgba(248, 250, 252, 0.99);
-webkit-backdrop-filter: blur(1.98px);
backdrop-filter: blur(1.98px);
}
div.blur div.itm_2 {
background: rgba(248, 250, 252, 0.98);
-webkit-backdrop-filter: blur(1.96px);
backdrop-filter: blur(1.96px);
}
div.blur div.itm_3 {
868
background: rgba(248, 250, 252, 0.97);
-webkit-backdrop-filter: blur(1.94px);
backdrop-filter: blur(1.94px);
}
div.blur div.itm_4 {
background: rgba(248, 250, 252, 0.96);
-webkit-backdrop-filter: blur(1.92px);
backdrop-filter: blur(1.92px);
}
div.blur div.itm_5 {
background: rgba(248, 250, 252, 0.95);
-webkit-backdrop-filter: blur(1.9px);
backdrop-filter: blur(1.9px);
}
div.blur div.itm_6 {
background: rgba(248, 250, 252, 0.94);
-webkit-backdrop-filter: blur(1.88px);
backdrop-filter: blur(1.88px);
}
div.blur div.itm_7 {
background: rgba(248, 250, 252, 0.93);
-webkit-backdrop-filter: blur(1.86px);
backdrop-filter: blur(1.86px);
}
div.blur div.itm_8 {
background: rgba(248, 250, 252, 0.92);
-webkit-backdrop-filter: blur(1.84px);
backdrop-filter: blur(1.84px);
}
div.blur div.itm_9 {
background: rgba(248, 250, 252, 0.91);
-webkit-backdrop-filter: blur(1.82px);
backdrop-filter: blur(1.82px);
}
div.blur div.itm_10 {
background: rgba(248, 250, 252, 0.9);
-webkit-backdrop-filter: blur(1.8px);
backdrop-filter: blur(1.8px);
}
div.blur div.itm_11 {
background: rgba(248, 250, 252, 0.89);
-webkit-backdrop-filter: blur(1.78px);
backdrop-filter: blur(1.78px);
}
div.blur div.itm_12 {
background: rgba(248, 250, 252, 0.88);
-webkit-backdrop-filter: blur(1.76px);
backdrop-filter: blur(1.76px);
}
869
div.blur div.itm_13 {
background: rgba(248, 250, 252, 0.87);
-webkit-backdrop-filter: blur(1.74px);
backdrop-filter: blur(1.74px);
}
div.blur div.itm_14 {
background: rgba(248, 250, 252, 0.86);
-webkit-backdrop-filter: blur(1.72px);
backdrop-filter: blur(1.72px);
}
div.blur div.itm_15 {
background: rgba(248, 250, 252, 0.85);
-webkit-backdrop-filter: blur(1.7px);
backdrop-filter: blur(1.7px);
}
div.blur div.itm_16 {
background: rgba(248, 250, 252, 0.84);
-webkit-backdrop-filter: blur(1.68px);
backdrop-filter: blur(1.68px);
}
div.blur div.itm_17 {
background: rgba(248, 250, 252, 0.83);
-webkit-backdrop-filter: blur(1.66px);
backdrop-filter: blur(1.66px);
}
div.blur div.itm_18 {
background: rgba(248, 250, 252, 0.82);
-webkit-backdrop-filter: blur(1.64px);
backdrop-filter: blur(1.64px);
}
div.blur div.itm_19 {
background: rgba(248, 250, 252, 0.81);
-webkit-backdrop-filter: blur(1.62px);
backdrop-filter: blur(1.62px);
}
div.blur div.itm_20 {
background: rgba(248, 250, 252, 0.8);
-webkit-backdrop-filter: blur(1.6px);
backdrop-filter: blur(1.6px);
}
div.blur div.itm_21 {
background: rgba(248, 250, 252, 0.79);
-webkit-backdrop-filter: blur(1.58px);
backdrop-filter: blur(1.58px);
}
div.blur div.itm_22 {
background: rgba(248, 250, 252, 0.78);
-webkit-backdrop-filter: blur(1.56px);
870
backdrop-filter: blur(1.56px);
}
div.blur div.itm_23 {
background: rgba(248, 250, 252, 0.77);
-webkit-backdrop-filter: blur(1.54px);
backdrop-filter: blur(1.54px);
}
div.blur div.itm_24 {
background: rgba(248, 250, 252, 0.76);
-webkit-backdrop-filter: blur(1.52px);
backdrop-filter: blur(1.52px);
}
div.blur div.itm_25 {
background: rgba(248, 250, 252, 0.75);
-webkit-backdrop-filter: blur(1.5px);
backdrop-filter: blur(1.5px);
}
div.blur div.itm_26 {
background: rgba(248, 250, 252, 0.74);
-webkit-backdrop-filter: blur(1.48px);
backdrop-filter: blur(1.48px);
}
div.blur div.itm_27 {
background: rgba(248, 250, 252, 0.73);
-webkit-backdrop-filter: blur(1.46px);
backdrop-filter: blur(1.46px);
}
div.blur div.itm_28 {
background: rgba(248, 250, 252, 0.72);
-webkit-backdrop-filter: blur(1.44px);
backdrop-filter: blur(1.44px);
}
div.blur div.itm_29 {
background: rgba(248, 250, 252, 0.71);
-webkit-backdrop-filter: blur(1.42px);
backdrop-filter: blur(1.42px);
}
div.blur div.itm_30 {
background: rgba(248, 250, 252, 0.7);
-webkit-backdrop-filter: blur(1.4px);
backdrop-filter: blur(1.4px);
}
div.blur div.itm_31 {
background: rgba(248, 250, 252, 0.69);
-webkit-backdrop-filter: blur(1.38px);
backdrop-filter: blur(1.38px);
}
div.blur div.itm_32 {
871
background: rgba(248, 250, 252, 0.68);
-webkit-backdrop-filter: blur(1.36px);
backdrop-filter: blur(1.36px);
}
div.blur div.itm_33 {
background: rgba(248, 250, 252, 0.67);
-webkit-backdrop-filter: blur(1.34px);
backdrop-filter: blur(1.34px);
}
div.blur div.itm_34 {
background: rgba(248, 250, 252, 0.66);
-webkit-backdrop-filter: blur(1.32px);
backdrop-filter: blur(1.32px);
}
div.blur div.itm_35 {
background: rgba(248, 250, 252, 0.65);
-webkit-backdrop-filter: blur(1.3px);
backdrop-filter: blur(1.3px);
}
div.blur div.itm_36 {
background: rgba(248, 250, 252, 0.64);
-webkit-backdrop-filter: blur(1.28px);
backdrop-filter: blur(1.28px);
}
div.blur div.itm_37 {
background: rgba(248, 250, 252, 0.63);
-webkit-backdrop-filter: blur(1.26px);
backdrop-filter: blur(1.26px);
}
div.blur div.itm_38 {
background: rgba(248, 250, 252, 0.62);
-webkit-backdrop-filter: blur(1.24px);
backdrop-filter: blur(1.24px);
}
div.blur div.itm_39 {
background: rgba(248, 250, 252, 0.61);
-webkit-backdrop-filter: blur(1.22px);
backdrop-filter: blur(1.22px);
}
div.blur div.itm_40 {
background: rgba(248, 250, 252, 0.6);
-webkit-backdrop-filter: blur(1.2px);
backdrop-filter: blur(1.2px);
}
div.blur div.itm_41 {
background: rgba(248, 250, 252, 0.59);
-webkit-backdrop-filter: blur(1.18px);
backdrop-filter: blur(1.18px);
}
872
div.blur div.itm_42 {
background: rgba(248, 250, 252, 0.58);
-webkit-backdrop-filter: blur(1.16px);
backdrop-filter: blur(1.16px);
}
div.blur div.itm_43 {
background: rgba(248, 250, 252, 0.57);
-webkit-backdrop-filter: blur(1.14px);
backdrop-filter: blur(1.14px);
}
div.blur div.itm_44 {
background: rgba(248, 250, 252, 0.56);
-webkit-backdrop-filter: blur(1.12px);
backdrop-filter: blur(1.12px);
}
div.blur div.itm_45 {
background: rgba(248, 250, 252, 0.55);
-webkit-backdrop-filter: blur(1.1px);
backdrop-filter: blur(1.1px);
}
div.blur div.itm_46 {
background: rgba(248, 250, 252, 0.54);
-webkit-backdrop-filter: blur(1.08px);
backdrop-filter: blur(1.08px);
}
div.blur div.itm_47 {
background: rgba(248, 250, 252, 0.53);
-webkit-backdrop-filter: blur(1.06px);
backdrop-filter: blur(1.06px);
}
div.blur div.itm_48 {
background: rgba(248, 250, 252, 0.52);
-webkit-backdrop-filter: blur(1.04px);
backdrop-filter: blur(1.04px);
}
div.blur div.itm_49 {
background: rgba(248, 250, 252, 0.51);
-webkit-backdrop-filter: blur(1.02px);
backdrop-filter: blur(1.02px);
}
div.blur div.itm_50 {
background: rgba(248, 250, 252, 0.5);
-webkit-backdrop-filter: blur(1px);
backdrop-filter: blur(1px);
}
div.blur div.itm_51 {
background: rgba(248, 250, 252, 0.49);
-webkit-backdrop-filter: blur(0.98px);
873
backdrop-filter: blur(0.98px);
}
div.blur div.itm_52 {
background: rgba(248, 250, 252, 0.48);
-webkit-backdrop-filter: blur(0.96px);
backdrop-filter: blur(0.96px);
}
div.blur div.itm_53 {
background: rgba(248, 250, 252, 0.47);
-webkit-backdrop-filter: blur(0.94px);
backdrop-filter: blur(0.94px);
}
div.blur div.itm_54 {
background: rgba(248, 250, 252, 0.46);
-webkit-backdrop-filter: blur(0.92px);
backdrop-filter: blur(0.92px);
}
div.blur div.itm_55 {
background: rgba(248, 250, 252, 0.45);
-webkit-backdrop-filter: blur(0.9px);
backdrop-filter: blur(0.9px);
}
div.blur div.itm_56 {
background: rgba(248, 250, 252, 0.44);
-webkit-backdrop-filter: blur(0.88px);
backdrop-filter: blur(0.88px);
}
div.blur div.itm_57 {
background: rgba(248, 250, 252, 0.43);
-webkit-backdrop-filter: blur(0.86px);
backdrop-filter: blur(0.86px);
}
div.blur div.itm_58 {
background: rgba(248, 250, 252, 0.42);
-webkit-backdrop-filter: blur(0.84px);
backdrop-filter: blur(0.84px);
}
div.blur div.itm_59 {
background: rgba(248, 250, 252, 0.41);
-webkit-backdrop-filter: blur(0.82px);
backdrop-filter: blur(0.82px);
}
div.blur div.itm_60 {
background: rgba(248, 250, 252, 0.4);
-webkit-backdrop-filter: blur(0.8px);
backdrop-filter: blur(0.8px);
}
div.blur div.itm_61 {
874
background: rgba(248, 250, 252, 0.39);
-webkit-backdrop-filter: blur(0.78px);
backdrop-filter: blur(0.78px);
}
div.blur div.itm_62 {
background: rgba(248, 250, 252, 0.38);
-webkit-backdrop-filter: blur(0.76px);
backdrop-filter: blur(0.76px);
}
div.blur div.itm_63 {
background: rgba(248, 250, 252, 0.37);
-webkit-backdrop-filter: blur(0.74px);
backdrop-filter: blur(0.74px);
}
div.blur div.itm_64 {
background: rgba(248, 250, 252, 0.36);
-webkit-backdrop-filter: blur(0.72px);
backdrop-filter: blur(0.72px);
}
div.blur div.itm_65 {
background: rgba(248, 250, 252, 0.35);
-webkit-backdrop-filter: blur(0.7px);
backdrop-filter: blur(0.7px);
}
div.blur div.itm_66 {
background: rgba(248, 250, 252, 0.34);
-webkit-backdrop-filter: blur(0.68px);
backdrop-filter: blur(0.68px);
}
div.blur div.itm_67 {
background: rgba(248, 250, 252, 0.33);
-webkit-backdrop-filter: blur(0.66px);
backdrop-filter: blur(0.66px);
}
div.blur div.itm_68 {
background: rgba(248, 250, 252, 0.32);
-webkit-backdrop-filter: blur(0.64px);
backdrop-filter: blur(0.64px);
}
div.blur div.itm_69 {
background: rgba(248, 250, 252, 0.31);
-webkit-backdrop-filter: blur(0.62px);
backdrop-filter: blur(0.62px);
}
div.blur div.itm_70 {
background: rgba(248, 250, 252, 0.3);
-webkit-backdrop-filter: blur(0.6px);
backdrop-filter: blur(0.6px);
}
875
div.blur div.itm_71 {
background: rgba(248, 250, 252, 0.29);
-webkit-backdrop-filter: blur(0.58px);
backdrop-filter: blur(0.58px);
}
div.blur div.itm_72 {
background: rgba(248, 250, 252, 0.28);
-webkit-backdrop-filter: blur(0.56px);
backdrop-filter: blur(0.56px);
}
div.blur div.itm_73 {
background: rgba(248, 250, 252, 0.27);
-webkit-backdrop-filter: blur(0.54px);
backdrop-filter: blur(0.54px);
}
div.blur div.itm_74 {
background: rgba(248, 250, 252, 0.26);
-webkit-backdrop-filter: blur(0.52px);
backdrop-filter: blur(0.52px);
}
div.blur div.itm_75 {
background: rgba(248, 250, 252, 0.25);
-webkit-backdrop-filter: blur(0.5px);
backdrop-filter: blur(0.5px);
}
div.blur div.itm_76 {
background: rgba(248, 250, 252, 0.24);
-webkit-backdrop-filter: blur(0.48px);
backdrop-filter: blur(0.48px);
}
div.blur div.itm_77 {
background: rgba(248, 250, 252, 0.23);
-webkit-backdrop-filter: blur(0.46px);
backdrop-filter: blur(0.46px);
}
div.blur div.itm_78 {
background: rgba(248, 250, 252, 0.22);
-webkit-backdrop-filter: blur(0.44px);
backdrop-filter: blur(0.44px);
}
div.blur div.itm_79 {
background: rgba(248, 250, 252, 0.21);
-webkit-backdrop-filter: blur(0.42px);
backdrop-filter: blur(0.42px);
}
div.blur div.itm_80 {
background: rgba(248, 250, 252, 0.2);
-webkit-backdrop-filter: blur(0.4px);
876
backdrop-filter: blur(0.4px);
}
div.blur div.itm_81 {
background: rgba(248, 250, 252, 0.19);
-webkit-backdrop-filter: blur(0.38px);
backdrop-filter: blur(0.38px);
}
div.blur div.itm_82 {
background: rgba(248, 250, 252, 0.18);
-webkit-backdrop-filter: blur(0.36px);
backdrop-filter: blur(0.36px);
}
div.blur div.itm_83 {
background: rgba(248, 250, 252, 0.17);
-webkit-backdrop-filter: blur(0.34px);
backdrop-filter: blur(0.34px);
}
div.blur div.itm_84 {
background: rgba(248, 250, 252, 0.16);
-webkit-backdrop-filter: blur(0.32px);
backdrop-filter: blur(0.32px);
}
div.blur div.itm_85 {
background: rgba(248, 250, 252, 0.15);
-webkit-backdrop-filter: blur(0.3px);
backdrop-filter: blur(0.3px);
}
div.blur div.itm_86 {
background: rgba(248, 250, 252, 0.14);
-webkit-backdrop-filter: blur(0.28px);
backdrop-filter: blur(0.28px);
}
div.blur div.itm_87 {
background: rgba(248, 250, 252, 0.13);
-webkit-backdrop-filter: blur(0.26px);
backdrop-filter: blur(0.26px);
}
div.blur div.itm_88 {
background: rgba(248, 250, 252, 0.12);
-webkit-backdrop-filter: blur(0.24px);
backdrop-filter: blur(0.24px);
}
div.blur div.itm_89 {
background: rgba(248, 250, 252, 0.11);
-webkit-backdrop-filter: blur(0.22px);
backdrop-filter: blur(0.22px);
}
div.blur div.itm_90 {
877
background: rgba(248, 250, 252, 0.1);
-webkit-backdrop-filter: blur(0.2px);
backdrop-filter: blur(0.2px);
}
div.blur div.itm_91 {
background: rgba(248, 250, 252, 0.09);
-webkit-backdrop-filter: blur(0.18px);
backdrop-filter: blur(0.18px);
}
div.blur div.itm_92 {
background: rgba(248, 250, 252, 0.08);
-webkit-backdrop-filter: blur(0.16px);
backdrop-filter: blur(0.16px);
}
div.blur div.itm_93 {
background: rgba(248, 250, 252, 0.07);
-webkit-backdrop-filter: blur(0.14px);
backdrop-filter: blur(0.14px);
}
div.blur div.itm_94 {
background: rgba(248, 250, 252, 0.06);
-webkit-backdrop-filter: blur(0.12px);
backdrop-filter: blur(0.12px);
}
div.blur div.itm_95 {
background: rgba(248, 250, 252, 0.05);
-webkit-backdrop-filter: blur(0.1px);
backdrop-filter: blur(0.1px);
}
div.blur div.itm_96 {
background: rgba(248, 250, 252, 0.04);
-webkit-backdrop-filter: blur(0.08px);
backdrop-filter: blur(0.08px);
}
div.blur div.itm_97 {
background: rgba(248, 250, 252, 0.03);
-webkit-backdrop-filter: blur(0.06px);
backdrop-filter: blur(0.06px);
}
div.blur div.itm_98 {
background: rgba(248, 250, 252, 0.02);
-webkit-backdrop-filter: blur(0.04px);
backdrop-filter: blur(0.04px);
}
div.blur div.itm_99 {
background: rgba(248, 250, 252, 0.01);
-webkit-backdrop-filter: blur(0.02px);
backdrop-filter: blur(0.02px);
}
878
div.blur div.itm_100 {
background: rgba(248, 250, 252, 0);
-webkit-backdrop-filter: blur(0px);
backdrop-filter: blur(0px);
}
</style></head><body>
879
<div class="itm_50"></div>
<div class="itm_51"></div>
<div class="itm_52"></div>
<div class="itm_53"></div>
<div class="itm_54"></div>
<div class="itm_55"></div>
<div class="itm_56"></div>
<div class="itm_57"></div>
<div class="itm_58"></div>
<div class="itm_59"></div>
<div class="itm_60"></div>
<div class="itm_61"></div>
<div class="itm_62"></div>
<div class="itm_63"></div>
<div class="itm_64"></div>
<div class="itm_65"></div>
<div class="itm_66"></div>
<div class="itm_67"></div>
<div class="itm_68"></div>
<div class="itm_69"></div>
<div class="itm_70"></div>
<div class="itm_71"></div>
<div class="itm_72"></div>
<div class="itm_73"></div>
<div class="itm_74"></div>
<div class="itm_75"></div>
<div class="itm_76"></div>
<div class="itm_77"></div>
<div class="itm_78"></div>
<div class="itm_79"></div>
<div class="itm_80"></div>
<div class="itm_81"></div>
<div class="itm_82"></div>
<div class="itm_83"></div>
<div class="itm_84"></div>
<div class="itm_85"></div>
<div class="itm_86"></div>
<div class="itm_87"></div>
<div class="itm_88"></div>
<div class="itm_89"></div>
<div class="itm_90"></div>
<div class="itm_91"></div>
<div class="itm_92"></div>
<div class="itm_93"></div>
<div class="itm_94"></div>
<div class="itm_95"></div>
<div class="itm_96"></div>
<div class="itm_97"></div>
<div class="itm_98"></div>
<div class="itm_99"></div>
<div class="itm_100"></div>
</div>
<h1>Stephen Hawking</h1>
<h4>From Wikipedia, the free encyclopedia</h4>
880
<h3>Stephen William Hawking, CH, CBE, FRS, FRSA (Listeni/ˈstiːvən ˈhɔːkɪŋ/; born 8 January 1942)
is an English theoretical physicist, cosmologist, author and Director of Research at the Centre
for Theoretical Cosmology within the University of Cambridge.[16][17] His scientific works
include a collaboration with Roger Penrose on gravitational singularity theorems in the framework
of general relativity, and the theoretical prediction that black holes emit radiation, often
called Hawking radiation. Hawking was the first to set forth a theory of cosmology explained by a
union of the general theory of relativity and quantum mechanics. He is a vigorous supporter of
the many-worlds interpretation of quantum mechanics</h3>
<p align="left"> He is an Honorary Fellow of the Royal Society of Arts, a lifetime member of the
Pontifical Academy of Sciences, and a recipient of the Presidential Medal of Freedom, the highest
civilian award in the United States.
Hawking was the Lucasian Professor of Mathematics at the University of Cambridge between 1979 and
2009 and has achieved commercial success with works of popular science in which he discusses his
own theories and cosmology in general; his book A Brief History of Time appeared on the British
Sunday Times best-seller list for a record-breaking 237 weeks.</p>
<p>Hawking has a rare early-onset, slow-progressing form of amyotrophic lateral sclerosis (ALS),
commonly known as motor neurone disease in the UK, that has gradually paralysed him over the
decades.[20][21] He now communicates using a single cheek muscle attached to a speech-generating
device.</p>
<p>Hawking was born on 8 January 1942[22] in Oxford, England, to Frank (1905–1986) and Isobel
Hawking (née Walker; 1915–2013).[23][24] His mother was Scottish.[25] Despite their families'
financial constraints, both parents attended the University of Oxford, where Frank studied
medicine and Isobel, Philosophy, Politics and Economics.[24] The two met shortly after the
beginning of the Second World War at a medical research institute where she was working as a
secretary and he as a medical researcher.[24][26] They lived in Highgate, but as London was being
bombed in those years, Isobel went to Oxford to give birth in greater safety.[27] Hawking has two
younger sisters, Philippa and Mary, and an adopted brother, Edward.[28].</p>
<p>In 1950, when his father became head of the division of parasitology at the National Institute
for Medical Research, Hawking and his family moved to St Albans, Hertfordshire.[29][30] In St
Albans, the family were considered highly intelligent and somewhat eccentric;[29][31] meals were
often spent with each person silently reading a book.[29] They lived a frugal existence in a
large, cluttered, and poorly maintained house, and travelled in a converted London
taxicab.[32][33] During one of Hawking's father's frequent absences working in Africa,[34] the
rest of the family spent four months in Majorca visiting his mother's friend Beryl and her
husband, the poet Robert Graves.</p>
<p>Hawking began his schooling at the Byron House School; he later blamed its "progressive
methods" for his failure to learn to read while at the school.[29] In St Albans, the eight-year-
old Hawking attended St Albans High School for Girls for a few months; at that time, younger boys
could attend one of the houses.</p>
<p> </p>
<p> </p>
<div class="blur bottom">
<div class="itm_100"></div>
<div class="itm_99"></div>
<div class="itm_98"></div>
881
<div class="itm_97"></div>
<div class="itm_96"></div>
<div class="itm_95"></div>
<div class="itm_94"></div>
<div class="itm_93"></div>
<div class="itm_92"></div>
<div class="itm_91"></div>
<div class="itm_90"></div>
<div class="itm_89"></div>
<div class="itm_88"></div>
<div class="itm_87"></div>
<div class="itm_86"></div>
<div class="itm_85"></div>
<div class="itm_84"></div>
<div class="itm_83"></div>
<div class="itm_82"></div>
<div class="itm_81"></div>
<div class="itm_80"></div>
<div class="itm_79"></div>
<div class="itm_78"></div>
<div class="itm_77"></div>
<div class="itm_76"></div>
<div class="itm_75"></div>
<div class="itm_74"></div>
<div class="itm_73"></div>
<div class="itm_72"></div>
<div class="itm_71"></div>
<div class="itm_70"></div>
<div class="itm_69"></div>
<div class="itm_68"></div>
<div class="itm_67"></div>
<div class="itm_66"></div>
<div class="itm_65"></div>
<div class="itm_64"></div>
<div class="itm_63"></div>
<div class="itm_62"></div>
<div class="itm_61"></div>
<div class="itm_60"></div>
<div class="itm_59"></div>
<div class="itm_58"></div>
<div class="itm_57"></div>
<div class="itm_56"></div>
<div class="itm_55"></div>
<div class="itm_54"></div>
<div class="itm_53"></div>
<div class="itm_52"></div>
<div class="itm_51"></div>
<div class="itm_50"></div>
<div class="itm_49"></div>
<div class="itm_48"></div>
<div class="itm_47"></div>
<div class="itm_46"></div>
<div class="itm_45"></div>
<div class="itm_44"></div>
<div class="itm_43"></div>
<div class="itm_42"></div>
<div class="itm_41"></div>
<div class="itm_40"></div>
882
<div class="itm_39"></div>
<div class="itm_38"></div>
<div class="itm_37"></div>
<div class="itm_36"></div>
<div class="itm_35"></div>
<div class="itm_34"></div>
<div class="itm_33"></div>
<div class="itm_32"></div>
<div class="itm_31"></div>
<div class="itm_30"></div>
<div class="itm_29"></div>
<div class="itm_28"></div>
<div class="itm_27"></div>
<div class="itm_26"></div>
<div class="itm_25"></div>
<div class="itm_24"></div>
<div class="itm_23"></div>
<div class="itm_22"></div>
<div class="itm_21"></div>
<div class="itm_20"></div>
<div class="itm_19"></div>
<div class="itm_18"></div>
<div class="itm_17"></div>
<div class="itm_16"></div>
<div class="itm_15"></div>
<div class="itm_14"></div>
<div class="itm_13"></div>
<div class="itm_12"></div>
<div class="itm_11"></div>
<div class="itm_10"></div>
<div class="itm_9"></div>
<div class="itm_8"></div>
<div class="itm_7"></div>
<div class="itm_6"></div>
<div class="itm_5"></div>
<div class="itm_4"></div>
<div class="itm_3"></div>
<div class="itm_2"></div>
<div class="itm_1"></div>
</div>
*****************************************************************************
<style class="cp-pen-styles">
@import
url(http://fonts.googleapis.com/css?family=Playfair+Display:400,700,900,400italic,700italic,900it
alic);
.wrapper {
margin: 50px auto;
display: block;
width: 600px;
font-family: 'Playfair Display', serif;
883
font-size: 36px;
color: saddlebrown;
}
p {
width: 600px;
margin: 50px auto;
}
span {
display: block;
line-height: 100%;
}
.are-you-kidding {
font-size: 68px;
font-weight: 900;
margin-bottom: 30px;
text-align: right;
color: darkseagreen;
}
.crudely {
text-transform: uppercase;
letter-spacing: 0.25em;
font-weight: 700;
font-size: 30px;
margin: 10px 0;
color: lightseagreen;
clear: both;
}
.that-guy, .wrapped {
font-size: 30px;
float: left;
margin-top: 10px;
margin-right: 10px;
}
.wrapped {
padding-left: 170px;
}
.wrapped, .enigma {
display: inline-block;
float: left;
margin-bottom: 15px;
}
884
.mystery, .enigma {
text-transform: uppercase;
letter-spacing: 0.05em;
font-weight: 900;
font-size: 50px;
color: teal;
}
.mystery {
color: burlywood;
}
.bleep {
-webkit-transform: rotate(-6deg);
transform: rotate(-6deg);
background: antiquewhite;
padding: 5px 5px 5px 10px;
color: rgb(255, 155, 0);
font-weight: 800;
letter-spacing: 0.15em;
margin-right: -10px;
font-size: 34px;
}
.time-bomb {
font-weight: 900;
font-size: 70px;
font-style: italic;
text-align: right;
margin-bottom: 50px;
color: tomato;
}
.he-was-either, .going-to {
margin-left: 120px;
font-style: italic;
font-size: 45px;
color: darkmagenta;
}
.hit {
font-style: italic;
font-weight: 700;
font-size: 80px;
margin-top: -15px;
color: indigo;
}
.blog {
885
font-size: 40px;
text-transform: uppercase;
letter-spacing: 0.15em;
color: navy;
}
cite {
font-style: initial;
font-size: 24px;
}</style></head><body>
<div class="wrapper">
<p>
<span class="are-you-kidding">
“Science is a way of life.
</span>
<span class="that-guy">
Science is a perspective.
</span>
<span class="mystery">
mystery
</span>
<span class="wrapped">
wrapped in an
</span>
<span class="enigma">
enigma
</span>
<span class="crudely">
and crudely stapled
</span>
<span class="to-a">
to a
<span class="ticking">
ticking
</span>
<span class="bleep">
&%$?
</span>
<span class="ing">
ing
</span>
<span class="time-bomb">
time bomb.
</span>
<span class="he-was-either">
it is either
</span>
<span class="going-to">
going to
</span>
<span class="hit">
hit market
</span>
<span class="blog">
or start a new opening.”
</span>
</p>
886
<cite>
—Dr.Science,
<em>The Magic world</em>
</cite>
</div>
*****************************************************************************
<style class="cp-pen-styles">
@import 'https://fonts.googleapis.com/css?family=Lora:400,700';
* {
box-sizing: border-box;
}
html, body {
font-family: 'Lora', serif;
width: 100%;
height: 100%;
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-box-align: center;
-webkit-align-items: center;
-ms-flex-align: center;
align-items: center;
-webkit-box-pack: center;
-webkit-justify-content: center;
-ms-flex-pack: center;
justify-content: center;
}
body {
border: 8px solid #00B388;
}
a {
cursor: pointer;
}
strong {
margin-top: 16px;
display: block;
font-weight: 700;
}
p {
padding: 24px;
max-width: 760px;
font-size: 22px;
887
font-weight: 300;
line-height: 1.9;
}
.link-1 {
position: relative;
text-decoration: none;
display: inline-block;
color: black;
padding: 0 1px;
-webkit-transition: color ease 0.3s;
transition: color ease 0.3s;
}
.link-1::after {
content: '';
position: absolute;
z-index: -1;
width: 100%;
height: 5%;
left: 0;
bottom: 0;
background-color: #00B388;
-webkit-transition: all ease 0.3s;
transition: all ease 0.3s;
}
.link-1:hover {
color: white;
}
.link-1:hover::after {
height: 100%;
}
.link-2 {
position: relative;
text-decoration: none;
display: inline-block;
color: black;
padding: 0 1px;
-webkit-transition: color ease 0.3s;
transition: color ease 0.3s;
.link-2::before, .link-2::after {
content: '';
position: absolute;
background-color: #00B388;
z-index: -1;
height: 5%;
}
.link-2::before {
width: 0%;
left: 0;
bottom: 0;
888
-webkit-transition: width ease 0.4s;
transition: width ease 0.4s;
}
.link-2::after {
width: 100%;
left: 0;
bottom: 0;
-webkit-transition: all ease 0.6s;
transition: all ease 0.6s;
}
.link-2:hover::before {
width: 100%;
}
.link-2:hover::after {
left: 100%;
width: 0%;
-webkit-transition: all ease 0.2s;
transition: all ease 0.2s;
}
</style></head><body>
<p>
"Attractive things make people feel good, which in turn makes them think more</a> <a
class="link-1"
href="http://www.w3schools.com/html/tryit.asp?filename=tryhtml_default">creatively</a>. How does
that make something easier to use? Simple, by making it easier for <a class="link-
2"href="http://www.w3schools.com/html/tryit.asp?filename=tryhtml_default">people</a> to find
solutions to the problems they encounter." <strong>- Don Norman</strong>
</p>
*****************************************************************************
<style class="cp-pen-styles">
.content-block {
background-color:#f09;
box-sizing:border-box;
color:#fff;
font-size:5vmin;
height:50vmin;
margin:25vmin;
overflow:hidden;
padding:5vmin;
position:relative;
width:50vmin;
}
.bite {
background-color:#fff;
border-radius:50%;
box-sizing:border-box;
height:70%;
889
position:absolute;
transition:all 1s ease;
width:70%;
}
.br {
bottom:-20%;
right:-20%;
}
.tr {
right:-20%;
top:-20%;
}
.bl {
bottom:-20%;
left:-20%;
}
.tl {
left:-20%;
top:-20%;
}
.center {
bottom:10%;
left:10%;
right:10%;
top:10%;
}
.tooth {
background-color:#fff;
border-radius: 50%;
height: 40px;
position: absolute;
width: 40px;
}
.biter {
background-color:#09f;
border:0;
bottom:20px;
color:#fff;
font-size:5vmin;
padding:1em;
position:fixed;
right:20px;
}
.biter:hover {
opacity:.8;
}
.biter:disabled,
.biter:disabled:hover {
background-color:#ccc;
890
}</style></head><body>
<div class="content-block">The true sign of intelligence is not knowledge but imagination.
</div>
<script>
"use strict";"object"!=typeof
window.CP&&(window.CP={}),window.CP.PenTimer={programNoLongerBeingMonitored:!1,timeOfFirstCallToS
houldStopLoop:0,_loopExits:{},_loopTimers:{},START_MONITORING_AFTER:2e3,STOP_ALL_MONITORING_TIMEO
UT:5e3,MAX_TIME_IN_LOOP_WO_EXIT:2200,exitedLoop:function(o){this._loopExits[o]=!0},shouldStopLoop
:function(o){if(this.programKilledSoStopMonitoring)return!0;if(this.programNoLongerBeingMonitored
)return!1;if(this._loopExits[o])return!1;var
t=this._getTime();if(0===this.timeOfFirstCallToShouldStopLoop)return
this.timeOfFirstCallToShouldStopLoop=t,!1;var i=t-
this.timeOfFirstCallToShouldStopLoop;if(i<this.START_MONITORING_AFTER)return!1;if(i>this.STOP_ALL
_MONITORING_TIMEOUT)return
this.programNoLongerBeingMonitored=!0,!1;try{this._checkOnInfiniteLoop(o,t)}catch(n){return
this._sendErrorMessageToEditor(),this.programKilledSoStopMonitoring=!0,!0}return!1},_sendErrorMes
sageToEditor:function(){try{if(this._shouldPostMessage()){var o={action:"infinite-
loop",line:this._findAroundLineNumber()};parent.postMessage(JSON.stringify(o),"*")}else
this._throwAnErrorToStopPen()}catch(t){this._throwAnErrorToStopPen()}},_shouldPostMessage:functio
n(){return document.location.href.match(/boomerang/)},_throwAnErrorToStopPen:function(){throw"We
found an infinite loop in your Pen. We've stopped the Pen from running. Please correct it or
contact [email protected]."},_findAroundLineNumber:function(){var o=new
Error,t=0;if(o.stack){var i=o.stack.match(/boomerang\S+:(\d+):\d+/);i&&(t=i[1])}return
t},_checkOnInfiniteLoop:function(o,t){if(!this._loopTimers[o])return this._loopTimers[o]=t,!1;var
i=t-this._loopTimers[o];if(i>this.MAX_TIME_IN_LOOP_WO_EXIT)throw"Infinite Loop found on loop:
"+o},_getTime:function(){return+new Date}},window.CP.shouldStopExecution=function(o){var
t=window.CP.PenTimer.shouldStopLoop(o);return t===!0&&console.warn("An infinite loop (or loop
taking too long) was detected, so we stopped its execution.
Sorry!"),t},window.CP.exitedLoop=function(o){window.CP.PenTimer.exitedLoop(o)};
</script>
<script>var cb = document.querySelector('.content-block');
var btn = document.querySelector('.biter');
var biteCount = 0;
function addTeeth(bite) {
var teeth = 18;
var angle = 360 / teeth;
var radius = 80;
var offsetToParentCenter = parseInt(bite.offsetWidth / 2);
var offsetToChildCenter = -60;
var totalOffset = offsetToParentCenter - offsetToChildCenter;
for (var i = 1; i <= teeth; ++i) {
if (window.CP.shouldStopExecution(1)) {
break;
}
var tooth = document.createElement('div');
tooth.className = 'tooth';
var y = Math.sin(angle * i * (Math.PI / 180)) * radius;
var x = Math.cos(angle * i * (Math.PI / 180)) * radius;
891
tooth.style.top = (y + totalOffset).toString() + 'px';
tooth.style.left = (x + totalOffset).toString() + 'px';
bite.appendChild(tooth);
}
window.CP.exitedLoop(1);
}
function bite() {
if (biteCount > 4)
return;
var b = document.createElement('div');
addTeeth(b);
b.className = 'bite';
switch (biteCount) {
case 0:
b.className += ' br';
break;
case 1:
b.className += ' bl';
break;
case 2:
b.className += ' tr';
break;
case 3:
b.className += ' tl';
break;
case 4:
b.className += ' center';
cb.parentNode.removeChild(cb);
btn.textContent = 'All gone';
btn.disabled = true;
}
cb.appendChild(b);
biteCount++;
}
</script>
*****************************************************************************
Card
<style>
*,
*:before,
*:after {
box-sizing: border-box;
}
.container {
max-width: 400px;
width: 100%;
margin: 0 auto;
padding-bottom: 70px;
position: relative;
}
892
.intro {
position: relative;
min-height: 300px;
height: 100%;
width: 100%;
background: transparent url(http://quotesblog.net/wp-content/uploads/2015/05/Albert-Einstein-
Quotes-8.jpg) top center no-repeat;
background-size: 100%;
overflow: hidden;
transition: all .72s ease-in-out;
}
.intro:after {
content: '';
display: block;
position: absolute;
/* width: 100%; */
height: 500px;
right: -100%;
left: 0;
transform: skew(100deg);
background: #fff;
bottom: -70%;
box-shadow: inset 1px 0px 5px 0px rgba(204, 204, 204, 0.72);
}
.container:after {
content: '';
max-width: 300px;
width: 100%;
margin: 0% auto 0;
position: absolute;
left: 0;
bottom: 0;
top:0;
right: 0;
box-shadow: 0px 5px 5px 0px rgba(204, 204, 204, 0.72);
z-index: -1;
transition: all .52s ease-in-out;
}
.meta {
max-width: 300px;
width: 100%;
margin: 0% auto 0;
position: absolute;
left: 0;
bottom: 0;
right: 0;
z-index: 10;
padding-top: 110px;
overflow: hidden;
.meta__inner {
893
padding: .25rem 1rem;
line-height: 1.5rem;
position: relative;
background: #fff;
z-index: 15;
background: #fff;
border: 1px solid #ccc;
border-top: none;
}
.meta:after {
content: '';
display: block;
position: absolute;
left:0;
right: 0;
top: 80px;
max-width: 300px;
height: 300px;
background: #fff;
border: 1px solid #ccc;
transform: rotate(90deg) skew(10deg);
z-index: 4;
}
h3 {
position: relative;
font-family: sans-serif;
font-weight: 300;
border-left: 4px solid #e91e63;
padding-left: .72rem;
}
p {
font-family: serif;
font-size: .85rem;
font-weight: inherit;
color: #555;
text-align: justify;
}
p a {
color: #e91e63;
text-decoration: none;
opacity: .72;
p a:hover {
opacity: 1;
text-decoration: underline;
}
.container:hover .meta{
transform: translateY(5px);
}
.container:hover .intro {
894
transform: translateY(-5px);
}
.container:hover:after {
transform: translateY(5px);
}
</style>
<div class="container">
<section class="intro"></section>
<div class="meta">
<div class="meta__inner">
<h3>Some Title</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Illo fugiat ad quae amet
dignissimos laborum, repellat maxime ipsa ipsam nisi <a href="#">read more ...</a></p>
</div>
</div>
</div>
*****************************************************************************
body {
background: #FFFFFF;
font-family: courier, serif;
text-align: center;
-webkit-font-smoothing: antialiased;
}
.hello {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
top: 25%;
}
.hello h3 {
position: relative;
color: #152860;
text-align: center;
white-space: nowrap;
font-size: 40px;
letter-spacing: 0.0625em;
width: calc(20ch + 20*0.0625em);
895
}
.hello h3:after {
display: block;
position: absolute;
content: '';
width: calc(20ch + 20*0.0625em);
height: 2ex;
left: 0;
top: 0;
background: #eff5ed;
animation: 0.6s blink 20, move 3s 1.5s forwards steps(1);
border-left: 1px solid #152860;
box-shadow: 0px 1ex 0px 0px #eff5ed;
}
@keyframes move {
5% {
width: calc(calc(20ch + 20*0.0625em) - (1ch + 1*0.0625em));
left: calc(1ch + 1*0.0625em);
}
10% {
width: calc(calc(20ch + 20*0.0625em) - (2ch + 2*0.0625em));
left: calc(2ch + 2*0.0625em);
}
15% {
width: calc(calc(20ch + 20*0.0625em) - (3ch + 3*0.0625em));
left: calc(3ch + 3*0.0625em);
}
20% {
width: calc(calc(20ch + 20*0.0625em) - (4ch + 4*0.0625em));
left: calc(4ch + 4*0.0625em);
}
25% {
width: calc(calc(20ch + 20*0.0625em) - (5ch + 5*0.0625em));
left: calc(5ch + 5*0.0625em);
}
30% {
width: calc(calc(20ch + 20*0.0625em) - (6ch + 6*0.0625em));
left: calc(6ch + 6*0.0625em);
}
35% {
width: calc(calc(20ch + 20*0.0625em) - (7ch + 7*0.0625em));
left: calc(7ch + 7*0.0625em);
}
40% {
width: calc(calc(20ch + 20*0.0625em) - (8ch + 8*0.0625em));
left: calc(8ch + 8*0.0625em);
}
45% {
width: calc(calc(20ch + 20*0.0625em) - (9ch + 9*0.0625em));
left: calc(9ch + 9*0.0625em);
}
50% {
width: calc(calc(20ch + 20*0.0625em) - (10ch + 10*0.0625em));
left: calc(10ch + 10*0.0625em);
}
55% {
width: calc(calc(20ch + 20*0.0625em) - (11ch + 11*0.0625em));
left: calc(11ch + 11*0.0625em);
896
}
60% {
width: calc(calc(20ch + 20*0.0625em) - (12ch + 12*0.0625em));
left: calc(12ch + 12*0.0625em);
}
65% {
width: calc(calc(20ch + 20*0.0625em) - (13ch + 13*0.0625em));
left: calc(13ch + 13*0.0625em);
}
70% {
width: calc(calc(20ch + 20*0.0625em) - (14ch + 14*0.0625em));
left: calc(14ch + 14*0.0625em);
}
75% {
width: calc(calc(20ch + 20*0.0625em) - (15ch + 15*0.0625em));
left: calc(15ch + 15*0.0625em);
}
80% {
width: calc(calc(20ch + 20*0.0625em) - (16ch + 16*0.0625em));
left: calc(16ch + 16*0.0625em);
}
85% {
width: calc(calc(20ch + 20*0.0625em) - (17ch + 17*0.0625em));
left: calc(17ch + 17*0.0625em);
}
90% {
width: calc(calc(20ch + 20*0.0625em) - (18ch + 18*0.0625em));
left: calc(18ch + 18*0.0625em);
}
95% {
width: calc(calc(20ch + 20*0.0625em) - (19ch + 19*0.0625em));
left: calc(19ch + 19*0.0625em);
}
100% {
width: calc(calc(20ch + 20*0.0625em) - (20ch + 20*0.0625em));
left: calc(20ch + 20*0.0625em);
}
}
@keyframes blink {
0% {
border-left-color: #152860;
}
50% {
border-left-color: #152860;
}
51% {
border-left-color: #eff5ed;
}
100% {
border-left-color: #eff5ed;
}
}
</style></head><body>
<div class="hello">
<h3>Albert Einstein</h3>
</div>
897
*****************************************************************************
Image Hover
<style class="cp-pen-styles">
@import url(https://fonts.googleapis.com/css?family=Slabo+27px);
@import url(https://fonts.googleapis.com/css?family=Lato);
.snip1523 {
font-family: 'Lato', sans-serif;
position: relative;
float: left;
overflow: hidden;
margin: 10px 1%;
min-width: 230px;
max-width: 315px;
width: 100%;
color: #ffffff;
text-align: left;
font-size: 16px;
background-color: #1A1A1A;
}
.snip1523 * {
-webkit-box-sizing: border-box;
box-sizing: border-box;
-webkit-transition: all 0.45s ease;
transition: all 0.45s ease;
}
.snip1523 img {
vertical-align: top;
max-width: 100%;
backface-visibility: hidden;
}
.snip1523 figcaption {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
z-index: 1;
padding: 30px;
background-color: #202123;
-webkit-transform: translateX(100%);
transform: translateX(100%);
-webkit-box-shadow: 0 0 50px rgba(0, 0, 0, 0.5);
box-shadow: 0 0 50px rgba(0, 0, 0, 0.5);
}
.snip1523 h2,
.snip1523 h3,
.snip1523 p {
margin: 0;
}
898
.snip1523 h2,
.snip1523 h3 {
font-family: 'Slabo 27px', serif;
line-height: 1.2em;
}
.snip1523 h2 {
font-size: 1.9em;
color: #35ADF9;
}
.snip1523 h3 {
color: #EBEBEB;
font-size: 1.3em;
font-weight: normal;
letter-spacing: 1px;
}
.snip1523 p {
border-top: 1px solid rgba(255, 255, 255, 0.2);
font-size: 0.9em;
margin-top: 12px;
padding: 12px 0 15px;
line-height: 1.5em;
}
.snip1523 a {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
z-index: 1;
}
.snip1523:hover figcaption,
.snip1523.hover figcaption {
-webkit-transform: translateX(0%);
transform: translateX(0%);
}
body {
background-color: #212121;
}</style></head><body>
<figure class="snip1523">
<img src="https://pbs.twimg.com/profile_images/661244915725287424/C7vPnSSE.jpg" alt="sample85"
/>
<figcaption>
<h2>Benjamin Evalent</h2>
899
<h3>UX Design</h3>
<p>I'm learning real skills that I can apply throughout the rest of my life ...
Procrastinating and rationalizing.</p>
</figcaption>
<a href="http://www.w3schools.com/html/tryit.asp?filename=tryhtml_default"></a>
</figure>
<figure class="snip1523 hover">
<img src="https://pbs.twimg.com/profile_images/661244915725287424/C7vPnSSE.jpg" alt="sample99"/>
<figcaption>
<h2>Sheq Bivouac</h2>
<h3>Accountant</h3>
<p>If you do the job badly enough, sometimes you don't get asked to do it again.</p>
</figcaption>
<a href="http://www.w3schools.com/html/tryit.asp?filename=tryhtml_default"></a>
</figure>
<figure class="snip1523"><img src="http://3.bp.blogspot.com/_923ogQ0alTo/TIMvmD-
tdvI/AAAAAAAAAfw/WjiafvXfi-o/s1600/einsteing.jpg" alt="sample73" />
<figcaption>
<h2>Ruby Von Rails</h2>
<h3>Public Relations</h3>
<p>But Calvin is no kind and loving god! He's one of the old gods! He demands sacrifice! </p>
</figcaption>
<a href="#"></a>
</figure>
<script>$('.hover').mouseleave(function () {
$(this).removeClass('hover');
});
</script>
*****************************************************************************
<style>
$textSize: 6vw;
html,
body {
margin: 0;
padding: 0;
font-size: 100%;
}
.container {
background: linear-gradient(to bottom, #f4e400 0%, #ed6e00 100%);
height: 100vh;
width: 100vw;
position: absolute;
overflow: hidden;
perspective: 500px;
}
900
.scrollTxt {
position: absolute;
bottom: 0 - $textSize * 2;
right: 0;
animation-name: scroll;
animation-duration: 50s;
animation-timing-function: linear;
animation-iteration-count: infinite;
}
.scrollTxt p {
color: red;
opacity: 0.3;
font-family: 'Oswald', sans-serif;
font-size: $textSize;
text-transform: uppercase;
line-height: 0;
text-align: center;
}
@keyframes scroll {
from {
transform: rotateX(20deg) rotateZ(30deg);
}
to {
transform: rotateX(20deg) rotateZ(30deg) translateY($textSize * 11);
}
}
</style>
<div class="container">
<div class="scrollTxt">
<p>HTML & CSS</p>
<p>Development</p>
<p>PHP & MySQL</p>
<p>Web Design</p>
<p>JavaScript</p>
<p>Graphic Design</p>
<p>Search Engine Optimisation</p>
<p>Server Administration</p>
<p>Photoshop</p>
<p>Affinity Photo</p>
<p>Affinity Designer</p>
<p>HTML & CSS</p>
<p>Development</p>
<p>PHP & MySQL</p>
<p>Web Design</p>
<p>JavaScript</p>
<p>Graphic Design</p>
<p>Search Engine Optimisation</p>
<p>Server Administration</p>
<p>Photoshop</p>
<p>Affinity Photo</p>
<p>Affinity Designer</p>
</div>
</div>
*****************************************************************************
901
Try and catch method
public class HelloWorld {
public static void main(String args[]) {
int d, a;
d = 2;
a = 42 / d;
System.out.println("42 divided by d");
}
}
42 divided by d
If d = 2; is replaced by d = 0;
i.e.,
at HelloWorld.main(HelloWorld.java:5)”
will be thrown on the screen since 42/ d is undefined and cannot be complied and executed by the
compiler.
int d, a;
try {
d = 0;
a = 42 / d;
902
}
catch(ArithmeticException e) {
42 divided by zero
*****************************************************************************
"I speak Spanish to God, Italian to women, French to men, and German to my horse." -- Emperor
Charles V (1500—1558)
: Jeremy Keith
Java → saved as class file → converted to byte codes → executed by JVM (Java
Virtual Machine)
Javascript → directly executed by web browser.
*****************************************************************************
Image animation + text
903
<style class="cp-pen-styles">
@import
url(https://fonts.googleapis.com/css?family=Open+Sans+Condensed:700|Playfair+Display:400,700);
*,
*:before,
*:after {
margin: 0;
padding: 0;
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
font-family: 'Playfair Display', serif;
}
.fullscreen {
width: 100%;
height: 100%;
}
.fullscreen img {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
-o-object-fit: cover;
object-fit: cover;
z-index: 1;
}
.fullscreen-caption {
position: relative;
top: 12.5%;
left: 27.5%;
width: 60%;
height: 75%;
z-index: 2;
border: 5vw solid white;
-webkit-border-image: url("http://media.boingboing.net/wp-content/uploads/2014/06/giphy-
13.gif");
-o-border-image: url("http://media.boingboing.net/wp-content/uploads/2014/06/giphy-
13.gif");
border-image: url("http://media.boingboing.net/wp-content/uploads/2014/06/giphy-
13.gif");
border-image-slice: 10%;
box-shadow: 0 0 100px rgba(0, 0, 0, 0.4), inset 0 0 100px rgba(0, 0, 0, 0.4);
}
.fullscreen-caption .inner {
position: relative;
display: inline-block;
top: 100%;
-webkit-transform: translateX(-55%) translateY(-50vh);
transform: translateX(-55%) translateY(-50vh);
904
}
.fullscreen-caption h2,
.fullscreen-caption h3,
.fullscreen-caption a {
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
.fullscreen-caption h2 {
display: inline-block;
margin-bottom: 1rem;
color: black;
text-align: left;
font-weight: 400;
font-size: 7vw;
line-height: 7.8vw;
}
.fullscreen-caption h3 {
text-align: center;
color: rgba(0, 0, 0, 0.3);
font-weight: 700;
font-size: 1.2rem;
font-style: italic;
}
.fullscreen-caption .fullscreen-link {
position: relative;
display: inline-block;
margin: 12vh 0 0 20px;
padding-bottom: 10px;
font-family: 'Open Sans Condensed', sans-serif;
color: white;
text-decoration: none;
text-transform: uppercase;
letter-spacing: 2px;
border-bottom: 2px solid white;
}
.fullscreen-caption .fullscreen-link:before {
content: '';
position: absolute;
top: 3px;
left: -20px;
width: 0;
height: 0;
border-top: 7px solid transparent;
border-bottom: 7px solid transparent;
border-left: 10px solid white;
}
</style></head><body>
<figure class="fullscreen">
<img src="http://media.boingboing.net/wp-content/uploads/2014/06/giphy-13.gif" alt="" />
<figcaption class="fullscreen-caption">
<div class="inner">
<h2>Man <br/>of Century</h2>
<h3>Albert Einstein</h3>
<a class="fullscreen-link" href="#">Watch video</a>
905
</div>
</figcaption>
</figure>
*****************************************************************************
HTML page
<style>
*,
*::before,
*::after {
box-sizing: inherit;
}
html {
font-family: sans-serif;
font-size: 16px;
/* background: rgba(0, 0, 0, 0.0125); */
}
html,
body {
height: 100%;
background: #fff;
}
body {
margin: 0;
font: 100%/1.5 AvenirNext-Regular, Corbel, "Lucida Grande", "Trebuchet Ms", sans-serif;
color: #111;
min-height: 100%;
box-sizing: border-box;
}
article, aside, details, figcaption, figure, footer, header, hgroup, main, nav, section, summary {
display: block;
}
h2, h3, h4, h5, h6, p, blockquote, pre, dl, ol, form, table, figure, nav, hr {
margin-top: 3rem;
}
label {
margin-top: 1rem;
}
906
audio:not([controls]) {
display: none;
height: 0;
}
[hidden], template {
display: none;
}
header,
footer {
text-align: center;
}
a{
background: transparent;
color: #4183c4;
text-decoration: none;
}
a:active,
a:hover {
outline: 0;
}
a:hover,
a:focus,
a:active {
text-decoration: underline;
}
abbr[title] {
border-bottom: 1px dotted;
}
b, strong {
font-weight: bold;
}
dfn {
font-style: italic;
}
mark {
background: #ff0;
color: #000;
}
small {
font-size: 80%;
907
}
sub, sup {
font-size: 75%;
line-height: 0;
position: relative;
vertical-align: baseline;
}
sup {
top: -0.5em;
}
sub {
bottom: -0.25em;
}
img, svg {
border: 0;
max-width: 100%;
}
svg:not(:root) {
overflow: hidden;
}
figure {
margin-left: 1em;
}
hr {
height: 0;
padding: 1px;
border: 1px solid #ccc;
margin-bottom: 3rem;
box-sizing: content-box;
background-color: #eee;
}
article,
.container {
max-width: 60em;
margin: 0 auto 2em;
padding: 2.5em 5% 3em;
overflow: auto;
}
h1 {
font-family: AvenirNextCondensed-Medium, "Segoe Ui", Corbel, "Lucida Grande","Trebuchet Ms", sans-serif;
padding-top: 0;
margin: 0;
}
em {
font-family: AvenirNext-DemiBoldItalic, "Segoe Ui", Corbel, "Lucida Grande","Trebuchet Ms", sans-serif;
}
i{
font-family: AvenirNext-Italic, Avenir-Oblique, TrebuchetMS-Italic, "Lucida Grande", Corbel, "Trebuchet Ms", sans-serif;
font-style: italic;
}
h1 {
font-size: 2.5rem;
}
h2 {
font-size: 2.25rem;
}
h3 {
font-size: 2rem;
}
h4 {
font-size: 1.75rem;
}
h5,
h6,
dt {
font-size: 1.25rem;
text-transform: uppercase;
}
h6 {
font-family: AvenirNext-UltraLight, Avenir-Light, "Lucida Grande", "Lucida Unicode", Corbel, "Trebuchet Ms", sans-serif;
font-weight: normal;
909
}
dt {
margin-top: 1rem;
}
dd {
margin: 0 0 .5em 2em;
}
p{
margin: 0;
padding: .5em 0;
}
h3 + p,
h4 + p {
padding-top: 0;
}
header h1 {
text-align: center;
}
strong em {
font-family: AvenirNext-BoldItalic, Avenir-HeavyOblique, Trebuchet-BoldItalic, "Lucida Grande", Corbel, "Trebuchet Ms",
sans-serif;
font-weight: bold;
}
pre {
background-color: #f8f8f8;
border: 1px solid #ddd;
font-size: .875rem;
line-height: 1.5;
overflow: auto;
padding: 1rem 1.5rem;
border-radius: 3px;
word-wrap: normal;
white-space: pre-wrap;
}
pre code {
910
margin: 0;
padding: 0;
background-color: transparent;
border: none;
word-wrap: normal;
max-width: initial;
display: inline;
overflow: initial;
line-height: inherit;
}
pre code:before,
pre code:after {
content: normal;
}
p code,
ul code {
font-family: Consolas, Menlo, Monaco, monospace;
font-size: .875em;
margin: 0;
border: 1px solid #ddd;
background-color: #f8f8f8;
border-radius: 3px;
padding: 2px 0 0 0;
}
p code:before,
p code:after,
ul code:before,
ul code:after {
content: "\00a0";
letter-spacing: -0.2em;
}
ul {
padding: 0 .5em;
margin: .5em 0 .5em -.45rem;
}
ol ul {
padding-left: 1.5rem;
}
ul li {
list-style: none;
position: relative;
margin-left: -.75em;
padding-left: .75em;
}
911
nav ul li,
nav ul li a {
display: inline-block;
}
nav ul li {
position: relative;
}
nav ul li a {
padding: .5em 1em;
}
article ul li::before,
nav ul li:after {
content: " \B7"; /* middot in unicode -> · */
font-size: 1.25em;
color: #3ca555;
line-height: 0;
display: inline-block;
vertical-align: middle;
}
article ul li::before {
padding-right: 3px;
}
nav ul li:last-of-type:after {
content: "";
display: none;
}
ul ol,
ol ol {
margin: .5rem 0 1rem 1.45rem;
}
ul li li {
margin-left: 0;
}
ul ol li {
margin-left: -.75rem;
}
ul li::before,
blockquote,
hr,
pre {
box-shadow: 1px 1px 0 rgba(0, 0, 0, 0.1);
912
}
blockquote {
border-left: .5em solid #ccc;
padding: 2em 2rem 2.5rem 3rem;
margin-left: 1em;
background-color: #f7f7f7;
color: #666;
font-family: AvenirNext-Italic, Avenir-Oblique, AvenirMedium-Oblique, Georgia, serif;
font-style: italic;
}
button, select {
text-transform: none;
}
button,
input[type="button"],
input[type="submit"],
input[type="file"],
input[type="reset"] {
-webkit-appearance: none;
overflow: visible;
border-radius: 4px;
background-clip: padding-box;
background-image: -webkit-linear-gradient(top, white, #ddd);
background-image: linear-gradient(to bottom, white, #ddd);
border: 1px solid;
border-color: #ddd #bbb #999;
cursor: pointer;
color: #333;
display: inline-block;
outline: 0;
overflow: visible;
margin: 1.5rem 1rem;
padding: 1em 2em;
text-shadow: white 0 1px 1px;
text-decoration: none;
vertical-align: top;
width: auto;
913
font-size: 16px;
line-height: 1.3;
}
button:invalid {
box-shadow: none;
}
button:focus,
input[type="button"]:focus,
input[type="submit"]:focus,
input[type="file"]:focus,
input[type="reset"]:focus{
box-shadow: #06f 0 0 5px 0;
z-index: 1;
}
button:hover,
input[type="button"]:hover,
input[type="submit"]:hover,
input[type="file"]:hover,
input[type="reset"]:hover {
background-image: -webkit-linear-gradient(top, white, #eee 1px, #ccc);
background-image: linear-gradient(to bottom, white, #eee 1px, #ccc);
text-decoration: none;
}
button:active,
input[type="button"]:active,
input[type="submit"]:active,
input[type="file"]:active,
input[type="reset"]:active {
background-image: -webkit-linear-gradient(top, #ddd, #eee);
background-image: linear-gradient(to bottom, #ddd, #eee);
box-shadow: inset rgba(0, 0, 0, 0.25) 0 1px 2px 0;
border-color: #999 #bbb #ddd;
}
input {
line-height: normal;
}
914
input[type="checkbox"], input[type="radio"] {
box-sizing: border-box;
padding: 0;
}
input[type="number"]::-webkit-inner-spin-button, input[type="number"]::-webkit-outer-spin-button {
height: auto;
}
input[type="search"] {
-webkit-appearance: textfield;
box-sizing: content-box;
}
input[type="search"]::-webkit-search-cancel-button, input[type="search"]::-webkit-search-decoration {
-webkit-appearance: none;
}
input[type="file"] {
color: transparent;
}
input[type="file"]::-webkit-file-upload-button {
visibility: hidden;
}
input[type="file"]::before {
content: 'Choose File';
color: #111;
display: inline-block;
outline: none;
white-space: nowrap;
-webkit-user-select: none;
}
input[type="file"]:hover::before {
border-color: black;
}
input[type="file"]:active {
outline: 0;
}
input[type="file"]:active::before {
background: -webkit-linear-gradient(top, #e3e3e3, #f9f9f9);
}
fieldset {
border: 1px solid #c0c0c0;
margin: 1rem 2px;
padding: 0.35em 0.625em 0.75em;
915
}
legend {
border: 0;
padding: 0;
}
textarea {
overflow: auto;
}
optgroup {
font-weight: bold;
}
table {
border-collapse: collapse;
border-spacing: 0;
font-family: Consolas, Menlo, Monaco, monospace;
background: #f7f7f7;
margin-bottom: 3em;
}
thead {
display: table-header-group;
}
thead th {
border-bottom: 1px solid #999;
text-align: center;
font-size: 1.125em;
text-transform: uppercase;
font-weight: bold;
background: #ddd;
}
thead th:nth-of-type(1) {
text-align: left;
}
th, td {
padding: .5em 1em;
}
/* zebra stripes */
tr:nth-of-type(even) {
background: rgba(0, 0, 0, 0.125);
}
.clearfix:before,
.clearfix:after {
916
content: " ";
display: table;
}
.clearfix:after,
.clear {
clear: both;
}
h2 {
font-size: 2.5rem;
}
h3 {
font-size: 2.25rem;
}
h4 {
font-size: 2rem;
}
h5 {
font-size: 1.75rem;
}
h6 {
font-size: 1.5rem;
}
p{
font-size: 1.25rem;
}
li {
font-size: 1.25rem;
}
li li {
font-size: 1rem;
}
}
</style>
<style class="cp-pen-styles">html,
body {
background-color: #000;
}
917
.container {
max-width: 100em;
padding: 0;
background-color: #1c1c1c;
}
main {
max-width: 60em;
margin: -6.8em auto 0;
background-color: #000;
border-right: 12px solid #fff;
overflow: auto;
}
.content,
.sidebar {
padding-top: 6em;
}
.content {
max-width: 45em;
border: none;
float: left;
width: 70%;
background-color: #fff;
}
.sidebar {
float: right;
width: 30%;
background-color: #000;
color: #fff;
}
@media (min-width: 1600px) {
.sidebar {
background-image: url("data:image/svg+xml;charset='utf8',%3Csvg xmlns='http://www.w3.org/2000/svg' width='324'
height='76' viewBox='0 0 324 76'%3E%3Cpolygon fill='rgb(255,255,255)' points='324,25.5 111,76 0,52 0,0
324,0'/%3E%3Cpolygon fill='rgb(216,0,50)' points='314,18 111,66 10,44 10,36 111,58 314,10'/%3E%3C/svg%3E");
background-position: -1.7em 3.25em;
background-repeat: no-repeat;
padding-top: 6em;
}
}
.sidebar ul {
padding: 2em;
margin-top: 2em;
}
.sidebar ul li {
918
font-size: 1em;
}
.content p {
font-size: 1.125em;
}
</style></head><body>
<div class="container">
<header class="banner">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 1600 400">
<defs>
<clipPath id="clipPolygon">
<polygon points="1600,0 0,0 0,387 320,316 687,364 795,337 1068,400 1386,325 1600,385"/>
</clipPath>
</defs>
<image clip-path="url(#clipPolygon)" width="800" height="200" xlink:href="http://media.boingboing.net/wp-
content/uploads/2014/06/giphy-13.gif" />
</svg>
</header>
<main>
<article class="content">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Officia veniam, eveniet quos, explicabo ab iste quibusdam aliquid
molestias deserunt. Assumenda cum consectetur, dolorum dolore facere natus, nulla officiis rem deserunt!</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Officia veniam, eveniet quos, explicabo ab iste quibusdam aliquid
molestias deserunt. Assumenda cum consectetur, dolorum dolore facere natus, nulla officiis rem deserunt!</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Officia veniam, eveniet quos, explicabo ab iste quibusdam aliquid
molestias deserunt. Assumenda cum consectetur, dolorum dolore facere natus, nulla officiis rem deserunt!</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Officia veniam, eveniet quos, explicabo ab iste quibusdam aliquid
molestias deserunt. Assumenda cum consectetur, dolorum dolore facere natus, nulla officiis rem deserunt!</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Officia veniam, eveniet quos, explicabo ab iste quibusdam aliquid
molestias deserunt. Assumenda cum consectetur, dolorum dolore facere natus, nulla officiis rem deserunt!</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Officia veniam, eveniet quos, explicabo ab iste quibusdam aliquid
molestias deserunt. Assumenda cum consectetur, dolorum dolore facere natus, nulla officiis rem deserunt!</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Officia veniam, eveniet quos, explicabo ab iste quibusdam aliquid
molestias deserunt. Assumenda cum consectetur, dolorum dolore facere natus, nulla officiis rem deserunt!</p>
</article>
<aside class="sidebar">
<ul>
<li><a href="http://www.w3schools.com/html/"><font size="6" face="times" color="white">list-item</a></li>
<li>list-item</li>
<li>list-item</li>
<li>list-item</li>
<li>list-item</li>
</ul>
</aside>
919
</main>
</div>
*****************************************************************************
CSS Tab
<style class="cp-pen-styles">
html, body {
font-size: 20px;
}
html {
box-sizing: border-box;
}
*, *:before, *:after {
box-sizing: border-box;
}
body {
padding: 40px;
margin: 0;
line-height: 1.5;
background-color: #333;
font-family: Roboto, Helvetica, Arial, sans-serif;
color: #333;
}
h1 {
margin-top: 0;
line-height: 1.25;
text-align: center;
font-family: "Roboto Slab", Times, "Times New Roman", serif;
color: white;
}
/* highlight colors */
::-moz-selection {
background-color: #333;
color: white;
}
::selection {
background-color: #333;
color: white;
}
/* wrapper */
.wrapper {
max-width: 70ch;
padding-right: 10px;
padding-left: 10px;
margin-right: auto;
margin-left: auto;
920
}
/* tabs */
.tabs {
border-right: 1px solid #ccc;
}
.tabs:after {
content: "";
display: table;
clear: both;
}
.tabs input[type=radio] {
display: none;
}
.tabs label {
display: block;
float: left;
width: 33.33333%;
padding: 1em;
border: 1px solid #ccc;
border-right: none;
background-color: #f7f7f7;
text-align: center;
font-weight: 700;
color: coral;
cursor: pointer;
-webkit-transition: background-color 150ms ease-in-out;
transition: background-color 150ms ease-in-out;
}
.tabs label:hover {
background-color: white;
}
.tabs [id^="tab"]:checked + label {
border-bottom-color: white;
background: white;
color: #333;
}
.tab-content {
display: none;
float: left;
width: 100%;
padding: 1em;
border-bottom: 1px solid #ccc;
border-left: 1px solid #ccc;
background-color: white;
}
#tab1:checked ~ #tab-content1,
#tab2:checked ~ #tab-content2,
#tab3:checked ~ #tab-content3 {
display: block;
}
.other-content {
color: white;
}
921
@media only screen and (max-width: 768px) {
body, html {
font-size: 18px;
}
}
@media only screen and (max-width: 645px) {
.tabs label {
float: none;
width: 100%;
}
}
@media only screen and (max-width: 480px) {
body, html {
font-size: 16px;
}
}
</style></head><body>
<div class="wrapper">
<h1>Pure CSS Tabs</h1>
<div class="tabs cf">
<input type="radio" name="tabs" id="tab1" checked>
<label for="tab1">
Description
</label>
<input type="radio" name="tabs" id="tab2">
<label for="tab2">
Features
</label>
<input type="radio" name="tabs" id="tab3">
<label for="tab3">
Delivery & returns
</label>
922
</div>
</div>
<div class="other-content">
<p>
Lorem ipsum dolor sit amet, ne duo urbanitas eloquentiam consectetuer, vel et stet
complectitur intellegebat.
</p>
</div>
</div>
*****************************************************************************
Image reflection
<style class="cp-pen-styles">
svg {
overflow: visible;
max-width: 640px;
}
</style></head><body>
*****************************************************************************
Word counter
<style class="cp-pen-styles">
/* border box */
html {
box-sizing: border-box;
-webkit-user-select: none;
/* Chrome all / Safari all */
-moz-user-select: none;
/* Firefox all */
-ms-user-select: none;
/* IE 10+ */
user-select: none;
/* Likely future */
}
923
*,
*:before,
*:after {
box-sizing: inherit;
}
b {
font-weight: bold;
}
body {
width: 700px;
margin: 0 auto;
background-color: #FAFAFA;
font-family: 'Source Sans Pro', sans-serif;
color: #111;
}
.container {
margin: 2% auto;
padding: 15px;
background-color: #FFFFFF;
-webkit-box-shadow: 0px 1px 4px 0px rgba(0, 0, 0, 0.2);
box-shadow: 0px 1px 4px 0px rgba(0, 0, 0, 0.2);
}
h1 {
font-size: 3rem;
font-weight: 900;
text-align: center;
margin: 1% 0 3%;
}
textarea {
width: 100%;
height: 250px;
padding: 10px;
border: 1px solid #d9d9d9;
outline: none;
font-size: 1rem;
resize: none;
line-height: 1.5rem;
}
textarea:hover {
border-color: #C0C0C0;
}
textarea:focus {
border-color: #4D90FE;
}
.output.row {
width: 100%;
border: 1px solid #DDD;
924
font-size: 1.4rem;
margin: 1% 0;
background-color: #F9F9F9;
}
.output.row div {
display: inline-block;
width: 42%;
padding: 10px 15px;
margin: 1%;
}
.output.row span {
font-weight: bold;
font-size: 1.5rem;
}
#readability {
width: 52%;
font-weight: bold;
}
#readability:hover {
background-color: #4D90FE;
color: #FFF;
border-radius: 2px;
cursor: pointer;
}
#readability:active {
background-color: #307AF3;
}
.keywords {
display: none;
margin: 4% 0 0;
font-size: 2rem;
font-weight: 900;
}
.keywords ul {
font-weight: 400;
border: 1px solid #DDD;
font-size: 1.4rem;
background-color: #F9F9F9;
margin: 2% 0;
}
.keywords li {
display: inline-block;
width: 44%;
padding: 10px;
margin: 1%;
}
/*
** Making it responsive
925
*/
926
border: 1px solid #DDD;
}
}</style></head><body>
<div class="container">
<h1>Word Counter</h1>
<textarea placeholder="Enter your text here..."></textarea>
<div class="output row">
<div>Characters: <span id="characterCount">0</span></div>
<div>Words: <span id="wordCount">0</span></div>
</div>
<div class="output row">
<div>Sentences: <span id="sentenceCount">0</span></div>
<div>Paragraphs: <span id="paragraphCount">0</span></div>
</div>
<div class="output row">
<div>Reading Time: <span id="readingTime">0</span></div>
<div id="readability">Show readability score.</div>
</div>
<div class="keywords">
Top keywords:
<ul id="topKeywords">
</ul>
</div>
</div>
<script>'use strict';
var input = document.querySelectorAll('textarea')[0], characterCount =
document.querySelector('#characterCount'), wordCount = document.querySelector('#wordCount'),
sentenceCount = document.querySelector('#sentenceCount'), paragraphCount =
document.querySelector('#paragraphCount'), readingTime = document.querySelector('#readingTime'),
readability = document.querySelector('#readability'), keywordsDiv =
document.querySelectorAll('.keywords')[0], topKeywords = document.querySelector('#topKeywords');
input.addEventListener('keyup', function () {
console.clear();
characterCount.innerHTML = input.value.length;
var words = input.value.match(/\b[-?(\w+)?]+\b/gi);
if (words) {
wordCount.innerHTML = words.length;
} else {
wordCount.innerHTML = 0;
}
if (words) {
var sentences = input.value.split(/[.|!|?]+/g);
console.log(sentences);
sentenceCount.innerHTML = sentences.length - 1;
} else {
sentenceCount.innerHTML = 0;
}
if (words) {
var paragraphs = input.value.replace(/\n$/gm, '').split(/\n/);
paragraphCount.innerHTML = paragraphs.length;
} else {
paragraphCount.innerHTML = 0;
}
if (words) {
var seconds = Math.floor(words.length * 60 / 275);
if (seconds > 59) {
var minutes = Math.floor(seconds / 60);
927
seconds = seconds - minutes * 60;
readingTime.innerHTML = minutes + 'm ' + seconds + 's';
} else {
readingTime.innerHTML = seconds + 's';
}
} else {
readingTime.innerHTML = '0s';
}
if (words) {
var nonStopWords = [];
var stopWords = [
'a',
'able',
'about',
'above',
'abst',
'accordance',
'according',
'accordingly',
'across',
'act',
'actually',
'added',
'adj',
'affected',
'affecting',
'affects',
'after',
'afterwards',
'again',
'against',
'ah',
'all',
'almost',
'alone',
'along',
'already',
'also',
'although',
'always',
'am',
'among',
'amongst',
'an',
'and',
'announce',
'another',
'any',
'anybody',
'anyhow',
'anymore',
'anyone',
'anything',
'anyway',
'anyways',
'anywhere',
'apparently',
'approximately',
928
'are',
'aren',
'arent',
'arise',
'around',
'as',
'aside',
'ask',
'asking',
'at',
'auth',
'available',
'away',
'awfully',
'b',
'back',
'be',
'became',
'because',
'become',
'becomes',
'becoming',
'been',
'before',
'beforehand',
'begin',
'beginning',
'beginnings',
'begins',
'behind',
'being',
'believe',
'below',
'beside',
'besides',
'between',
'beyond',
'biol',
'both',
'brief',
'briefly',
'but',
'by',
'c',
'ca',
'came',
'can',
'cannot',
'can\'t',
'cause',
'causes',
'certain',
'certainly',
'co',
'com',
'come',
'comes',
'contain',
929
'containing',
'contains',
'could',
'couldnt',
'd',
'date',
'did',
'didn\'t',
'different',
'do',
'does',
'doesn\'t',
'doing',
'done',
'don\'t',
'down',
'downwards',
'due',
'during',
'e',
'each',
'ed',
'edu',
'effect',
'eg',
'eight',
'eighty',
'either',
'else',
'elsewhere',
'end',
'ending',
'enough',
'especially',
'et',
'et-al',
'etc',
'even',
'ever',
'every',
'everybody',
'everyone',
'everything',
'everywhere',
'ex',
'except',
'f',
'far',
'few',
'ff',
'fifth',
'first',
'five',
'fix',
'followed',
'following',
'follows',
'for',
930
'former',
'formerly',
'forth',
'found',
'four',
'from',
'further',
'furthermore',
'g',
'gave',
'get',
'gets',
'getting',
'give',
'given',
'gives',
'giving',
'go',
'goes',
'gone',
'got',
'gotten',
'h',
'had',
'happens',
'hardly',
'has',
'hasn\'t',
'have',
'haven\'t',
'having',
'he',
'hed',
'hence',
'her',
'here',
'hereafter',
'hereby',
'herein',
'heres',
'hereupon',
'hers',
'herself',
'hes',
'hi',
'hid',
'him',
'himself',
'his',
'hither',
'home',
'how',
'howbeit',
'however',
'hundred',
'i',
'id',
'ie',
931
'if',
'i\'ll',
'im',
'immediate',
'immediately',
'importance',
'important',
'in',
'inc',
'indeed',
'index',
'information',
'instead',
'into',
'invention',
'inward',
'is',
'isn\'t',
'it',
'itd',
'it\'ll',
'its',
'itself',
'i\'ve',
'j',
'just',
'k',
'keep',
'keeps',
'kept',
'kg',
'km',
'know',
'known',
'knows',
'l',
'largely',
'last',
'lately',
'later',
'latter',
'latterly',
'least',
'less',
'lest',
'let',
'lets',
'like',
'liked',
'likely',
'line',
'little',
'\'ll',
'look',
'looking',
'looks',
'ltd',
'm',
932
'made',
'mainly',
'make',
'makes',
'many',
'may',
'maybe',
'me',
'mean',
'means',
'meantime',
'meanwhile',
'merely',
'mg',
'might',
'million',
'miss',
'ml',
'more',
'moreover',
'most',
'mostly',
'mr',
'mrs',
'much',
'mug',
'must',
'my',
'myself',
'n',
'na',
'name',
'namely',
'nay',
'nd',
'near',
'nearly',
'necessarily',
'necessary',
'need',
'needs',
'neither',
'never',
'nevertheless',
'new',
'next',
'nine',
'ninety',
'no',
'nobody',
'non',
'none',
'nonetheless',
'noone',
'nor',
'normally',
'nos',
'not',
933
'noted',
'nothing',
'now',
'nowhere',
'o',
'obtain',
'obtained',
'obviously',
'of',
'off',
'often',
'oh',
'ok',
'okay',
'old',
'omitted',
'on',
'once',
'one',
'ones',
'only',
'onto',
'or',
'ord',
'other',
'others',
'otherwise',
'ought',
'our',
'ours',
'ourselves',
'out',
'outside',
'over',
'overall',
'owing',
'own',
'p',
'page',
'pages',
'part',
'particular',
'particularly',
'past',
'per',
'perhaps',
'placed',
'please',
'plus',
'poorly',
'possible',
'possibly',
'potentially',
'pp',
'predominantly',
'present',
'previously',
'primarily',
934
'probably',
'promptly',
'proud',
'provides',
'put',
'q',
'que',
'quickly',
'quite',
'qv',
'r',
'ran',
'rather',
'rd',
're',
'readily',
'really',
'recent',
'recently',
'ref',
'refs',
'regarding',
'regardless',
'regards',
'related',
'relatively',
'research',
'respectively',
'resulted',
'resulting',
'results',
'right',
'run',
's',
'said',
'same',
'saw',
'say',
'saying',
'says',
'sec',
'section',
'see',
'seeing',
'seem',
'seemed',
'seeming',
'seems',
'seen',
'self',
'selves',
'sent',
'seven',
'several',
'shall',
'she',
'shed',
'she\'ll',
935
'shes',
'should',
'shouldn\'t',
'show',
'showed',
'shown',
'showns',
'shows',
'significant',
'significantly',
'similar',
'similarly',
'since',
'six',
'slightly',
'so',
'some',
'somebody',
'somehow',
'someone',
'somethan',
'something',
'sometime',
'sometimes',
'somewhat',
'somewhere',
'soon',
'sorry',
'specifically',
'specified',
'specify',
'specifying',
'still',
'stop',
'strongly',
'sub',
'substantially',
'successfully',
'such',
'sufficiently',
'suggest',
'sup',
'sure',
't',
'take',
'taken',
'taking',
'tell',
'tends',
'th',
'than',
'thank',
'thanks',
'thanx',
'that',
'that\'ll',
'thats',
'that\'ve',
936
'the',
'their',
'theirs',
'them',
'themselves',
'then',
'thence',
'there',
'thereafter',
'thereby',
'thered',
'therefore',
'therein',
'there\'ll',
'thereof',
'therere',
'theres',
'thereto',
'thereupon',
'there\'ve',
'these',
'they',
'theyd',
'they\'ll',
'theyre',
'they\'ve',
'think',
'this',
'those',
'thou',
'though',
'thoughh',
'thousand',
'throug',
'through',
'throughout',
'thru',
'thus',
'til',
'tip',
'to',
'together',
'too',
'took',
'toward',
'towards',
'tried',
'tries',
'truly',
'try',
'trying',
'ts',
'twice',
'two',
'u',
'un',
'under',
'unfortunately',
937
'unless',
'unlike',
'unlikely',
'until',
'unto',
'up',
'upon',
'ups',
'us',
'use',
'used',
'useful',
'usefully',
'usefulness',
'uses',
'using',
'usually',
'v',
'value',
'various',
'\'ve',
'very',
'via',
'viz',
'vol',
'vols',
'vs',
'w',
'want',
'wants',
'was',
'wasn\'t',
'way',
'we',
'wed',
'welcome',
'we\'ll',
'went',
'were',
'weren\'t',
'we\'ve',
'what',
'whatever',
'what\'ll',
'whats',
'when',
'whence',
'whenever',
'where',
'whereafter',
'whereas',
'whereby',
'wherein',
'wheres',
'whereupon',
'wherever',
'whether',
'which',
938
'while',
'whim',
'whither',
'who',
'whod',
'whoever',
'whole',
'who\'ll',
'whom',
'whomever',
'whos',
'whose',
'why',
'widely',
'willing',
'wish',
'with',
'within',
'without',
'won\'t',
'words',
'world',
'would',
'wouldn\'t',
'www',
'x',
'y',
'yes',
'yet',
'you',
'youd',
'you\'ll',
'your',
'youre',
'yours',
'yourself',
'yourselves',
'you\'ve',
'z',
'zero'
];
for (var i = 0; i < words.length; i++) {
if (window.CP.shouldStopExecution(1)) {
break;
}
if (stopWords.indexOf(words[i].toLowerCase()) === -1 && isNaN(words[i])) {
nonStopWords.push(words[i].toLowerCase());
}
}
window.CP.exitedLoop(1);
var keywords = {};
for (var i = 0; i < nonStopWords.length; i++) {
if (window.CP.shouldStopExecution(2)) {
break;
}
if (nonStopWords[i] in keywords) {
keywords[nonStopWords[i]] += 1;
} else {
939
keywords[nonStopWords[i]] = 1;
}
}
window.CP.exitedLoop(2);
var sortedKeywords = [];
for (var keyword in keywords) {
if (window.CP.shouldStopExecution(3)) {
break;
}
sortedKeywords.push([
keyword,
keywords[keyword]
]);
}
window.CP.exitedLoop(3);
sortedKeywords.sort(function (a, b) {
return b[1] - a[1];
});
topKeywords.innerHTML = '';
for (var i = 0; i < sortedKeywords.length && i < 4; i++) {
var li = document.createElement('li');
li.innerHTML = '<b>' + sortedKeywords[i][0] + '</b>: ' + sortedKeywords[i][1];
topKeywords.appendChild(li);
}
}
if (words) {
keywordsDiv.style.display = 'block';
} else {
keywordsDiv.style.display = 'none';
}
});
readability.addEventListener('click', function () {
readability.innerHTML = 'Fetching score...';
var requestUrl = 'https://ipeirotis-readability-
metrics.p.mashape.com/getReadabilityMetrics?text=';
var data = input.value;
var request = new XMLHttpRequest();
request.open('POST', encodeURI(requestUrl + data), true);
request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
request.setRequestHeader('X-Mashape-Authorization',
'PQ4FOFuaR6mshI6qpnQKQvkDZQXjp1o6Zcqjsnug7GvNggTzUE');
request.send();
request.onload = function () {
if (this.status >= 200 && this.status < 400) {
readability.innerHTML = readingEase(JSON.parse(this.response).FLESCH_READING);
} else {
readability.innerHTML = 'Not available.';
}
};
request.onerror = function () {
readability.innerHTML = 'Not available.';
};
});
function readingEase(num) {
switch (true) {
case num <= 30:
return 'Readability: College graduate.';
break;
940
case num > 30 && num <= 50:
return 'Readability: College level.';
break;
case num > 50 && num <= 60:
return 'Readability: 10th - 12th grade.';
break;
case num > 60 && num <= 70:
return 'Readability: 8th - 9th grade.';
break;
case num > 70 && num <= 80:
return 'Readability: 7th grade.';
break;
case num > 80 && num <= 90:
return 'Readability: 6th grade.';
break;
case num > 90 && num <= 100:
return 'Readability: 5th grade.';
break;
default:
return 'Not available.';
break;
}
}
</script>
*****************************************************************************
Page Resource
<style class="cp-pen-styles">*,
*:before,
*:after {
box-sizing: border-box;
margin: 0px;
}
html,
body {
height: 100%;
}
body {
background: -webkit-linear-gradient(315deg, #2fa6a9, #2fa6a9 30%, #f5f5f5 30%, #f5f5f5 70%,
#2fa6a9 70%) no-repeat fixed;
background: linear-gradient(135deg, #2fa6a9, #2fa6a9 30%, #f5f5f5 30%, #f5f5f5 70%, #2fa6a9
70%) no-repeat fixed;
width: 100%;
padding: 100px;
}
.product-select {
font-family: "proxima-nova", sans-serif;
width: 1000px;
margin: 0px auto;
position: relative;
height: 100%;
941
}
.product-select li {
display: inline;
width: 33%;
background: #fff;
text-align: center;
position: absolute;
box-shadow: 0px 0px 55px 0px rgba(0, 0, 0, 0.15);
border-radius: 0.38em;
padding: 35px 0;
-webkit-transition: all 0.2s ease;
transition: all 0.2s ease;
}
.product-select li img {
height: 160px;
}
.product-select li .price {
display: block;
font-family: "sofia-pro-soft";
font-size: 4em;
line-height: 0.9em;
color: #2fa6a9;
}
.product-select li .price:before {
content: '$';
font-size: 0.5em;
position: relative;
top: -0.5em;
}
.product-select li .price:after {
content: '/mo';
font-size: 0.5em;
}
.product-select li .featured {
text-transform: uppercase;
display: block;
color: white;
font-size: 1.3em;
letter-spacing: 0.15em;
background: #52c883;
padding: 10px;
margin: 5px 0;
}
.product-select li h1 {
color: #5c7576;
font-weight: 700;
padding: 5px;
letter-spacing: 0.05em;
}
.product-select li p {
color: #87a9aa;
position: relative;
letter-spacing: 0.05em;
padding: 10px 0 10px;
}
.product-select li a {
display: inline-block;
text-decoration: none;
942
color: #fff;
background: #52d990;
margin: 10px 0 0;
padding: 15px 50px;
border-radius: 2em;
font-weight: 700;
font-size: 1.3em;
box-shadow: #52c883 0px 0.3em 0px;
-webkit-transition: all 0.2s ease;
transition: all 0.2s ease;
}
.product-select li a:hover {
-webkit-transform: translateY(0.2em);
transform: translateY(0.2em);
box-shadow: #52c883 0px 0.1em 0px;
}
.product-select li:nth-child(2) {
z-index: 1;
left: 355px;
top: -25px;
-webkit-transform: scale(1.05);
transform: scale(1.05);
}
.product-select li:nth-child(3) {
right: 0%;
}
.product-select li:hover {
z-index: 2;
-webkit-transform: scale(1.07);
transform: scale(1.07);
}
943
transform: scale(1);
}
.product-select li:nth-child(3) {
right: 0px;
}
.product-select li:hover {
-webkit-transform: scale(1);
transform: scale(1);
}
}
</style></head><body>
<script src="https://use.typekit.net/jwv5czq.js"></script>
<script>
try{Typekit.load({ async: true });}catch(e){}
</script>
<div class="container">
<ul class="product-select">
<li>
<img src="http://media.boingboing.net/wp-content/uploads/2014/06/giphy-13.gif">
<span class="price">0</span>
<h1>Free</h1>
<p>Our Branding</p>
<p>1 GB Storage</p>
<a href="#">Sign Up Now</a>
</li>
<li>
<img
src="https://static1.squarespace.com/static/54447168e4b07b71baef4d26/t/576a9ee55016e162b7fc0bec/1
466605286658/windmill.png">
<span class="price">35</span>
<span class="featured">Most Popular</span>
<h1>Premium</h1>
<p>Fully Customizeable</p>
<p>Unlimited Storage</p>
<a href="#">Add to Cart</a>
</li>
<li>
<img
src="https://static1.squarespace.com/static/54447168e4b07b71baef4d26/t/576ae1e7cd0f68434d8aa0e7/1
466622440745/plant.png">
<span class="price">99</span>
<h1>Enterprise</h1>
<p>Full License</p>
<p>Scaleable Architecture</p>
<a href="#">Add to Cart</a>
</li>
</ul>
</div>
*****************************************************************************
Border image animation
<style class="cp-pen-styles">*,
*:before,
*:after {
margin: 0;
padding: 0;
944
}
html, body {
width: 100%;
height: 100%;
}
body {
background-image: url("http://animationsa2z.com/attachments/Image/funny/funny56.gif");
background-size: cover;
background-repeat: no-repeat;
background-position: 50%;
}
body:before {
content: '';
position: absolute;
top: 50%;
left: 50%;
width: 40vw;
height: 40vh;
border-top: 20vh solid;
border-right: 20vw solid;
border-bottom: 20vh solid;
border-left: 20vw solid;
-webkit-border-image: url("http://animationsa2z.com/attachments/Image/funny/funny56.gif");
-o-border-image: url("http://animationsa2z.com/attachments/Image/funny/funny56.gif");
border-image: url("http://animationsa2z.com/attachments/Image/funny/funny56.gif");
border-image-slice: 25%;
-webkit-transform: translateX(-50%) translateY(-50%);
transform: translateX(-50%) translateY(-50%);
-webkit-animation: animateBorder 3s infinite alternate-reverse;
animation: animateBorder 3s infinite alternate-reverse;
-webkit-animation-delay: -1s;
animation-delay: -1s;
}
@-webkit-keyframes animateBorder {
0% {
border-image-slice: 8%;
}
100% {
border-image-slice: 35%;
}
}
@keyframes animateBorder {
0% {
border-image-slice: 8%;
}
100% {
border-image-slice: 35%;
}
}
</style>
*****************************************************************************
945
Pure CSS Link URL Preview
<style class="cp-pen-styles">
a {
position: relative;
display: inline-block;
color: #228475;
}
a::before {
position: absolute;
top: 100%;
content: attr(href);
opacity: 0;
display: block;
transition: .25s all;
height: 0;
overflow: hidden;
padding: .25em 1em;
background: #fff;
box-shadow: 0 0 3px 0 rgba(0, 0, 0, 0.3);
font-size: .7em;
color: #555;
}
a:hover::before {
opacity: 1;
display: block;
height: auto;
}
body {
display: flex;
align-items: center;
justify-content: center;
height: 100vh;
background: #E9C46A;
font-size: 1.3em;
line-height: 170%;
font-family: 'Lora', serif;
}
article {
padding: 1em;
max-width: 95%;
width: 20em;
background: #fff;
box-shadow: 0 0 0 15px rgba(0, 0, 0, 0.1);
}
p {
margin: 0;
}
h1 {
margin: 0;
text-align: center;
}
946
h1::after {
display: block;
content: '';
border-top: 2px solid #F4A261;
width: 5em;
margin: 1em auto;
}
</style></head><body>
<article>
<h1>Link URL Preview</h1>
<p>Ever wanted to know what URL a link has in store? Here's an easy way to show your users <a
href="http://jondaiello.com" target="_blank">where a text link</a> will take them.</p>
</article>
*****************************************************************************
text-align-last
<style class="cp-pen-styles">
body {
margin: 20px 40px;
font-family: 'Lato';
max-width: 640px;
}
h2 {
font-size: 1.5em;
background: black;
color: white;
text-align: center;
padding: 10px;
margin-bottom: 50px;
}
p {
line-height: 1.5;
margin-bottom: 15px;
}
article {
text-align: justify;
}
article p:last-of-type {
-moz-text-align-last: right;
text-align-last: right;
}</style></head><body>
<article>
</article>
*****************************************************************************
LinkedIn Button
<style class="cp-pen-styles">
body {
margin: 0;
padding: 0;
}
* {
box-sizing: border-box;
}
body {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-box-pack: center;
-webkit-justify-content: center;
-ms-flex-pack: center;
justify-content: center;
-webkit-box-align: center;
-webkit-align-items: center;
-ms-flex-align: center;
align-items: center;
height: 100vh;
width: 100%;
font-family: 'Mada', sans-serif;
-webkit-font-smoothing: antialiased;
font-size: 3em;
}
a {
position: relative;
top: 0;
left: 0;
margin-right: 0.25em;
948
padding: 0.25em;
font-weight: 900;
color: #0077b5;
text-decoration: none;
background-color: #fff;
border: 8px solid #0077b5;
-webkit-transition: all 0.15s ease-in-out;
transition: all 0.15s ease-in-out;
}
a:after {
content: '';
position: absolute;
top: 0;
left: 0;
z-index: -1;
display: block;
height: calc(100% + 12px);
width: calc(100% + 12px);
background-color: #0077b5;
-webkit-transition: all 0.15s ease-in-out;
transition: all 0.15s ease-in-out;
}
a:hover {
top: 6px;
left: 6px;
}
a:hover:after {
top: -6px;
left: -6px;
}
</style></head><body>
<div>
Would you like to <a href="https://www.linkedin.com/" target="_blank">connect</a>?
</div>
*****************************************************************************
<style class="cp-pen-styles">
.c-posts {
display: flex;
flex-wrap: wrap;
align-items: top;
padding: 5%;
}
.c-posts__item {
flex-grow: 1;
padding-bottom: 2em;
}
.c-posts__item:first-child {
flex-grow: 2;
}
950
.c-footer p {
font-weight: 300;
}
* {
box-sizing: border-box;
}
body {
font-family: 'Georgia', Times, serif;
line-height: 1.6em;
padding: 0;
margin: 0;
}
h1 {
font-size: calc(130% + 1vw);
font-weight: normal;
}
h2 {
font-size: 1.5em;
font-weight: normal;
margin-bottom: 0;
margin-top: 0;
}
a {
color: #0F5257;
}
.c-btn {
color: #000;
display: inline-block;
border-bottom: 4px solid #000;
text-decoration: none;
text-transform: uppercase;
font-family: 'Source Sans Pro', sans-serif;
font-weight: 900;
letter-spacing: .1em;
padding: .3em 0;
position: relative;
transition: .2s all;
}
.c-btn:before {
content: '';
position: absolute;
bottom: 0;
width: 100%;
background: #FF521B;
height: 0%;
transition: .2s all;
left: 0;
z-index: -10;
}
.c-btn:hover {
padding-left: .75em;
padding-right: .75em;
951
color: #fff;
border-color: #FF521B;
}
.c-btn:hover:before {
height: 100%;
}
</style></head><body>
<header class="c-header">
<h1>Responsive Flexbox Article Listing</h1>
<p>Flexbox is an amazingly powerful layout tool. In this example I have created a responsive
grid of articles that increased the amount of visible articles on the page at larger
resolutions.</p>
</header>
<section class="c-posts">
<article class="c-posts__item">
<h2>Article Title Here</h2>
<p>Hydrogen stratosphere control tower capacitor Saturn Lalande 21185. Control tower x-rays
Luhman 16 Banard's Star engine lunar. Horizon engine capture Pluto Brahe sun continuum ion-drive
control tower Proxima Centauri space-time booster. Core horizon subspace Voyager coordinates
water. Contractors Banard's Star nozzle time Orion weightless Gemini extra-vehicular explore.</p>
<p><a href="#" class="c-btn">Read More</a></p>
</article>
<article class="c-posts__item">
<h2>Article Title Here</h2>
<p>Mars NASA subspace crew warp Herschel stratosphere. Saturn sky zero-g stratosphere fuel
cell Venus grounded crew yaw Ptolemy Challenger. Pioneer stratosphere Cassini Lalande 21185 Earth
telemetry. Galileo uranium jumpsuit warp Hawking.</p>
<p><a href="#" class="c-btn">Read More</a></p>
</article>
<article class="c-posts__item">
<h2>Article Title Here</h2>
<p>Challenger Voyager Sirius capsule Pioneer Kepler hyperspace launch. Singularity extra-
vehicular circumnavigate burst. Procyon fuel cell asteroid subspace uranium Proxima Centauri
prototype capsule.</p>
<p><a href="#" class="c-btn">Read More</a></p>
</article>
<article class="c-posts__item">
<h2>Article Title Here</h2>
<p>Capsule crew Discovery ice spacecraft Pioneer gravity Picard. Lithium contractors meteor
water core saucer white hole stars planet Picard Jupiter Skunkworks. Prototype clusters Voyager
cosmos zero-g Pluto Skunkworks hatch. Circumnavigate core hyperspace motion comet Ptolemy.</p>
<p><a href="#" class="c-btn">Read More</a></p>
</article>
<article class="c-posts__item">
<h2>Article Title Here</h2>
<p>Orbit warp atomic Buzz Lightyear. Uranium circumnavigate Halley Neptune nebula launch
north Proxima Centauri engine.</p>
<p><a href="#" class="c-btn">Read More</a></p>
</article>
<article class="c-posts__item">
<h2>Article Title Here</h2>
<p>Troposphere capacitor Newton Kepler. Jupiter ionosphere saucer Gemini Neptune core Alpha
Centauri Venus comet Proxima Centauri Herschel. Banard's Star inertia laser contractors ion-drive
fuel cell NASA. Panel solar-flare dwarf probe Sagan Sirius jetpack time laser. Columbia nebula
horizon mesoshphere pulsar mission nuclear Sirius jetpack UFO.</p>
<p><a href="#" class="c-btn">Read More</a></p>
</article>
<article class="c-posts__item">
952
<h2>Article Title Here</h2>
<p>X-rays Orion capsule re-entry Mercury tank capture Mars control tower. Fusion Challenger
physics flight Saturn . Warp countdown flare telemetry yaw rocket stars. Planet astronomy Venus
reusable continuum inertia robotic re-entry booster Pioneer.</p>
<p><a href="#" class="c-btn">Read More</a></p>
</article>
<article class="c-posts__item">
<h2>Article Title Here</h2>
<p>Solar crew hydrogen booster panel Europa array Saturn fusion Jupiter control tower
singularity. Telemetry laser Venus wave capacitor gamma ray orbit lunar Uranus. Venus supernova
Hawking ignite Mars Kirk Pluto.</p>
<p><a href="#" class="c-btn">Read More</a></p>
</article>
<article class="c-posts__item">
<h2>Article Title Here</h2>
<p>Dormant container star system subspace solar binary inverter hyperspace warp. Yaw LiDAR
hydrogen container galaxy heliosphere Houston Skunkworks gravity weightless pulsar pitch. Stars
volatile ice kryptonite extra-vehicular Cassini crew meteor Earth positron. Aurora singularity
coordinates nozzle Skunkworks valve orbit Herschel.</p>
<p><a href="#" class="c-btn">Read More</a></p>
</article>
<article class="c-posts__item">
<h2>Article Title Here</h2>
<p>Hubble nebula Europa Gemini Skunkworks subspace uranium extra-vehicular Galileo release
planet Banard's Star. Pulsar stars Tyson prototype lunar explore Pioneer ion-drive
mesoshphere.</p>
<p><a href="#" class="c-btn">Read More</a></p>
</article>
<article class="c-posts__item">
<h2>Article Title Here</h2>
<p>Hydrogen stratosphere control tower capacitor Saturn Lalande 21185. Control tower x-rays
Luhman 16 Banard's Star engine lunar. Horizon engine capture Pluto Brahe sun continuum ion-drive
control tower Proxima Centauri space-time booster. Core horizon subspace Voyager coordinates
water. Contractors Banard's Star nozzle time Orion weightless Gemini extra-vehicular explore.</p>
<p><a href="#" class="c-btn">Read More</a></p>
</article>
</section>
<footer class="c-footer">
<p>Ipsum provided by <a href="http://interstellaripsum.com?ref=codepen?pen=wWWmNB"
target="_blank">InterstellarIpsum.com</a></p>
</footer>
*****************************************************************************
<style class="cp-pen-styles">
div {
position: absolute;
top: 50%;
left: 50%;
}
.wrapper {
953
margin: -7.98em -20.02em;
width: 40.04em;
height: 15.96em;
}
.tiles {
-webkit-animation: r 9s linear infinite;
animation: r 9s linear infinite;
}
@-webkit-keyframes r {
to {
-webkit-filter: hue-rotate(360deg);
filter: hue-rotate(360deg);
}
}
@keyframes r {
to {
-webkit-filter: hue-rotate(360deg);
filter: hue-rotate(360deg);
}
}
video {
width: inherit;
height: inherit;
-o-object-fit: cover;
object-fit: cover;
}
.tile {
width: 7em;
height: 4.2em;
opacity: .5;
background: #59a112;
-webkit-animation: a 0s ease-in-out infinite alternate;
animation: a 0s ease-in-out infinite alternate;
}
.tile:nth-of-type(1) {
margin: -7.14em -19.18em;
-webkit-animation-duration: 3.14s;
animation-duration: 3.14s;
-webkit-animation-delay: -2.3864s;
animation-delay: -2.3864s;
}
.tile:nth-of-type(2) {
margin: -7.14em -11.34em;
-webkit-animation-duration: 2.14s;
animation-duration: 2.14s;
-webkit-animation-delay: -0.0214s;
animation-delay: -0.0214s;
}
.tile:nth-of-type(3) {
margin: -7.14em -3.5em;
-webkit-animation-duration: 2.87s;
animation-duration: 2.87s;
-webkit-animation-delay: -2.583s;
animation-delay: -2.583s;
954
}
.tile:nth-of-type(4) {
margin: -7.14em 4.34em;
-webkit-animation-duration: 2.24s;
animation-duration: 2.24s;
-webkit-animation-delay: -0.8064s;
animation-delay: -0.8064s;
}
.tile:nth-of-type(5) {
margin: -7.14em 12.18em;
-webkit-animation-duration: 3.07s;
animation-duration: 3.07s;
-webkit-animation-delay: -0.614s;
animation-delay: -0.614s;
}
.tile:nth-of-type(6) {
margin: -2.1em -19.18em;
-webkit-animation-duration: 3.55s;
animation-duration: 3.55s;
-webkit-animation-delay: -1.917s;
animation-delay: -1.917s;
}
.tile:nth-of-type(7) {
margin: -2.1em -11.34em;
-webkit-animation-duration: 3.3s;
animation-duration: 3.3s;
-webkit-animation-delay: -1.353s;
animation-delay: -1.353s;
}
.tile:nth-of-type(8) {
margin: -2.1em -3.5em;
-webkit-animation-duration: 2.21s;
animation-duration: 2.21s;
-webkit-animation-delay: -0.7072s;
animation-delay: -0.7072s;
}
.tile:nth-of-type(9) {
margin: -2.1em 4.34em;
-webkit-animation-duration: 3.16s;
animation-duration: 3.16s;
-webkit-animation-delay: -0.1264s;
animation-delay: -0.1264s;
}
.tile:nth-of-type(10) {
margin: -2.1em 12.18em;
-webkit-animation-duration: 3.35s;
animation-duration: 3.35s;
-webkit-animation-delay: -1.4405s;
animation-delay: -1.4405s;
}
.tile:nth-of-type(11) {
margin: 2.94em -19.18em;
-webkit-animation-duration: 2.07s;
animation-duration: 2.07s;
-webkit-animation-delay: -0.9936s;
animation-delay: -0.9936s;
}
.tile:nth-of-type(12) {
955
margin: 2.94em -11.34em;
-webkit-animation-duration: 2.92s;
animation-duration: 2.92s;
-webkit-animation-delay: -2.6572s;
animation-delay: -2.6572s;
}
.tile:nth-of-type(13) {
margin: 2.94em -3.5em;
-webkit-animation-duration: 2.61s;
animation-duration: 2.61s;
-webkit-animation-delay: -1.7226s;
animation-delay: -1.7226s;
}
.tile:nth-of-type(14) {
margin: 2.94em 4.34em;
-webkit-animation-duration: 2.7s;
animation-duration: 2.7s;
-webkit-animation-delay: -0.432s;
animation-delay: -0.432s;
}
.tile:nth-of-type(15) {
margin: 2.94em 12.18em;
-webkit-animation-duration: 3.91s;
animation-duration: 3.91s;
-webkit-animation-delay: -2.1114s;
animation-delay: -2.1114s;
}
@-webkit-keyframes a {
to {
-webkit-filter: brightness(200%) saturate(0);
filter: brightness(200%) saturate(0);
}
}
@keyframes a {
to {
-webkit-filter: brightness(200%) saturate(0);
filter: brightness(200%) saturate(0);
}
}
</style></head><body>
<div class='wrapper'>
<video autoplay loop muted src='https://s3-us-west-
2.amazonaws.com/s.cdpn.io/2017/video_ex_flower_640x360.mp4'></video>
<div class='tiles'>
<div class='tile'></div>
<div class='tile'></div>
<div class='tile'></div>
<div class='tile'></div>
<div class='tile'></div>
<div class='tile'></div>
<div class='tile'></div>
<div class='tile'></div>
<div class='tile'></div>
<div class='tile'></div>
<div class='tile'></div>
<div class='tile'></div>
956
<div class='tile'></div>
<div class='tile'></div>
<div class='tile'></div>
</div>
</div>
*****************************************************************************
Video reflection
<style class="cp-pen-styles">
html {
height: 100vh;
background-color: white;
}
.reflected {
display: inline-block;
position: relative;
margin-right: 1em;
width: 16em;
height: 10em;
/* WebKit-only solution */
-webkit-box-reflect: below 0.25em linear-gradient(transparent, white);
/**/
/* Firefox-only solution */
}
.reflected:after {
position: absolute;
top: calc(100% + 0.25em);
left: 0;
width: inherit;
height: inherit;
transform: scaleY(-1);
/* only works in Firefox */
mask: url(#m);
/**/
content: '';
}
img, video {
width: inherit;
height: inherit;
object-fit: cover;
}
#vid:after {
background: -moz-element(#vid);
}
</style></head><body>
957
<div id="pic" class="reflected"><img src="https://s3-us-west-
2.amazonaws.com/s.cdpn.io/2017/tiger.jpg"/></div>
<div id="vid" class="reflected">
<video src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/2017/video_ex_flower_640x360.mp4"
loop="loop" autoplay="autoplay" muted="muted"></video>
</div>
<svg>
<linearGradient id="lg" gradientTransform="rotate(90)">
<stop offset="0%" stop-color="#000"></stop>
<stop offset="100%" stop-color="#fff"></stop>
</linearGradient>
<mask id="m" maskContentUnits="objectBoundingBox">
<rect width="1" height="1" fill="url(#lg)"></rect>
</mask>
</svg>
*****************************************************************************
HTML page
<style class="cp-pen-styles"></style></head><body>
<HTML>
<HEAD>
<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
</HEAD>
<body>
<style>
@import url(http://fonts.googleapis.com/css?family=Droid+Sans);
</style>
958
<td width="47%"> </td>
<td width="47%"> </td>
<td width="3%"> </td>
</tr>
<tr>
<td> </td>
<td>
<a href="https://en.wikipedia.org/wiki/Albert_Einstein"><img
alt="Republic Wireless" height="91" src="https://colorlib.com/wp/wp-
content/uploads/sites/2/2013/10/BoldMedia-flat-logo.png" width="122"></a>
</td>
<td align="right">
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</tbody>
</table>
<!-- End Masthead -->
<!-- Begin Body -->
959
Papin, inventor of a type of high-pressure cooker that was a forerunner of the steam engine and
pressure cooker <em>awesome</em>.</p>
</td>
<td width="6%"> </td>
<td width="3%"> </td>
</tr>
</tbody>
</table>
960
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr align="center" valign="middle">
<td height="50" width="21%"> </td>
<td width="7%"> </td>
<td width="7%"> </td>
<td width="7%"> </td>
<td width="7%"> </td>
<td width="7%"> </td>
<td width="7%"> </td>
<td width="21%"> </td>
</tr>
<td width="50">
<a href="http://physicsworld.com/"><img alt="Facebook"
height="34"
src="http://image.mail.republicwireless.com/lib/fe9a13707560007f71/m/1/eml_img_bw_social-
facebook_bw.png" width="34"></a>
</td>
<td width="50">
<a href="http://physicsworld.com/"><img alt="Twitter" height="34"
src="http://image.mail.republicwireless.com/lib/fe9a13707560007f71/m/1/eml_img_bw_social-
twitter.png" width="34"></a>
</td>
<td width="50">
<a href="http://physicsworld.com/"><img alt="Google" height="34"
src="http://image.mail.republicwireless.com/lib/fe9a13707560007f71/m/1/eml_img_bw_social-
google.png" width="34"></a>
</td>
<td width="50">
<a href="http://physicsworld.com/"><img alt="Pinterest"
height="34"
src="http://image.mail.republicwireless.com/lib/fe9a13707560007f71/m/1/eml_img_bw_social-
pinterest.png" width="34"></a>
</td>
<td width="50">
<a href="http://physicsworld.com/"><img alt="YouTube" height="34"
src="http://image.mail.republicwireless.com/lib/fe9a13707560007f71/m/1/eml_img_bw_social-
youtube.png" width="34"></a>
</td>
<td width="50">
<a href="http://physicsworld.com/"><img alt="Instagram"
height="34"
961
src="http://image.mail.republicwireless.com/lib/fe9a13707560007f71/m/1/eml_img_bw_social-
instagram.png" width="34"></a>
</td>
<td> </td>
</tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</tbody>
</table>
<!-- End Social -->
<!-- Begin Footer Links -->
<tr>
<td height="50"> </td>
<td> </td>
<td> </td>
</tr>
</tbody>
</table>
<!-- End Footer Links -->
962
</div>
</td>
</tr>
<tr>
<td>
<table style="background: #ccc;" width="650px" border="0" cellspacing="0"
cellpadding="0">
<tr>
<td width="325px"><img align="bottom" border="0"
src="http://image.mail.republicwireless.com/lib/fe9a13707560007f71/m/1/spacer.png"
style="margin:0;margin-right:0px;margin-left:0px;padding:0;background:none;border:none;white-
space:normal;line-height:normal;vertical-align:bottom;min-width:325px;min-
height:1px;display:block"
width="325px" height="1"></td>
<td width="325px"><img align="bottom" border="0"
src="http://image.mail.republicwireless.com/lib/fe9a13707560007f71/m/1/spacer.png"
style="margin:0;margin-right:0px;margin-left:0px;padding:0;background:none;border:none;white-
space:normal;line-height:normal;vertical-align:bottom;min-width:325px;min-
height:1px;display:block"
width="325px" height="1"></td>
</tr>
</table>
</td>
</tr>
</tbody>
</table>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<img
src="http://trk.kissmetrics.com/e?_k=8216fa8d8852d2c65f72f2df6769d06698af5df4&_n=Viewed+Email&_p=
[email protected]">
<table cellpadding="2" cellspacing="0" width="600" align="center">
<tr>
<td>
<font face="verdana" size="1" color="#777777">
This email was sent to: <b>[email protected]</b><br><br>
<table cellpadding="2" cellspacing="0" width="450" ID="Table1" Border=0>
<tr>
<td>
<font face="verdana" size="1" color="#777777">
This email was sent by: Republic Wireless<br> 900 Main Campus Drive, Suite 500
Raleigh, NC 27606 USA
</font>
</td>
</tr>
</table><br><br> We respect your right to privacy - <a href="http://physicsworld.com/"
style="color: #0000ff">view our policy</a>
</font>
</td>
</tr>
</table>
963
*****************************************************************************
Title Animation
<style class="cp-pen-styles">
html,
body {
width: 100%;
height: 100%;
}
body {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-box-align: center;
-webkit-align-items: center;
-ms-flex-align: center;
align-items: center;
-webkit-box-pack: center;
-webkit-justify-content: center;
-ms-flex-pack: center;
justify-content: center;
background: #262626;
}
.title {
position: relative;
-webkit-perspective: 400;
perspective: 400;
padding-left: 17px;
font-family: Arial;
font-weight: bold;
font-size: 52px;
text-transform: uppercase;
color: #fff;
}
.title:before {
content: '';
display: block;
position: absolute;
height: 100%;
width: 6px;
background: #ff1212;
top: 0;
left: 0;
opacity: 0;
-webkit-transform: translateX(-150px);
transform: translateX(-150px);
-webkit-animation: title-border-slide-in 0.35s ease-out forwards;
animation: title-border-slide-in 0.35s ease-out forwards;
}
.title .title-word {
opacity: 0;
-webkit-transform-origin: bottom center;
transform-origin: bottom center;
964
-webkit-transform: rotateX(-90deg);
transform: rotateX(-90deg);
}
.title .title-word:nth-child(1) {
-webkit-animation: roll-in 0.15s 0s ease-out forwards;
animation: roll-in 0.15s 0s ease-out forwards;
}
.title .title-word:nth-child(2) {
-webkit-animation: roll-in 0.15s 0.175s ease-out forwards;
animation: roll-in 0.15s 0.175s ease-out forwards;
}
.title .title-word:nth-child(3) {
-webkit-animation: roll-in 0.15s 0.35s ease-out forwards;
animation: roll-in 0.15s 0.35s ease-out forwards;
}
.title .title-word:nth-child(4) {
-webkit-animation: roll-in 0.15s 0.525s ease-out forwards;
animation: roll-in 0.15s 0.525s ease-out forwards;
}
@-webkit-keyframes title-border-slide-in {
0% {
-webkit-transform: translateX(-150px);
transform: translateX(-150px);
opacity: 0;
}
100% {
-webkit-transform: translateX(0);
transform: translateX(0);
opacity: 1;
}
}
@keyframes title-border-slide-in {
0% {
-webkit-transform: translateX(-150px);
transform: translateX(-150px);
opacity: 0;
}
100% {
-webkit-transform: translateX(0);
transform: translateX(0);
opacity: 1;
}
}
@-webkit-keyframes roll-in {
0% {
-webkit-transform: rotateX(-90deg);
transform: rotateX(-90deg);
opacity: 1;
}
100% {
-webkit-transform: rotateX(0deg);
transform: rotateX(0deg);
opacity: 1;
}
}
@keyframes roll-in {
0% {
-webkit-transform: rotateX(-90deg);
965
transform: rotateX(-90deg);
opacity: 1;
}
100% {
-webkit-transform: rotateX(0deg);
transform: rotateX(0deg);
opacity: 1;
}
}
</style></head><body>
<div class="title">
<div class="title-word">Stephen</div>
<div class="title-word">William</div>
<div class="title-word">Hawking</div>
</div>
</body>
*****************************************************************************
Solar System
<style class="cp-pen-styles">
html, body {
height: 100%;
}
body {
display: flex;
justify-content: center;
align-items: center;
background-color: #000;
color: #fff;
perspective: 4000px;
}
body::before {
position: absolute;
top: 0;
left: 0;
width: 2px;
height: 2px;
box-shadow: 69vw 11vh #fff, 52vw 86vh #fff, 27vw 75vh #fff, 15vw 60vh #fff, 79vw 28vh #fff,
34vw 10vh #fff, 44vw 100vh #fff, 2vw 19vh #fff, 72vw 77vh #fff, 9vw 25vh #fff, 30vw 99vh #fff,
39vw 75vh #fff, 67vw 55vh #fff, 11vw 1vh #fff, 98vw 40vh #fff, 95vw 34vh #fff, 89vw 8vh #fff, 3vw
79vh #fff, 48vw 8vh #fff, 23vw 48vh #fff, 12vw 93vh #fff, 1vw 34vh #fff, 20vw 30vh #fff, 33vw
82vh #fff, 43vw 68vh #fff, 88vw 62vh #fff, 8vw 74vh #fff, 98vw 62vh #fff, 28vw 88vh #fff, 38vw
59vh #fff, 23vw 90vh #fff, 93vw 81vh #fff, 85vw 17vh #fff, 25vw 17vh #fff, 75vw 65vh #fff, 27vw
14vh #fff, 75vw 93vh #fff, 6vw 7vh #fff, 45vw 47vh #fff, 69vw 59vh #fff, 53vw 6vh #fff, 47vw 86vh
#fff, 30vw 65vh #fff, 45vw 73vh #fff, 86vw 1vh #fff, 78vw 44vh #fff, 70vw 34vh #fff, 56vw 66vh
#fff, 21vw 4vh #fff, 38vw 92vh #fff, 61vw 4vh #fff, 52vw 53vh #fff, 43vw 75vh #fff, 30vw 82vh
#fff, 65vw 27vh #fff, 75vw 24vh #fff, 13vw 77vh #fff, 81vw 11vh #fff, 67vw 7vh #fff, 79vw 79vh
#fff, 23vw 87vh #fff, 57vw 20vh #fff, 68vw 61vh #fff, 24vw 52vh #fff, 19vw 16vh #fff, 51vw 27vh
#fff, 53vw 13vh #fff, 34vw 86vh #fff, 7vw 96vh #fff, 51vw 79vh #fff, 91vw 23vh #fff, 8vw 52vh
#fff, 94vw 47vh #fff, 16vw 34vh #fff, 99vw 24vh #fff, 65vw 12vh #fff, 3vw 29vh #fff, 28vw 27vh
966
#fff, 42vw 58vh #fff, 46vw 41vh #fff, 19vw 17vh #fff, 3vw 60vh #fff, 94vw 13vh #fff, 55vw 36vh
#fff, 58vw 26vh #fff, 19vw 52vh #fff, 95vw 22vh #fff, 28vw 38vh #fff, 49vw 68vh #fff, 63vw 76vh
#fff, 95vw 69vh #fff, 37vw 86vh #fff, 94vw 88vh #fff, 33vw 49vh #fff, 31vw 74vh #fff, 4vw 75vh
#fff, 8vw 14vh #fff, 10vw 98vh #fff, 2vw 9vh #fff, 53vw 85vh #fff, 39vw 33vh #fff, 14vw 66vh
#fff, 67vw 42vh #fff, 47vw 10vh #fff, 70vw 92vh #fff, 58vw 1vh #fff, 35vw 86vh #fff, 12vw 44vh
#fff, 59vw 33vh #fff, 99vw 10vh #fff, 60vw 34vh #fff, 62vw 44vh #fff, 66vw 34vh #fff, 44vw 41vh
#fff, 16vw 74vh #fff, 66vw 99vh #fff, 71vw 9vh #fff, 3vw 47vh #fff, 94vw 65vh #fff, 40vw 24vh
#fff, 100vw 73vh #fff, 64vw 26vh #fff, 3vw 47vh #fff, 70vw 23vh #fff, 65vw 38vh #fff, 1vw 94vh
#fff, 77vw 97vh #fff, 57vw 33vh #fff, 27vw 18vh #fff, 96vw 95vh #fff, 13vw 52vh #fff, 33vw 24vh
#fff, 53vw 76vh #fff, 18vw 44vh #fff, 46vw 100vh #fff, 78vw 3vh #fff, 32vw 51vh #fff, 89vw 37vh
#fff, 81vw 73vh #fff, 49vw 21vh #fff, 40vw 87vh #fff, 95vw 6vh #fff, 50vw 35vh #fff, 55vw 28vh
#fff, 19vw 70vh #fff, 43vw 50vh #fff, 75vw 8vh #fff, 48vw 1vh #fff, 69vw 65vh #fff, 40vw 6vh
#fff, 22vw 79vh #fff, 16vw 45vh #fff, 71vw 5vh #fff, 30vw 66vh #fff, 42vw 7vh #fff, 58vw 72vh
#fff, 43vw 84vh #fff, 6vw 66vh #fff, 39vw 9vh #fff, 19vw 9vh #fff, 27vw 4vh #fff, 48vw 11vh #fff,
66vw 94vh #fff, 62vw 78vh #fff, 80vw 57vh #fff, 11vw 23vh #fff, 22vw 72vh #fff, 18vw 96vh #fff,
1vw 27vh #fff, 28vw 75vh #fff, 39vw 14vh #fff, 71vw 85vh #fff, 6vw 24vh #fff, 69vw 10vh #fff,
13vw 57vh #fff, 29vw 12vh #fff, 70vw 40vh #fff, 37vw 55vh #fff, 93vw 31vh #fff, 24vw 19vh #fff,
67vw 46vh #fff, 84vw 52vh #fff, 31vw 91vh #fff, 17vw 49vh #fff, 49vw 2vh #fff, 42vw 78vh #fff,
80vw 10vh #fff, 57vw 20vh #fff, 2vw 73vh #fff, 22vw 16vh #fff, 74vw 40vh #fff, 73vw 36vh #fff,
100vw 36vh #fff, 100vw 18vh #fff, 70vw 76vh #fff, 58vw 43vh #fff, 20vw 60vh #fff, 65vw 2vh #fff,
52vw 36vh #fff, 91vw 31vh #fff;
content: '';
}
.Solarsystem {
position: relative;
width: 40px;
height: 40px;
background-color: #ff0;
border-radius: 50%;
box-shadow: 0 0 40px #ff0;
transform: rotateX(60deg);
}
.Planet {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
border-radius: 50%;
box-shadow: 0 0 0 1px #fff;
text-align: center;
}
.Planet::before {
position: absolute;
left: 50%;
top: 0;
border-radius: 50%;
content: '';
}
.Planet--mercury {
width: 64px;
height: 64px;
}
.Planet--mercury::before {
width: 16px;
height: 16px;
967
margin: -8px;
background-color: #ffa700;
transform-origin: center 40px;
animation: rotate 0.53204s linear infinite;
}
.Planet--venus {
width: 112px;
height: 112px;
}
.Planet--venus::before {
width: 20px;
height: 20px;
margin: -10px;
background-color: #0fb;
transform-origin: center 66px;
animation: rotate 1.35899s linear infinite;
}
.Planet--earth {
width: 160px;
height: 160px;
}
.Planet--earth::before {
width: 24px;
height: 24px;
margin: -12px;
background-color: #00f;
transform-origin: center 92px;
animation: rotate 2.20903s linear infinite;
}
.Planet--mars {
width: 240px;
height: 240px;
}
.Planet--mars::before {
width: 20px;
height: 20px;
margin: -10px;
background-color: #f00;
transform-origin: center 130px;
animation: rotate 4.15475s linear infinite;
}
.Planet--jupiter {
width: 480px;
height: 480px;
}
.Planet--jupiter::before {
width: 32px;
height: 32px;
margin: -16px;
background-color: #0f7;
transform-origin: center 256px;
animation: rotate 26.2031s linear infinite;
}
968
.Planet--saturn {
width: 560px;
height: 560px;
}
.Planet--saturn::before {
width: 30px;
height: 30px;
margin: -15px;
background-color: #ff8;
transform-origin: center 295px;
animation: rotate 65.07168s linear infinite;
}
.Planet--saturn::after {
position: absolute;
left: 50%;
top: 0;
content: '';
width: 33px;
height: 33px;
margin: -16.5px;
border-radius: 50%;
box-shadow: 0 0 0 4.5px #fff;
transform-origin: center 296.5px;
animation: rotate 65.07168s linear infinite;
}
.Planet--uranus {
width: 720px;
height: 720px;
}
.Planet--uranus::before {
width: 16px;
height: 16px;
margin: -8px;
background-color: #f6f;
transform-origin: center 368px;
animation: rotate 185.60397s linear infinite;
}
.Planet--neptun {
width: 960px;
height: 960px;
}
.Planet--neptun::before {
width: 12px;
height: 12px;
margin: -6px;
background-color: #06f;
transform-origin: center 486px;
animation: rotate 364.04847s linear infinite;
}
@keyframes rotate {
to {
transform: rotate(360deg);
}
}
</style></head><body>
969
<div class="Solarsystem">
<div class="Planet Planet--mercury">
<!--= planet.toUpperCase()-->
</div>
<div class="Planet Planet--venus">
<!--= planet.toUpperCase()-->
</div>
<div class="Planet Planet--earth">
<!--= planet.toUpperCase()-->
</div>
<div class="Planet Planet--mars">
<!--= planet.toUpperCase()-->
</div>
<div class="Planet Planet--jupiter">
<!--= planet.toUpperCase()-->
</div>
<div class="Planet Planet--saturn">
<!--= planet.toUpperCase()-->
</div>
<div class="Planet Planet--uranus">
<!--= planet.toUpperCase()-->
</div>
<div class="Planet Planet--neptun">
<!--= planet.toUpperCase()-->
</div>
</div>
*****************************************************************************
<style class="cp-pen-styles">
@font-face {
font-family: 'Calluna';
src: url("https://s3-us-west-2.amazonaws.com/s.cdpn.io/4273/CallunaSansRegular.otf")
format("opentype");
}
* {
box-sizing: border-box;
}
body {
font-family: Calluna, Arial, sans-serif;
background: -webkit-linear-gradient(rgba(255, 255, 255, 0), rgba(255, 255, 255, 0)),
url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/4273/times-square-perspective.jpg);
background: linear-gradient(rgba(255, 255, 255, 0), rgba(255, 255, 255, 0)), url(https://s3-us-
west-2.amazonaws.com/s.cdpn.io/4273/times-square-perspective.jpg);
background-repeat: no-repeat;
background-attachment: fixed !important;
background-size: 100% !important;
background-position: center top !important;
padding: 1rem;
padding-top: 45%;
color: #fff;
970
}
h1 {
font-size: 4rem;
text-shadow: 0 0 5px rgba(0, 0, 0, 0.5);
line-height: 1;
position: absolute;
top: 10px;
font-weight: 100;
}
p {
font-size: 1.3rem;
text-align: left;
line-height: 1.6;
margin-left: 8rem;
margin-right: 8rem;
color: #000;
}
h2 {
text-align: center;
text-transform: uppercase;
margin-bottom: 0;
}
span {
display: block;
margin: 0;
text-align: center;
font-size: 3rem;
}
</style></head><body>
<h1>New York Stories</h1>
<h2>Scroll</h2>
<span id="directionality">▼</span>
<p>In my younger and more vulnerable years my father gave me some advice that I've been turning
over in my mind ever since.
<p>"Whenever you feel like criticizing anyone," he told me, "just remember that all the people in
this world haven't had the advantages that you've had."
<p>He didn't say any more but we've always been unusually communicative in a reserved way, and I
understood that he meant a great deal more than that. In consequence I'm inclined to reserve all
judgments, a habit that has opened up many curious natures to me and also made me the victim of
not a few veteran bores. The abnormal mind is quick to detect and attach itself to this quality
when it appears in a normal person, and so it came about that in college I was unjustly accused
of being a politician, because I was privy to the secret griefs of wild, unknown men. Most of the
confidences were unsought--frequently I have feigned sleep, preoccupation, or a hostile levity
when I realized by some unmistakable sign that an intimate revelation was quivering on the
horizon--for the intimate revelations of young men or at least the terms in which they express
them are usually plagiaristic and marred by obvious suppressions. Reserving judgments is a matter
of infinite hope. I am still a little afraid of missing something if I forget that, as my father
snobbishly suggested, and I snobbishly repeat a sense of the fundamental decencies is parcelled
out unequally at birth.
<p>And, after boasting this way of my tolerance, I come to the admission that it has a limit.
Conduct may be founded on the hard rock or the wet marshes, but after a certain point I don’t
care what it’s founded on. When I came back from the East last autumn I felt that I wanted the
world to be in uniform and at a sort of moral attention forever; I wanted no more riotous
excursions with privileged glimpses into the human heart. Only Gatsby, the man who gives his name
971
to this book, was exempt from my reaction — Gatsby, who represented everything for which I have
an unaffected scorn. If personality is an unbroken series of successful gestures, then there was
something gorgeous about him, some heightened sensitivity to the promises of life, as if he were
related to one of those intricate machines that register earthquakes ten thousand miles away.
This responsiveness had nothing to do with that flabby impressionability which is dignified under
the name of the “creative temperament.”— it was an extraordinary gift for hope, a romantic
readiness such as I have never found in any other person and which it is not likely I shall ever
find again. No — Gatsby turned out all right at the end; it is what preyed on Gatsby, what foul
dust floated in the wake of his dreams that temporarily closed out my interest in the abortive
sorrows and short-winded elations of men.
</script>
*****************************************************************************
<style class="cp-pen-styles">
body, html {
margin: 0;
font-family: arial;
height: 100vh;
background: #ccc;
}
*, *:before, *:after {
box-sizing: border-box;
}
.nav-mobile {
position: fixed;
top: 0;
left: 0;
width: 100%;
background: #446CB3;
color: #FFF;
padding: 0;
margin: 0;
cursor: auto;
font-size: 18px;
list-style-type: none;
z-index: 999999;
box-shadow: 0 5px 5px -5px #333;
}
972
.nav-mobile:after {
content: "";
display: table;
clear: both;
}
.nav-mobile svg {
height: 45px;
width: 65px;
padding: 9px;
}
.nav-mobile svg path {
fill: #fff;
}
.nav-mobile svg.icon-close {
display: none;
padding: 15px;
}
.nav-mobile li {
width: 100%;
height: 45px;
line-height: 46px;
text-align: center;
float: left;
}
.nav-mobile li a {
display: block;
color: #333;
width: 100%;
height: 100%;
text-decoration: none;
}
.nav-mobile .menu-button {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
margin: 0;
cursor: pointer;
display: block;
}
.nav-mobile .menu-button:after {
opacity: 0;
top: 45px;
content: "";
width: 100vw;
display: block;
position: fixed;
height: 100vh;
background: rgba(0, 0, 0, 0.5);
content: "";
z-index: 9;
pointer-events: none;
transition: opacity 0.2s cubic-bezier(0, 0, 0.3, 1);
transition-delay: 0.1s;
}
.nav-mobile #menu-toggle {
display: none;
973
}
.nav-mobile #menu-toggle.active ~ .menu-button .icon-close, .nav-mobile #menu-toggle:checked ~
.menu-button .icon-close {
display: block;
}
.nav-mobile #menu-toggle.active ~ .menu-button .icon-open, .nav-mobile #menu-toggle:checked ~
.menu-button .icon-open {
display: none;
}
.nav-mobile #menu-toggle.active ~ .menu-button:after, .nav-mobile #menu-toggle:checked ~ .menu-
button:after {
opacity: 1;
pointer-events: auto;
transition: opacity 0.3s cubic-bezier(0, 0, 0.3, 1);
}
.nav-mobile #menu-toggle.active ~ .menu-sidebar, .nav-mobile #menu-toggle:checked ~ .menu-sidebar
{
transform: translateX(0);
transition: transform 0.3s cubic-bezier(0, 0, 0.3, 1);
}
.nav-mobile .menu-container {
width: 65px;
float: left;
cursor: pointer;
position: absolute;
}
.nav-mobile .menu-container .menu-sidebar {
box-shadow: 5px 0 5px -5px #333;
display: block;
width: 65vw;
bottom: 0;
background: white;
color: #333;
position: fixed;
z-index: 9999999;
transform: translateX(-405px);
transition: transform 0.3s cubic-bezier(0, 0, 0.3, 1);
top: 45px;
list-style-type: none;
padding: 0;
max-width: 400px;
}
.nav-mobile .menu-container .menu-sidebar .arrow {
position: absolute;
line-height: 50px;
font-size: 32px;
color: #555;
top: 0;
z-index: 0;
}
.nav-mobile .menu-container .menu-sidebar .arrow.left {
left: 25px;
}
.nav-mobile .menu-container .menu-sidebar .arrow.right {
right: 25px;
}
.nav-mobile .menu-container .menu-sidebar li {
height: 55px;
974
line-height: 55px;
font-size: 16px;
text-align: left;
position: relative;
border-bottom: 1px solid rgba(0, 0, 0, 0.1);
padding-left: 20px;
}
.nav-mobile .menu-container .menu-sidebar li:hover {
background: #eee;
}
.nav-mobile .menu-container .menu-sidebar li .menu-sub {
position: fixed;
top: 0;
right: 0;
bottom: 0;
width: 0;
overflow: hidden;
background: white;
visibility: hidden;
transition: all 0.3s cubic-bezier(0, 0, 0.3, 1);
border-left: 1px solid #ccc;
list-style-type: none;
padding: 0;
margin: 0;
z-index: 2;
max-width: 400px;
}
.nav-mobile .menu-container .menu-sidebar li .menu-sub li {
overflow: hidden;
}
.nav-mobile .menu-container .menu-sidebar li .menu-sub .menu-sub-title {
padding-left: 50px;
}
.nav-mobile .menu-container .menu-sidebar li .submenu-label {
cursor: pointer;
width: 100%;
height: 100%;
display: block;
}
.nav-mobile .menu-container .menu-sidebar li .submenu-toggle {
display: none;
}
.nav-mobile .menu-container .menu-sidebar li .submenu-toggle.active ~ .menu-sub, .nav-mobile
.menu-container .menu-sidebar li .submenu-toggle:checked ~ .menu-sub {
width: 65vw;
visibility: visible;
z-index: 1;
transition: width 0.35s cubic-bezier(0, 0, 0.3, 1);
}
.carousel-container {
list-style-type: none;
padding: 0;
margin: 30px auto;
width: 550px;
height: 338px;
border-radius: 5px;
position: relative;
975
z-index: 0;
}
.carousel-container .arrow {
cursor: pointer;
background: rgba(0, 0, 0, 0.5);
color: rgba(255, 255, 255, 0.5);
display: block;
width: 50px;
font-size: 62px;
text-align: center;
bottom: 0;
top: 0;
line-height: 330px;
position: absolute;
z-index: 9999;
padding-bottom: 4px;
padding-top: 2px;
border-radius: 2px;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
.carousel-container .arrow.next {
left: 0px;
background: linear-gradient(to right, rgba(0, 0, 0, 0.5), transparent);
}
.carousel-container .arrow.back {
right: 0px;
background: linear-gradient(to left, rgba(0, 0, 0, 0.5), transparent);
}
.carousel-container .arrow:hover {
color: white;
}
.carousel-container li:nth-child(1) > .dot {
margin-left: 44.6%;
}
.carousel-container .carousel-content {
height: 0;
overflow: hidden;
line-height: 22px;
background: #000;
position: absolute;
top: 0px;
border-radius: 5px;
box-shadow: 0 5px 5px -5px #333;
list-style-type: none;
padding: 0;
}
.carousel-container .carousel-content img {
opacity: 0;
padding: 0;
position: absolute;
left: 0;
top: 0;
width: 100%;
border-radius: 5px;
transition: 0.2s ease-in;
976
}
.carousel-container .dot {
float: left;
cursor: pointer;
opacity: 1;
width: 12px;
height: 12px;
background: rgba(255, 255, 255, 0.5);
position: relative;
margin-top: 56%;
border-radius: 50%;
z-index: 999;
margin-right: 8px;
display: block;
}
.carousel-container .dot:hover {
background: #fff;
}
.carousel-container .carousel-toggle {
display: none;
}
.carousel-container .carousel-toggle:checked + .dot, .carousel-container .carousel-toggle.active
+ .dot {
background: #fff;
}
.carousel-container .carousel-toggle:checked ~ .carousel-content, .carousel-container .carousel-
toggle.active ~ .carousel-content {
height: 100%;
width: 100%;
}
.carousel-container .carousel-toggle:checked ~ .carousel-content img, .carousel-container
.carousel-toggle.active ~ .carousel-content img {
opacity: 1;
}
.tab-container {
list-style-type: none;
padding: 0;
margin: 60px auto;
max-width: 350px;
position: relative;
background: #fff;
}
.tab-container:after {
content: "";
display: table;
clear: both;
}
.tab-container ul {
list-style-type: none;
padding: 0;
}
.tab-container .arrows {
display: block;
width: 60px;
font-size: 32px;
bottom: 10px;
right: 0px;
977
position: absolute;
}
.tab-container .arrows label {
display: inline-block;
cursor: pointer;
color: #aaa;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
margin-left: 5px;
}
.tab-container .arrows label:hover {
color: #333;
}
.tab-container .tab-content-container {
border-bottom-left-radius: 4px;
border-bottom-right-radius: 4px;
height: 0;
opacity: 0;
overflow: hidden;
line-height: 22px;
background: #fff;
position: absolute;
top: 42px;
padding: 0px 40px 0 20px;
border: 2px solid #446CB3;
border-top: 0;
box-shadow: 0 5px 5px -5px #333;
}
.tab-container .tab-content-container .tab-content {
opacity: 0;
padding: 15px 0;
min-height: 185px;
transition: opacity 0.1s ease-in;
}
.tab-container .tab {
outline: 0;
float: left;
cursor: pointer;
opacity: 1;
width: 25%;
line-height: 40px;
display: block;
margin: 0;
position: relative;
background: #446CB3;
color: #fff;
text-align: center;
border-top: 2px solid #446CB3;
border-right: 2px solid #446CB3;
}
.tab-container .tab.l-b {
border-left: 2px solid #446CB3;
}
.tab-container .tab:hover {
background: #365690;
}
978
.tab-container .tab-toggle {
display: none;
}
.tab-container .tab-toggle.active + .tab, .tab-container .tab-toggle:checked + .tab {
background: #fff;
color: #333;
}
.tab-container .tab-toggle.active ~ .tab-content-container, .tab-container .tab-toggle:checked ~
.tab-content-container {
height: auto;
opacity: 1;
}
.tab-container .tab-toggle.active ~ .tab-content-container .tab-content, .tab-container .tab-
toggle:checked ~ .tab-content-container .tab-content {
opacity: 1;
}
.tab-container .tab-toggle.active ~ .tab-content-container .tab-content label, .tab-container
.tab-toggle:checked ~ .tab-content-container .tab-content label {
opacity: 1;
}
.accordion-container {
width: 300px;
margin: 60px auto;
border: 2px solid #446CB3;
border-radius: 4px;
box-shadow: 0 5px 5px -5px #333;
list-style-type: none;
padding: 0;
}
.accordion-container ul {
list-style-type: none;
padding-left: 0;
}
.accordion-container .accordion-category {
position: relative;
background: #fff;
}
.accordion-container .accordion-category .accordion-title {
padding-left: 20px;
height: 40px;
font-size: 18px;
line-height: 40px;
background: #446CB3;
color: #fff;
position: relative;
display: block;
cursor: pointer;
}
.accordion-container .accordion-category .accordion-title:hover {
background: #365690;
}
.accordion-container .accordion-category .accordion-items {
max-height: 0;
height: 0;
margin: 0;
overflow: hidden;
transition: 0.6s ease-in;
979
}
.accordion-container .accordion-category .accordion-items li {
padding: 5px 20px;
}
.accordion-container .accordion-category .accordion-items li:first-child {
padding-top: 10px;
}
.accordion-container .accordion-category .accordion-items li:last-child {
padding-bottom: 10px;
}
.accordion-container .accordion-category input {
display: none;
}
.accordion-container .accordion-category input.active ~ .accordion-items, .accordion-container
.accordion-category input:checked ~ .accordion-items {
height: auto;
max-height: 900px;
-webkit-transform: translate3d(0, 0, 0);
}
.accordion-container .accordion-category input.active ~ .accordion-title:after, .accordion-
container .accordion-category input:checked ~ .accordion-title:after, .accordion-container
.accordion-category input:hover ~ .accordion-title:after {
content: "\203A";
position: absolute;
width: 40px;
font-size: 32px;
right: 0;
padding-left: 15px;
top: 0;
bottom: 0;
transform: rotate(90deg);
}
.modal-container {
margin: 60px auto;
padding-top: 0px;
position: relative;
width: 160px;
}
.modal-container .modal-btn {
display: block;
margin: 0 auto;
color: #fff;
width: 160px;
height: 50px;
line-height: 50px;
background: #446CB3;
font-size: 22px;
border: 0;
border-radius: 3px;
cursor: pointer;
text-align: center;
box-shadow: 0 5px 5px -5px #333;
transition: background 0.3s ease-in;
}
.modal-container .modal-btn:hover {
background: #365690;
}
980
.modal-container .modal-content,
.modal-container .modal-backdrop {
height: 0;
width: 0;
opacity: 0;
visibility: hidden;
overflow: hidden;
cursor: pointer;
transition: opacity 0.2s ease-in;
}
.modal-container .modal-close {
color: #aaa;
position: absolute;
right: 5px;
top: 5px;
padding-top: 3px;
background: #fff;
font-size: 16px;
width: 25px;
height: 25px;
font-weight: bold;
text-align: center;
cursor: pointer;
}
.modal-container .modal-close:hover {
color: #333;
}
.modal-container .modal-content-btn {
position: absolute;
text-align: center;
cursor: pointer;
bottom: 20px;
right: 30px;
background: #446CB3;
color: #fff;
width: 50px;
border-radius: 2px;
font-size: 14px;
height: 32px;
padding-top: 9px;
font-weight: normal;
}
.modal-container .modal-content-btn:hover {
color: #fff;
background: #365690;
}
.modal-container #modal-toggle {
display: none;
}
.modal-container #modal-toggle.active ~ .modal-backdrop, .modal-container #modal-toggle:checked ~
.modal-backdrop {
background-color: rgba(0, 0, 0, 0.6);
width: 100vw;
height: 100vh;
position: fixed;
left: 0;
top: 0;
z-index: 9;
981
visibility: visible;
opacity: 1;
transition: opacity 0.2s ease-in;
}
.modal-container #modal-toggle.active ~ .modal-content, .modal-container #modal-toggle:checked ~
.modal-content {
opacity: 1;
background-color: #fff;
max-width: 400px;
width: 400px;
height: 280px;
padding: 10px 30px;
position: fixed;
left: calc(50% - 200px);
top: 12%;
border-radius: 4px;
z-index: 999;
pointer-events: auto;
cursor: auto;
visibility: visible;
box-shadow: 0 3px 7px rgba(0, 0, 0, 0.6);
}
@media (max-width: 400px) {
.modal-container #modal-toggle.active ~ .modal-content, .modal-container #modal-toggle:checked
~ .modal-content {
left: 0;
}
}
.tooltip-container {
margin: 60px auto;
padding-top: 0px;
position: relative;
width: 160px;
}
.tooltip-container .tooltip-btn {
display: block;
margin: 0 auto;
color: #fff;
width: 160px;
height: 50px;
line-height: 50px;
background: #446CB3;
font-size: 22px;
border: 0;
border-radius: 3px;
cursor: pointer;
text-align: center;
box-shadow: 0 5px 5px -5px #333;
transition: background 0.3s ease-in;
}
.tooltip-container .tooltip-btn:hover {
background: #365690;
}
.tooltip-container .tooltip-btn.tooltip-toggle:hover ~ .tooltip-content {
opacity: 1;
background-color: #fff;
max-width: 400px;
982
width: 200px;
min-height: 70px;
padding: 0px 20px;
position: absolute;
left: calc(50% - 100px);
top: 145%;
border-radius: 4px;
z-index: 999;
pointer-events: auto;
cursor: auto;
visibility: visible;
overflow: visible;
box-shadow: 0 3px 7px rgba(0, 0, 0, 0.6);
}
@media (max-width: 400px) {
.tooltip-container .tooltip-btn.tooltip-toggle:hover ~ .tooltip-content {
left: 0;
}
}
.tooltip-container .tooltip-btn.tooltip-toggle:hover ~ .tooltip-content:before {
content: "";
width: 0;
height: 0;
border-style: solid;
border-width: 0 10px 10px 10px;
border-color: transparent transparent #ffffff transparent;
position: absolute;
top: -10px;
left: 30px;
}
.tooltip-container .tooltip-content,
.tooltip-container .tooltip-backdrop {
height: 0;
width: 0;
opacity: 0;
visibility: hidden;
overflow: hidden;
transition: opacity 0.2s ease-in;
}
.tooltip-container #tooltip-toggle {
display: none;
}
.tooltip-container #tooltip-toggle.active ~ .tooltip-backdrop, .tooltip-container #tooltip-
toggle:checked ~ .tooltip-backdrop {
background-color: transparent;
width: 100vw;
height: 100vh;
position: fixed;
left: 0;
top: 0;
z-index: 9;
visibility: visible;
opacity: 1;
transition: opacity 0.2s ease-in;
}
.tooltip-container #tooltip-toggle.active ~ .tooltip-content, .tooltip-container #tooltip-
toggle:checked ~ .tooltip-content {
opacity: 1;
983
background-color: #fff;
max-width: 400px;
width: 200px;
min-height: 70px;
padding: 0px 20px;
position: absolute;
left: calc(50% - 100px);
top: 145%;
border-radius: 4px;
z-index: 999;
pointer-events: auto;
visibility: visible;
overflow: visible;
box-shadow: 0 3px 7px rgba(0, 0, 0, 0.6);
}
@media (max-width: 400px) {
.tooltip-container #tooltip-toggle.active ~ .tooltip-content, .tooltip-container #tooltip-
toggle:checked ~ .tooltip-content {
left: 0;
}
}
.tooltip-container #tooltip-toggle.active ~ .tooltip-content:before, .tooltip-container #tooltip-
toggle:checked ~ .tooltip-content:before {
content: "";
width: 0;
height: 0;
border-style: solid;
border-width: 0 10px 10px 10px;
border-color: transparent transparent #ffffff transparent;
position: absolute;
top: -10px;
left: 30px;
}
.star-container {
text-align: center;
font-size: 0;
}
.star-container label {
display: inline-block;
cursor: pointer;
}
.star-container label:after {
content: "\2605";
font-size: 46px;
color: #999;
text-shadow: 1px 1px 1px rgba(0, 0, 0, 0.3);
}
.star-container label:hover:after {
color: #F89406;
}
.star-container input {
display: none;
}
.star-container #one:checked ~ label[for=one]:after,
.star-container #two:checked ~ label[for=two]:after,
.star-container #three:checked ~ label[for=three]:after,
.star-container #four:checked ~ label[for=four]:after,
984
.star-container #five:checked ~ label[for=five]:after {
color: #F89406;
}
.star-container #two:checked ~ label[for=one]:after {
color: #F89406;
}
.star-container #three:checked ~ label[for=one]:after, .star-container #three:checked ~
label[for=two]:after {
color: #F89406;
}
.star-container #four:checked ~ label[for=one]:after, .star-container #four:checked ~
label[for=two]:after, .star-container #four:checked ~ label[for=three]:after {
color: #F89406;
}
.star-container #five:checked ~ label[for=one]:after, .star-container #five:checked ~
label[for=two]:after, .star-container #five:checked ~ label[for=three]:after, .star-container
#five:checked ~ label[for=four]:after {
color: #F89406;
}
.readmo {
width: 400px;
border: 2px solid #446CB3;
margin: 30px auto;
padding: 0px 0 30px;
background: white;
position: relative;
}
.readmo p {
padding: 0px 10px 0px;
margin-bottom: 10px;
max-height: 50px;
overflow: hidden;
transition: max-height 0.1s ease-in;
}
.readmo label {
display: block;
cursor: pointer;
text-align: center;
padding: 0px 0 0px;
margin: 0px 0 0 0;
position: absolute;
width: 100%;
bottom: 0px;
background: linear-gradient(180deg, rgba(255, 255, 255, 0) 0%, rgba(255, 255, 255, 0) 5%,
rgba(255, 255, 255, 0.94) 95%, white 100%);
/* w3c */
}
.readmo label:after {
content: "\203A";
color: #999;
position: relative;
width: 100%;
font-size: 32px;
padding: 0;
display: block;
transform: rotate(90deg);
}
985
.readmo label:hover:after {
color: #333;
}
.readmo input[type=checkbox] {
display: none;
}
.readmo input[type=checkbox]:checked + label:after {
transform: rotate(270deg);
}
.readmo input[type=checkbox]:checked ~ p {
max-height: 200px;
transition: max-height 0.1s ease-in;
}
.step-container {
width: 400px;
margin: 30px auto;
min-height: 200px;
position: relative;
}
.step-container:after {
content: "";
display: table;
clear: both;
}
.step-container .step-content {
display: none;
border: 2px solid #446CB3;
border-radius: 2px;
background: #fff;
min-height: 150px;
position: absolute;
top: 70px;
}
.step-container .step-content .text {
padding: 15px;
}
.step-container .step-dot {
float: left;
width: 33.333%;
text-align: center;
padding-top: 40px;
position: relative;
}
.step-container .step-dot:after {
content: "";
width: 30px;
height: 30px;
background: #fff;
color: #666;
display: block;
border-radius: 50%;
border: 2px solid #219150;
padding-top: 5px;
position: absolute;
top: 0px;
left: 41%;
z-index: 99;
986
box-shadow: 0px 1px 1px 0 rgba(0, 0, 0, 0.3);
transition: 0.1s ease-in;
}
.step-container .step-dot.one:after {
content: "1";
}
.step-container .step-dot.two:after {
content: "2";
}
.step-container .step-dot.three:after {
content: "3";
}
.step-container .step-dot.one:before {
display: none;
}
.step-container .step-dot:before {
content: "";
width: 100%;
height: 4px;
background: #999;
display: block;
position: absolute;
top: 12px;
left: -41%;
box-shadow: 0px 1px 1px 0 rgba(0, 0, 0, 0.3);
transition: 0.1s ease-in;
}
.step-container label {
cursor: pointer;
padding: 10px 0;
display: block;
width: 100px;
float: right;
user-select: none;
-webkit-user-select: none;
text-align: center;
background: #446CB3;
color: #fff;
margin-left: 15px;
border-bottom-left-radius: 2px;
}
.step-container label:hover {
background: #365690;
}
.step-container input[name='toggler'] {
display: none;
}
.step-container input[name='toggler']:checked + .step-dot + .step-content {
display: block;
}
.step-container input[name='toggler']:checked + .step-dot:after {
background: #219150;
color: #fff;
}
.step-container input[name='toggler']:checked ~ input:checked + .step-dot:before {
background: #219150;
}
.step-container input[name='toggler']:checked ~ input:not(:checked) + .step-dot {
987
color: #888;
}
.step-container input[name='toggler']:checked ~ input:not(:checked) + .step-dot:after {
border-color: #888;
color: #888;
}
</style></head><body>
<ul class="nav-mobile check">
<li>CSS-only Playground</li>
<li class="menu-container">
<input id="menu-toggle" type="checkbox">
<label for="menu-toggle" class="menu-button">
<svg class="icon-open" viewBox="0 0 24 24"><path d="M3 18h18v-2H3v2zm0-5h18v-2H3v2zm0-
7v2h18V6H3z"></path></svg>
<svg class="icon-close" viewBox="0 0 100 100">
<path d="M83.288 88.13c-2.114 2.112-5.575 2.112-7.69 0L53.66 66.188c-2.113-2.112-5.572-
2.112-7.686 0l-21.72 21.72c-2.114 2.113-5.572 2.113-7.687 0l-4.693-4.692c-2.114-2.114-2.114-5.573
0-7.688l21.72-21.72c2.112-2.115 2.112-5.574 0-7.687L11.87 24.4c-2.114-2.113-2.114-5.57 0-
7.686l4.842-4.842c2.113-2.114 5.57-2.114 7.686 0l21.72 21.72c2.114 2.113 5.572 2.113 7.688
0l21.72-21.72c2.115-2.114 5.574-2.114 7.688 0l4.695 4.695c2.112 2.113 2.112 5.57-.002 7.686l-
21.72 21.72c-2.112 2.114-2.112 5.573 0 7.686L88.13 75.6c2.112 2.11 2.112 5.572 0 7.687l-4.842
4.84z"/>
</svg>
</label>
<ul class="menu-sidebar">
<li><a href="#">Item</a></li>
<li><a href="#">Item</a></li>
<li><a href="#">Item</a></li>
<li>
<input type="checkbox" id="sub-one" class="submenu-toggle">
<label class="submenu-label" for="sub-one">Category</label>
<div class="arrow right">›</div>
<ul class="menu-sub">
<li class="menu-sub-title">
<label class="submenu-label" for="sub-one">Back</label>
<div class="arrow left">‹</div>
</li>
<li><a href="#">Sub-item</a></li>
<li><a href="#">Sub-item</a></li>
<li><a href="#">Sub-item</a></li>
<li><a href="#">Sub-item</a></li>
</ul>
</li>
<li>
<input type="checkbox" id="sub-two" class="submenu-toggle">
<label class="submenu-label" for="sub-two">Category</label>
<div class="arrow right">›</div>
<ul class="menu-sub">
<li class="menu-sub-title">
<label class="submenu-label" for="sub-two">Back</label>
<div class="arrow left">‹</div>
</li>
<li><a href="#">Sub-item</a></li>
<li><a href="#">Sub-item</a></li>
<li><a href="#">Sub-item</a></li>
<li><a href="#">Sub-item</a></li>
</ul>
</li>
988
</ul>
</li>
</ul>
<br /><br /><br />
<ul class="carousel-container radio">
<li>
<input class="carousel-toggle" id="slide-1" type="radio" name="c-toggle" checked/>
<label class="dot" for="slide-1"></label>
<ul class="carousel-content">
<li>
<img src="http://www.spacebuckets.com/gal/1-1.jpg"/>
<label class="arrow back" for="slide-2">› </label>
<label class="arrow next" for="slide-4">‹</label>
</li>
</ul>
</li>
<li>
<input class="carousel-toggle" id="slide-2" type="radio" name="c-toggle" />
<label class="dot" for="slide-2"></label>
<ul class="carousel-content">
<li>
<img src="http://www.spacebuckets.com/gal/2-1.jpg"/>
<label class="arrow back" for="slide-3">› </label>
<label class="arrow next" for="slide-1">‹</label>
</li>
</ul>
</li>
<li>
<input class="carousel-toggle" id="slide-3" type="radio" name="c-toggle" />
<label class="dot" for="slide-3"></label>
<ul class="carousel-content">
<li>
<img src="http://www.spacebuckets.com/gal/3-1.jpg"/>
<label class="arrow back" for="slide-4">› </label>
<label class="arrow next" for="slide-2">‹</label>
</li>
</ul>
</li>
<li>
<input class="carousel-toggle" id="slide-4" type="radio" name="c-toggle" />
<label class="dot" for="slide-4"></label>
<ul class="carousel-content">
<img src="http://www.spacebuckets.com/gal/4-1.jpg"/>
<label class="arrow back" for="slide-1">› </label>
<label class="arrow next" for="slide-3">‹</label>
</ul>
</li>
</ul>
<hr />
<ul class="tab-container radio">
<li>
<input class="tab-toggle" id="tab-1" type="radio" name="toggle" checked />
<label data-title="Tab 1" class="tab l-b" for="tab-1">Tabs</label>
<ul class="tab-content-container">
<li class="tab-content">
This is a testing text to test the tab content container. Lorem Ipsum dolor sit amet!
Consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
This is a testing text to test the tab content container. Lorem Ipsum dolor sit amet!
989
<div class="arrows">
<label class="back" for="tab-4">‹</label>
<label class="next" for="tab-2">› </label>
</div>
</li>
</ul>
</li>
<li>
<input class="tab-toggle" id="tab-2" type="radio" name="toggle" />
<label class="tab" for="tab-2">Are</label>
<ul class="tab-content-container">
<li class="tab-content">
Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit
anim id est laborum.
Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit
anim id est laborum.
<div class="arrows">
<label class="back" for="tab-1">‹</label>
<label class="next" for="tab-3">› </label>
</div>
</li>
</ul>
</li>
<li>
<input class="tab-toggle" id="tab-3" type="radio" name="toggle"/>
<label class="tab" for="tab-3">Pretty</label>
<ul class="tab-content-container">
<li class="tab-content">
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat
nulla pariatur.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat
nulla pariatur.
<div class="arrows">
<label class="back" for="tab-2">‹</label>
<label class="next" for="tab-4">› </label>
</div>
</li>
</ul>
</li>
<li>
<input class="tab-toggle" id="tab-4" type="radio" name="toggle"/>
<label class="tab" for="tab-4">Cool</label>
<ul class="tab-content-container">
<li class="tab-content">
This is the final content for the tab example.
<div class="arrows">
<label class="back" for="tab-3">‹</label>
<label class="next" for="tab-1">› </label>
</div>
</li>
</ul>
</li>
</ul>
<br /><br /><br /><br /><br /><br /><br /><br />
<hr />
<ul class="accordion-container radio">
<li class="accordion-category">
<input type="radio" name="a-toggle" id="one" checked>
990
<label for="one" class="accordion-title">Accordions</label>
<ul class="accordion-items">
<li>Item One</li>
<li>Item Two</li>
<li>Item Three</li>
</ul>
</li>
<li class="accordion-category">
<input id="two" type="radio" name="a-toggle">
<label for="two" class="accordion-title">Condense</label>
<ul class="accordion-items">
<li>Item A</li>
<li>Item B</li>
</ul>
</li>
<li class="accordion-category">
<input id="tre" type="radio" name="a-toggle">
<label for="tre" class="accordion-title">Stuff</label>
<ul class="accordion-items">
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
<li>Item 4</li>
</ul>
</ul>
</div>
<hr />
<div class="modal-container check">
<input id="modal-toggle" type="checkbox">
<label class="modal-btn" for="modal-toggle">Modal</label>
<label class="modal-backdrop" for="modal-toggle"></label>
<div class="modal-content">
<label class="modal-close" for="modal-toggle">✕</label>
<h2>Modal title</h2><hr />
<p>Hello from inside the modal!</p>
<label class="modal-content-btn" for="modal-toggle">OK</label>
</div>
</div>
<hr />
<div class="tooltip-container check">
<input id="tooltip-toggle" type="checkbox">
<label class="tooltip-btn" for="tooltip-toggle">Tooltip click</label>
<label class="tooltip-backdrop" for="tooltip-toggle"></label>
<div class="tooltip-content">
<p>Hello from inside the CSS tooltip!</p>
</div>
</div>
<div class="tooltip-container">
<div class="tooltip-btn tooltip-toggle">Tooltip hover</div>
<div class="tooltip-content">
<p>Hello from inside the CSS tooltip!</p>
</div>
</div>
<hr />
<br />
<div class="star-container">
<input type="radio" name="starred" id="five"/>
<input type="radio" name="starred" id="four"/>
991
<input type="radio" name="starred" id="three"/>
<input type="radio" name="starred" id="two"/>
<input type="radio" name="starred" id="one"/>
<label for="one"></label>
<label for="two"></label>
<label for="three"></label>
<label for="four"></label>
<label for="five"></label>
</div>
<br />
<hr />
<div class="step-container">
<input type="checkbox" id="step-1" name="toggler" checked/>
<div class="step-dot one">Ready</div>
<div class="step-content">
<label for="step-2">Next</label>
<div class="text">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud
exercitation ullamco laboris nisi ut aliquip ex ea commodo. </div>
</div>
<input type="checkbox" id="step-2" name="toggler" />
<div class="step-dot two">Set</div>
<div class="step-content">
<label for="step-3">Next</label>
<div class="text">Duis aute irure dolor in reprehenderit in voluptate velit esse cillum
dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa
qui officia deserunt mollit anim id est laborum.</div>
</div>
<input type="checkbox" id="step-3" name="toggler" />
<div class="step-dot three">Go!</div>
<div class="step-content">
<div class="text">Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium
doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi
architecto beatae vitae dicta sunt explicabo.</div>
</div>
</div>
<br />
<hr />
<div class="readmo">
<input type="checkbox" id="toggler" />
<label for="toggler"></label>
<p>This is a filler text filler text filler text lorem ipsum dolor sit ametThis is a filler
text filler text filler text lorem ipsum dolor sit amet. filler text filler text filler text
lorem ipsum dolor sit ametThis is a filler text filler text filler text lorem ipsum dolor sit
amet. filler text filler text filler text lorem ipsum dolor sit ametThis is a filler text filler
text filler text lorem ipsum dolor sit amet</p>
</div>
*****************************************************************************
List view
<style class="cp-pen-styles">
@keyframes shake {
992
0%, 100% {
transform: translateX(0);
}
10%, 30%, 50%, 70% {
transform: translateX(-5px);
}
20%, 40%, 60%, 80% {
transform: translateX(5px);
}
}
* {
box-sizing: border-box;
}
body {
background: #f8f9fa;
font-family: sans-serif;
color: #333;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
.container {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
margin: auto;
width: 300px;
height: 300px;
background: #f2f3f6;
padding: 1em;
border: 1px solid #d4d7e1;
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05), 0 5px 10px rgba(0, 0, 0, 0.05);
border-radius: 3px;
overflow: hidden;
}
.input-query {
width: 100%;
padding: 0.5em;
border: 1px solid #d4d7e1;
border-radius: 3px;
font-size: 1em;
}
.input-query:focus ~ .counter {
opacity: 0.1;
transition: opacity 1s ease-in;
}
.list-wrap {
margin-top: 0.4em;
overflow-y: auto;
overflow-x: hidden;
}
.list {
993
max-height: 220px;
}
.list-item {
font-size: 0.9em;
padding: 0.5em 0.8em;
border-bottom: 1px solid #d4d7e1;
border-top: 1px solid white;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
word-wrap: normal;
max-width: 100%;
}
.list-item:first-child {
border-top: none;
}
.list-item:last-child {
border-bottom: none;
}
.list-item-link {
color: #444;
text-decoration: none;
}
.item-list-subtext {
font-size: 85%;
color: grey;
}
.item-list-subtext:before {
content: ' (';
}
.item-list-subtext:after {
content: ')';
}
.list-item--disable {
text-align: center;
border-bottom: none;
animation: shake 0.6s;
color: #9da1b1;
}
.counter {
position: absolute;
bottom: -15px;
right: 10px;
z-index: 0;
font-size: 3.5em;
color: black;
transform: translateY(0);
opacity: 0;
}
</style></head><body>
994
<span class="counter" data-search-on-list="counter"></span>
<div class="list-wrap">
<ul class="list" data-search-on-list="list">
<li class="list-item" data-search-on-list="list-item">
<a href="http://codepen.io/davilious/pen/YqdoyP" class="list-item-link">Ali <span
class="item-list-subtext">Smith</span></a>
</li>
<li class="list-item" data-search-on-list="list-item">
<a href="" class="list-item-link">Alia <span class="item-list-subtext">Johnson</span></a>
</li>
<li class="list-item" data-search-on-list="list-item">
<a href="" class="list-item-link">Amira<span class="item-list-subtext">Johnson</span></a>
</li>
<li class="list-item" data-search-on-list="list-item">
<a href="" class="list-item-link">Omar<span class="item-list-subtext">Davis</span></a>
</li>
<li class="list-item" data-search-on-list="list-item">
<a href="" class="list-item-link">Aaron<span class="item-list-subtext">Davis</span></a>
</li>
<li class="list-item" data-search-on-list="list-item">
<a href="" class="list-item-link">Bailey <span class="item-list-subtext">Moore</span></a>
</li>
<li class="list-item" data-search-on-list="list-item">
<a href="" class="list-item-link">Noah<span class="item-list-subtext">Thomas</span></a>
</li>
<li class="list-item" data-search-on-list="list-item">
<a href="" class="list-item-link">Liam<span class="item-list-subtext">Garcia</span></a>
</li>
<li class="list-item" data-search-on-list="list-item">
<a href="" class="list-item-link">Dakota<span class="item-list-subtext">Garcia</span></a>
</li>
<li class="list-item" data-search-on-list="list-item">
<a href="" class="list-item-link">Olivia<span class="item-list-subtext">Taylor</span></a>
</li>
<li class="list-item" data-search-on-list="list-item">
<a href="" class="list-item-link">Mason<span class="item-list-subtext">Garcia</span></a>
</li>
<li class="list-item" data-search-on-list="list-item">
<a href="" class="list-item-link">Abigail<span class="item-list-subtext">Martin</span></a>
</li>
<li class="list-item" data-search-on-list="list-item">
<a href="" class="list-item-link">Emily<span class="item-list-subtext">Robinson</span></a>
</li>
<li class="list-item" data-search-on-list="list-item">
<a href="" class="list-item-link">Emily<span class="item-list-subtext">García</span></a>
</li>
<li class="list-item" data-search-on-list="list-item">
<a href="" class="list-item-link">John<span class="item-list-subtext">Robinson</span></a>
</li>
<li class="list-item" data-search-on-list="list-item">
<a href="" class="list-item-link">Emily<span class="item-list-subtext">Clark</span></a>
</li>
<li class="list-item" data-search-on-list="list-item">
<a href="" class="list-item-link">Aurora<span class="item-list-subtext">Lewis</span></a>
</li>
<li class="list-item" data-search-on-list="list-item">
<a href="" class="list-item-link">Adeline<span class="item-list-
subtext">Robinson</span></a>
995
</li>
<li class="list-item" data-search-on-list="list-item">
<a href="" class="list-item-link">John<span class="item-list-subtext">García</span></a>
</li>
<li class="list-item" data-search-on-list="list-item">
<a href="" class="list-item-link">Isla<span class="item-list-subtext">Lewis</span></a>
</li>
</ul>
</div>
</div>
*****************************************************************************
<style class="cp-pen-styles">
@import url("https://fonts.googleapis.com/css?family=Montserrat:400,700");
html {
box-sizing: border-box;
-webkit-font-smoothing: antialiased;
}
*, *:before, *:after {
box-sizing: inherit;
}
body {
height: 100vh;
overflow: hidden;
background-image: -webkit-linear-gradient(bottom left, rgba(0, 0, 255, 0.5), rgba(255, 0, 0,
0.75)), -webkit-linear-gradient(rgba(0, 0, 255, 0.25) 100%, transparent),
url("http://media.boingboing.net/wp-content/uploads/2014/06/giphy-13.gif");
background-image: linear-gradient(to top right, rgba(0, 0, 255, 0.5), rgba(255, 0, 0, 0.75)),
linear-gradient(rgba(0, 0, 255, 0.25) 100%, transparent), url("http://media.boingboing.net/wp-
content/uploads/2014/06/giphy-13.gif");
background-size: cover;
background-position: center;
color: white;
font-family: "Montserrat", sans-serif;
font-size: 20px;
line-height: 30px;
}
h1 {
font-size: 45px;
line-height: 45px;
letter-spacing: 15px;
text-transform: uppercase;
}
h1:after {
content: "";
display: block;
width: 120px;
height: 4px;
996
margin: 28px auto -2px;
background-color: currentcolor;
}
h1, p {
margin: 30px 0;
}
.content {
position: absolute;
top: 50%;
left: 50%;
width: 100%;
max-width: 660px;
padding: 0 30px;
text-align: center;
-webkit-transform: translate(-50%, 50vh);
transform: translate(-50%, 50vh);
opacity: 0;
-webkit-animation: 0.75s 0.75s forwards slide_in;
animation: 0.75s 0.75s forwards slide_in;
}
@-webkit-keyframes slide_in {
100% {
-webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
opacity: 1;
}
}
@keyframes slide_in {
100% {
-webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
opacity: 1;
}
}
</style></head><body>
<div class='content'>
<h1>Hello World!</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Obcaecati incidunt non nam quasi
mollitia recusandae harum deleniti hic.</p>
<A HREF="http://www.w3schools.com/html/tryit.asp?filename=tryhtml_default">Click Me</A>
</div>
*****************************************************************************
Fancy button
.bg-gradient2 span,
.bg-gradient2:before {
background: #44ea76;
background: -webkit-linear-gradient(left, #44ea76 0%, #39fad7 80%, #39fad7 100%);
background: linear-gradient(to right, #44ea76 0%, #39fad7 80%, #39fad7 100%);
}
.bg-gradient3 span,
.bg-gradient3:before {
background: #fa6c9f;
background: -webkit-linear-gradient(left, #fa6c9f 0%, #ffe140 80%, #ffe140 100%);
background: linear-gradient(to right, #fa6c9f 0%, #ffe140 80%, #ffe140 100%);
}
/* General */
.wrapper {
margin: 5% auto;
text-align: center;
}
a {
text-decoration: none;
}
a:hover, a:focus, a:active {
text-decoration: none;
}
/* fancy Button */
.fancy-button {
display: inline-block;
margin: 30px;
font-family: 'Montserrat', Helvetica, Arial, sans-serif;
font-size: 17px;
letter-spacing: 0.03em;
text-transform: uppercase;
color: #ffffff;
position: relative;
}
.fancy-button:before {
content: '';
display: inline-block;
height: 40px;
position: absolute;
bottom: -5px;
left: 30px;
right: 30px;
z-index: -1;
border-radius: 30em;
-webkit-filter: blur(20px) brightness(0.95);
filter: blur(20px) brightness(0.95);
-webkit-transform-style: preserve-3d;
transform-style: preserve-3d;
-webkit-transition: all 0.3s ease-out;
transition: all 0.3s ease-out;
}
.fancy-button i {
998
margin-top: -1px;
margin-right: 20px;
font-size: 1.265em;
vertical-align: middle;
}
.fancy-button span {
display: inline-block;
padding: 18px 60px;
border-radius: 50em;
position: relative;
z-index: 2;
will-change: transform, filter;
-webkit-transform-style: preserve-3d;
transform-style: preserve-3d;
-webkit-transition: all 0.3s ease-out;
transition: all 0.3s ease-out;
}
.fancy-button:focus, .fancy-button:active {
color: #ffffff;
}
.fancy-button:hover {
color: #ffffff;
}
.fancy-button:hover span {
-webkit-filter: brightness(1.05) contrast(1.05);
filter: brightness(1.05) contrast(1.05);
-webkit-transform: scale(0.95);
transform: scale(0.95);
}
.fancy-button:hover:before {
bottom: 0;
-webkit-filter: blur(10px) brightness(0.95);
filter: blur(10px) brightness(0.95);
}
.fancy-button.pop-onhover:before {
opacity: 0;
bottom: 10px;
}
.fancy-button.pop-onhover:hover:before {
bottom: -7px;
opacity: 1;
-webkit-filter: blur(20px);
filter: blur(20px);
}
.fancy-button.pop-onhover:hover span {
-webkit-transform: scale(1.04);
transform: scale(1.04);
}
.fancy-button.pop-onhover:hover:active span {
-webkit-filter: brightness(1) contrast(1);
filter: brightness(1) contrast(1);
-webkit-transform: scale(1);
transform: scale(1);
-webkit-transition: all 0.15s ease-out;
transition: all 0.15s ease-out;
}
.fancy-button.pop-onhover:hover:active:before {
bottom: 0;
999
-webkit-filter: blur(10px) brightness(0.95);
filter: blur(10px) brightness(0.95);
-webkit-transition: all 0.2s ease-out;
transition: all 0.2s ease-out;
}
</style></head><body>
<div class="wrapper">
<a href="#" class="fancy-button bg-gradient1"><span><i class="fa fa-wheelchair-alt"></i>Follow
Me</span></a>
<a href="#" class="fancy-button bg-gradient2"><span><i class="fa fa-
envelope"></i>Messages</span></a>
</div><!-- /.wrapper -->
<div class="wrapper">
<a href="#" class="fancy-button pop-onhover bg-gradient1"><span>Post A Comment</span></a>
<a href="#" class="fancy-button pop-onhover bg-gradient3"><span>Share Channel</span></a>
</div>
*****************************************************************************
CSS Sphere
<style class="cp-pen-styles">
body {
margin: 0;
display: flex;
height: 100vh;
overflow: hidden;
justify-content: center;
align-items: center;
background: black;
}
.mommy {
width: 500px;
height: 500px;
position: relative;
perspective: 800px;
}
.daddy {
width: 500px;
height: 500px;
transform-style: preserve-3d;
animation: rotate 25s infinite linear;
}
span {
display: inline-block;
position: absolute;
top: 50%;
left: 50%;
perspective: 800px;
transform-style: preserve-3d;
width: 0;
1000
height: 0;
}
span:before {
content: "";
width: 4px;
height: 4px;
display: inline-block;
position: absolute;
top: calc(50% - 2px);
left: calc(50% - 2px);
background: currentColor;
color: inherit;
border-radius: 50%;
animation: invertRotate 25s infinite linear, scale 2s infinite linear;
box-shadow: 0 0 10px currentColor;
}
.mommy span:nth-child(1) {
transform: translate3d(2.41129px, 1.01948px, 249.98629px);
color: #ff0500;
}
.mommy span:nth-child(1):before {
animation-delay: 0s, -0.00667s;
}
.mommy span:nth-child(2) {
transform: translate3d(3.64768px, 3.75579px, 249.94517px);
color: #ff0a00;
}
.mommy span:nth-child(2):before {
animation-delay: 0s, -0.01333s;
}
.mommy span:nth-child(3) {
transform: translate3d(2.84548px, 7.31901px, 249.87664px);
color: #ff0f00;
}
.mommy span:nth-child(3):before {
animation-delay: 0s, -0.02s;
}
.mommy span:nth-child(4) {
transform: translate3d(-0.30569px, 10.46445px, 249.78071px);
color: #ff1400;
}
.mommy span:nth-child(4):before {
animation-delay: 0s, -0.02667s;
}
.mommy span:nth-child(5) {
transform: translate3d(-5.44486px, 11.89724px, 249.65738px);
color: #ff1a00;
}
.mommy span:nth-child(5):before {
animation-delay: 0s, -0.03333s;
}
.mommy span:nth-child(6) {
1001
transform: translate3d(-11.57533px, 10.60317px, 249.50668px);
color: #ff1f00;
}
.mommy span:nth-child(6):before {
animation-delay: 0s, -0.04s;
}
.mommy span:nth-child(7) {
transform: translate3d(-17.25167px, 6.13348px, 249.32862px);
color: #ff2400;
}
.mommy span:nth-child(7):before {
animation-delay: 0s, -0.04667s;
}
.mommy span:nth-child(8) {
transform: translate3d(-20.88379px, -1.22116px, 249.12321px);
color: #ff2900;
}
.mommy span:nth-child(8):before {
animation-delay: 0s, -0.05333s;
}
.mommy span:nth-child(9) {
transform: translate3d(-21.09811px, -10.41121px, 248.89049px);
color: #ff2e00;
}
.mommy span:nth-child(9):before {
animation-delay: 0s, -0.06s;
}
.mommy span:nth-child(10) {
transform: translate3d(-17.08109px, -19.77685px, 248.63047px);
color: #ff3300;
}
.mommy span:nth-child(10):before {
animation-delay: 0s, -0.06667s;
}
.mommy span:nth-child(11) {
transform: translate3d(-8.83099px, -27.34361px, 248.34319px);
color: #ff3800;
}
.mommy span:nth-child(11):before {
animation-delay: 0s, -0.07333s;
}
.mommy span:nth-child(12) {
transform: translate3d(2.74163px, -31.21313px, 248.02868px);
color: #ff3d00;
}
.mommy span:nth-child(12):before {
animation-delay: 0s, -0.08s;
}
.mommy span:nth-child(13) {
transform: translate3d(15.89625px, -29.97464px, 247.68696px);
color: #ff4200;
1002
}
.mommy span:nth-child(13):before {
animation-delay: 0s, -0.08667s;
}
.mommy span:nth-child(14) {
transform: translate3d(28.32425px, -23.05434px, 247.31808px);
color: #ff4700;
}
.mommy span:nth-child(14):before {
animation-delay: 0s, -0.09333s;
}
.mommy span:nth-child(15) {
transform: translate3d(37.55093px, -10.92755px, 246.92209px);
color: #ff4d00;
}
.mommy span:nth-child(15):before {
animation-delay: 0s, -0.1s;
}
.mommy span:nth-child(16) {
transform: translate3d(41.40805px, 4.85919px, 246.49901px);
color: #ff5200;
}
.mommy span:nth-child(16):before {
animation-delay: 0s, -0.10667s;
}
.mommy span:nth-child(17) {
transform: translate3d(38.48926px, 21.87498px, 246.0489px);
color: #ff5700;
}
.mommy span:nth-child(17):before {
animation-delay: 0s, -0.11333s;
}
.mommy span:nth-child(18) {
transform: translate3d(28.49842px, 37.17963px, 245.57181px);
color: #ff5c00;
}
.mommy span:nth-child(18):before {
animation-delay: 0s, -0.12s;
}
.mommy span:nth-child(19) {
transform: translate3d(12.41584px, 47.82911px, 245.06779px);
color: #ff6100;
}
.mommy span:nth-child(19):before {
animation-delay: 0s, -0.12667s;
}
.mommy span:nth-child(20) {
transform: translate3d(-7.56279px, 51.42479px, 244.5369px);
color: #ff6600;
}
.mommy span:nth-child(20):before {
1003
animation-delay: 0s, -0.13333s;
}
.mommy span:nth-child(21) {
transform: translate3d(-28.31983px, 46.60624px, 243.97919px);
color: #ff6b00;
}
.mommy span:nth-child(21):before {
animation-delay: 0s, -0.14s;
}
.mommy span:nth-child(22) {
transform: translate3d(-46.30345px, 33.39159px, 243.39473px);
color: #ff7000;
}
.mommy span:nth-child(22):before {
animation-delay: 0s, -0.14667s;
}
.mommy span:nth-child(23) {
transform: translate3d(-58.1332px, 13.29168px, 242.78357px);
color: #ff7500;
}
.mommy span:nth-child(23):before {
animation-delay: 0s, -0.15333s;
}
.mommy span:nth-child(24) {
transform: translate3d(-61.22048px, -10.83833px, 242.14579px);
color: #ff7a00;
}
.mommy span:nth-child(24):before {
animation-delay: 0s, -0.16s;
}
.mommy span:nth-child(25) {
transform: translate3d(-54.29192px, -35.20076px, 241.48146px);
color: #ff8000;
}
.mommy span:nth-child(25):before {
animation-delay: 0s, -0.16667s;
}
.mommy span:nth-child(26) {
transform: translate3d(-37.71495px, -55.65474px, 240.79064px);
color: #ff8500;
}
.mommy span:nth-child(26):before {
animation-delay: 0s, -0.17333s;
}
.mommy span:nth-child(27) {
transform: translate3d(-13.55408px, -68.41812px, 240.07342px);
color: #ff8a00;
}
.mommy span:nth-child(27):before {
animation-delay: 0s, -0.18s;
}
1004
.mommy span:nth-child(28) {
transform: translate3d(14.66872px, -70.75337px, 239.32987px);
color: #ff8f00;
}
.mommy span:nth-child(28):before {
animation-delay: 0s, -0.18667s;
}
.mommy span:nth-child(29) {
transform: translate3d(42.48545px, -61.51483px, 238.56008px);
color: #ff9400;
}
.mommy span:nth-child(29):before {
animation-delay: 0s, -0.19333s;
}
.mommy span:nth-child(30) {
transform: translate3d(65.1913px, -41.45254px, 237.76413px);
color: #ff9900;
}
.mommy span:nth-child(30):before {
animation-delay: 0s, -0.2s;
}
.mommy span:nth-child(31) {
transform: translate3d(78.6388px, -13.20525px, 236.9421px);
color: #ff9e00;
}
.mommy span:nth-child(31):before {
animation-delay: 0s, -0.20667s;
}
.mommy span:nth-child(32) {
transform: translate3d(79.98305px, 19.03396px, 236.09409px);
color: #ffa300;
}
.mommy span:nth-child(32):before {
animation-delay: 0s, -0.21333s;
}
.mommy span:nth-child(33) {
transform: translate3d(68.24586px, 50.13944px, 235.22019px);
color: #ffa800;
}
.mommy span:nth-child(33):before {
animation-delay: 0s, -0.22s;
}
.mommy span:nth-child(34) {
transform: translate3d(44.59143px, 74.86995px, 234.3205px);
color: #ffad00;
}
.mommy span:nth-child(34):before {
animation-delay: 0s, -0.22667s;
}
.mommy span:nth-child(35) {
1005
transform: translate3d(12.25056px, 88.75048px, 233.39511px);
color: #ffb300;
}
.mommy span:nth-child(35):before {
animation-delay: 0s, -0.23333s;
}
.mommy span:nth-child(36) {
transform: translate3d(-23.91129px, 88.87058px, 232.44412px);
color: #ffb800;
}
.mommy span:nth-child(36):before {
animation-delay: 0s, -0.24s;
}
.mommy span:nth-child(37) {
transform: translate3d(-58.12632px, 74.45845px, 231.46765px);
color: #ffbd00;
}
.mommy span:nth-child(37):before {
animation-delay: 0s, -0.24667s;
}
.mommy span:nth-child(38) {
transform: translate3d(-84.64667px, 47.12177px, 230.46579px);
color: #ffc200;
}
.mommy span:nth-child(38):before {
animation-delay: 0s, -0.25333s;
}
.mommy span:nth-child(39) {
transform: translate3d(-98.70889px, 10.69853px, 229.43866px);
color: #ffc700;
}
.mommy span:nth-child(39):before {
animation-delay: 0s, -0.26s;
}
.mommy span:nth-child(40) {
transform: translate3d(-97.3788px, -29.27521px, 228.38636px);
color: #ffcc00;
}
.mommy span:nth-child(40):before {
animation-delay: 0s, -0.26667s;
}
.mommy span:nth-child(41) {
transform: translate3d(-80.12864px, -66.40789px, 227.30903px);
color: #ffd100;
}
.mommy span:nth-child(41):before {
animation-delay: 0s, -0.27333s;
}
.mommy span:nth-child(42) {
transform: translate3d(-49.03685px, -94.47692px, 226.20676px);
color: #ffd600;
1006
}
.mommy span:nth-child(42):before {
animation-delay: 0s, -0.28s;
}
.mommy span:nth-child(43) {
transform: translate3d(-8.5608px, -108.47048px, 225.07969px);
color: #ffdb00;
}
.mommy span:nth-child(43):before {
animation-delay: 0s, -0.28667s;
}
.mommy span:nth-child(44) {
transform: translate3d(35.0977px, -105.47241px, 223.92794px);
color: #ffe000;
}
.mommy span:nth-child(44):before {
animation-delay: 0s, -0.29333s;
}
.mommy span:nth-child(45) {
transform: translate3d(74.94438px, -85.23527px, 222.75163px);
color: #ffe600;
}
.mommy span:nth-child(45):before {
animation-delay: 0s, -0.3s;
}
.mommy span:nth-child(46) {
transform: translate3d(104.31576px, -50.33313px, 221.55089px);
color: #ffeb00;
}
.mommy span:nth-child(46):before {
animation-delay: 0s, -0.30667s;
}
.mommy span:nth-child(47) {
transform: translate3d(117.99266px, -5.85203px, 220.32586px);
color: #fff000;
}
.mommy span:nth-child(47):before {
animation-delay: 0s, -0.31333s;
}
.mommy span:nth-child(48) {
transform: translate3d(113.11821px, 41.34831px, 219.07667px);
color: #fff500;
}
.mommy span:nth-child(48):before {
animation-delay: 0s, -0.32s;
}
.mommy span:nth-child(49) {
transform: translate3d(89.76004px, 83.69463px, 217.80345px);
color: #fffa00;
}
.mommy span:nth-child(49):before {
1007
animation-delay: 0s, -0.32667s;
}
.mommy span:nth-child(50) {
transform: translate3d(51.01026px, 114.11816px, 216.50635px);
color: yellow;
}
.mommy span:nth-child(50):before {
animation-delay: 0s, -0.33333s;
}
.mommy span:nth-child(51) {
transform: translate3d(2.58986px, 127.234px, 215.18551px);
color: #faff00;
}
.mommy span:nth-child(51):before {
animation-delay: 0s, -0.34s;
}
.mommy span:nth-child(52) {
transform: translate3d(-47.99434px, 120.28525px, 213.84107px);
color: #f5ff00;
}
.mommy span:nth-child(52):before {
animation-delay: 0s, -0.34667s;
}
.mommy span:nth-child(53) {
transform: translate3d(-92.6163px, 93.68763px, 212.47317px);
color: #f0ff00;
}
.mommy span:nth-child(53):before {
animation-delay: 0s, -0.35333s;
}
.mommy span:nth-child(54) {
transform: translate3d(-123.83919px, 51.07106px, 211.08198px);
color: #ebff00;
}
.mommy span:nth-child(54):before {
animation-delay: 0s, -0.36s;
}
.mommy span:nth-child(55) {
transform: translate3d(-136.15442px, -1.20519px, 209.66764px);
color: #e6ff00;
}
.mommy span:nth-child(55):before {
animation-delay: 0s, -0.36667s;
}
.mommy span:nth-child(56) {
transform: translate3d(-126.94498px, -55.00099px, 208.23031px);
color: #e0ff00;
}
.mommy span:nth-child(56):before {
animation-delay: 0s, -0.37333s;
}
1008
.mommy span:nth-child(57) {
transform: translate3d(-97.00574px, -101.66609px, 206.77014px);
color: #dbff00;
}
.mommy span:nth-child(57):before {
animation-delay: 0s, -0.38s;
}
.mommy span:nth-child(58) {
transform: translate3d(-50.52153px, -133.43425px, 205.2873px);
color: #d6ff00;
}
.mommy span:nth-child(58):before {
animation-delay: 0s, -0.38667s;
}
.mommy span:nth-child(59) {
transform: translate3d(5.50982px, -144.71544px, 203.78195px);
color: #d1ff00;
}
.mommy span:nth-child(59):before {
animation-delay: 0s, -0.39333s;
}
.mommy span:nth-child(60) {
transform: translate3d(62.33154px, -133.0714px, 202.25425px);
color: #ccff00;
}
.mommy span:nth-child(60):before {
animation-delay: 0s, -0.4s;
}
.mommy span:nth-child(61) {
transform: translate3d(110.79998px, -99.70517px, 200.70437px);
color: #c7ff00;
}
.mommy span:nth-child(61):before {
animation-delay: 0s, -0.40667s;
}
.mommy span:nth-child(62) {
transform: translate3d(142.85929px, -49.37083px, 199.13248px);
color: #c2ff00;
}
.mommy span:nth-child(62):before {
animation-delay: 0s, -0.41333s;
}
.mommy span:nth-child(63) {
transform: translate3d(152.88031px, 10.29808px, 197.53875px);
color: #bdff00;
}
.mommy span:nth-child(63):before {
animation-delay: 0s, -0.42s;
}
.mommy span:nth-child(64) {
1009
transform: translate3d(138.64118px, 69.94754px, 195.92336px);
color: #b8ff00;
}
.mommy span:nth-child(64):before {
animation-delay: 0s, -0.42667s;
}
.mommy span:nth-child(65) {
transform: translate3d(101.77988px, 119.9734px, 194.28649px);
color: #b3ff00;
}
.mommy span:nth-child(65):before {
animation-delay: 0s, -0.43333s;
}
.mommy span:nth-child(66) {
transform: translate3d(47.63117px, 152.07105px, 192.62831px);
color: #adff00;
}
.mommy span:nth-child(66):before {
animation-delay: 0s, -0.44s;
}
.mommy span:nth-child(67) {
transform: translate3d(-15.54148px, 160.61426px, 190.94901px);
color: #a8ff00;
}
.mommy span:nth-child(67):before {
animation-delay: 0s, -0.44667s;
}
.mommy span:nth-child(68) {
transform: translate3d(-77.80901px, 143.63378px, 189.24876px);
color: #a3ff00;
}
.mommy span:nth-child(68):before {
animation-delay: 0s, -0.45333s;
}
.mommy span:nth-child(69) {
transform: translate3d(-129.14148px, 103.227px, 187.52777px);
color: #9eff00;
}
.mommy span:nth-child(69):before {
animation-delay: 0s, -0.46s;
}
.mommy span:nth-child(70) {
transform: translate3d(-161.02726px, 45.31784px, 185.78621px);
color: #99ff00;
}
.mommy span:nth-child(70):before {
animation-delay: 0s, -0.46667s;
}
.mommy span:nth-child(71) {
transform: translate3d(-167.8846px, -21.20917px, 184.02427px);
color: #94ff00;
1010
}
.mommy span:nth-child(71):before {
animation-delay: 0s, -0.47333s;
}
.mommy span:nth-child(72) {
transform: translate3d(-148.03158px, -85.8746px, 182.24216px);
color: #8fff00;
}
.mommy span:nth-child(72):before {
animation-delay: 0s, -0.48s;
}
.mommy span:nth-child(73) {
transform: translate3d(-104.04685px, -138.25932px, 180.44006px);
color: #8aff00;
}
.mommy span:nth-child(73):before {
animation-delay: 0s, -0.48667s;
}
.mommy span:nth-child(74) {
transform: translate3d(-42.44904px, -169.68685px, 178.61817px);
color: #85ff00;
}
.mommy span:nth-child(74):before {
animation-delay: 0s, -0.49333s;
}
.mommy span:nth-child(75) {
transform: translate3d(27.26806px, -174.66097px, 176.7767px);
color: #80ff00;
}
.mommy span:nth-child(75):before {
animation-delay: 0s, -0.5s;
}
.mommy span:nth-child(76) {
transform: translate3d(94.10188px, -151.81992px, 174.91584px);
color: #7aff00;
}
.mommy span:nth-child(76):before {
animation-delay: 0s, -0.50667s;
}
.mommy span:nth-child(77) {
transform: translate3d(147.28213px, -104.24294px, 173.03579px);
color: #75ff00;
}
.mommy span:nth-child(77):before {
animation-delay: 0s, -0.51333s;
}
.mommy span:nth-child(78) {
transform: translate3d(178.01018px, -39.04585px, 171.13678px);
color: #70ff00;
}
.mommy span:nth-child(78):before {
1011
animation-delay: 0s, -0.52s;
}
.mommy span:nth-child(79) {
transform: translate3d(180.91541px, 33.68302px, 169.21899px);
color: #6bff00;
}
.mommy span:nth-child(79):before {
animation-delay: 0s, -0.52667s;
}
.mommy span:nth-child(80) {
transform: translate3d(154.98719px, 102.44747px, 167.28265px);
color: #66ff00;
}
.mommy span:nth-child(80):before {
animation-delay: 0s, -0.53333s;
}
.mommy span:nth-child(81) {
transform: translate3d(103.82192px, 156.16553px, 165.32797px);
color: #61ff00;
}
.mommy span:nth-child(81):before {
animation-delay: 0s, -0.54s;
}
.mommy span:nth-child(82) {
transform: translate3d(35.13209px, 185.95922px, 163.35515px);
color: #5cff00;
}
.mommy span:nth-child(82):before {
animation-delay: 0s, -0.54667s;
}
.mommy span:nth-child(83) {
transform: translate3d(-40.41701px, 186.62258px, 161.36442px);
color: #57ff00;
}
.mommy span:nth-child(83):before {
animation-delay: 0s, -0.55333s;
}
.mommy span:nth-child(84) {
transform: translate3d(-110.86732px, 157.52493px, 159.356px);
color: #52ff00;
}
.mommy span:nth-child(84):before {
animation-delay: 0s, -0.56s;
}
.mommy span:nth-child(85) {
transform: translate3d(-164.86574px, 102.79362px, 157.3301px);
color: #4dff00;
}
.mommy span:nth-child(85):before {
animation-delay: 0s, -0.56667s;
}
1012
.mommy span:nth-child(86) {
transform: translate3d(-193.49773px, 30.73422px, 155.28695px);
color: #47ff00;
}
.mommy span:nth-child(86):before {
animation-delay: 0s, -0.57333s;
}
.mommy span:nth-child(87) {
transform: translate3d(-191.75981px, -47.43135px, 153.22676px);
color: #42ff00;
}
.mommy span:nth-child(87):before {
animation-delay: 0s, -0.58s;
}
.mommy span:nth-child(88) {
transform: translate3d(-159.42781px, -119.31689px, 151.14978px);
color: #3dff00;
}
.mommy span:nth-child(88):before {
animation-delay: 0s, -0.58667s;
}
.mommy span:nth-child(89) {
transform: translate3d(-101.17091px, -173.33982px, 149.05622px);
color: #38ff00;
}
.mommy span:nth-child(89):before {
animation-delay: 0s, -0.59333s;
}
.mommy span:nth-child(90) {
transform: translate3d(-25.8812px, -200.59149px, 146.94631px);
color: #33ff00;
}
.mommy span:nth-child(90):before {
animation-delay: 0s, -0.6s;
}
.mommy span:nth-child(91) {
transform: translate3d(54.68581px, -196.30727px, 144.82029px);
color: #2eff00;
}
.mommy span:nth-child(91):before {
animation-delay: 0s, -0.60667s;
}
.mommy span:nth-child(92) {
transform: translate3d(127.75141px, -160.69367px, 142.67839px);
color: #29ff00;
}
.mommy span:nth-child(92):before {
animation-delay: 0s, -0.61333s;
}
.mommy span:nth-child(93) {
1013
transform: translate3d(181.54584px, -98.96969px, 140.52084px);
color: #24ff00;
}
.mommy span:nth-child(93):before {
animation-delay: 0s, -0.62s;
}
.mommy span:nth-child(94) {
transform: translate3d(207.20841px, -20.60432px, 138.34789px);
color: #1fff00;
}
.mommy span:nth-child(94):before {
animation-delay: 0s, -0.62667s;
}
.mommy span:nth-child(95) {
transform: translate3d(200.24804px, 62.1389px, 136.15976px);
color: #1aff00;
}
.mommy span:nth-child(95):before {
animation-delay: 0s, -0.63333s;
}
.mommy span:nth-child(96) {
transform: translate3d(161.32357px, 136.12608px, 133.9567px);
color: #14ff00;
}
.mommy span:nth-child(96):before {
animation-delay: 0s, -0.64s;
}
.mommy span:nth-child(97) {
transform: translate3d(96.20879px, 189.44318px, 131.73895px);
color: #0fff00;
}
.mommy span:nth-child(97):before {
animation-delay: 0s, -0.64667s;
}
.mommy span:nth-child(98) {
transform: translate3d(14.93706px, 213.31874px, 129.50675px);
color: #0aff00;
}
.mommy span:nth-child(98):before {
animation-delay: 0s, -0.65333s;
}
.mommy span:nth-child(99) {
transform: translate3d(-69.74806px, 203.5682px, 127.26035px);
color: #05ff00;
}
.mommy span:nth-child(99):before {
animation-delay: 0s, -0.66s;
}
.mommy span:nth-child(100) {
transform: translate3d(-144.39633px, 161.32173px, 125px);
color: lime;
1014
}
.mommy span:nth-child(100):before {
animation-delay: 0s, -0.66667s;
}
.mommy span:nth-child(101) {
transform: translate3d(-196.99263px, 92.90989px, 122.72594px);
color: #00ff05;
}
.mommy span:nth-child(101):before {
animation-delay: 0s, -0.67333s;
}
.mommy span:nth-child(102) {
transform: translate3d(-218.89521px, 8.91494px, 120.43842px);
color: #00ff0a;
}
.mommy span:nth-child(102):before {
animation-delay: 0s, -0.68s;
}
.mommy span:nth-child(103) {
transform: translate3d(-206.2569px, -77.46984px, 118.13769px);
color: #00ff0f;
}
.mommy span:nth-child(103):before {
animation-delay: 0s, -0.68667s;
}
.mommy span:nth-child(104) {
transform: translate3d(-160.69556px, -152.51799px, 115.82401px);
color: #00ff14;
}
.mommy span:nth-child(104):before {
animation-delay: 0s, -0.69333s;
}
.mommy span:nth-child(105) {
transform: translate3d(-89.09738px, -204.15667px, 113.49762px);
color: #00ff1a;
}
.mommy span:nth-child(105):before {
animation-delay: 0s, -0.7s;
}
.mommy span:nth-child(106) {
transform: translate3d(-2.5753px, -223.91313px, 111.15879px);
color: #00ff1f;
}
.mommy span:nth-child(106):before {
animation-delay: 0s, -0.70667s;
}
.mommy span:nth-child(107) {
transform: translate3d(85.26016px, -208.30644px, 108.80777px);
color: #00ff24;
}
.mommy span:nth-child(107):before {
1015
animation-delay: 0s, -0.71333s;
}
.mommy span:nth-child(108) {
transform: translate3d(160.44758px, -159.45555px, 106.44482px);
color: #00ff29;
}
.mommy span:nth-child(108):before {
animation-delay: 0s, -0.72s;
}
.mommy span:nth-child(109) {
transform: translate3d(210.89962px, -84.79826px, 104.0702px);
color: #00ff2e;
}
.mommy span:nth-child(109):before {
animation-delay: 0s, -0.72667s;
}
.mommy span:nth-child(110) {
transform: translate3d(228.35058px, 4.04288px, 101.68416px);
color: #00ff33;
}
.mommy span:nth-child(110):before {
animation-delay: 0s, -0.73333s;
}
.mommy span:nth-child(111) {
transform: translate3d(209.71226px, 93.07452px, 99.28697px);
color: #00ff38;
}
.mommy span:nth-child(111):before {
animation-delay: 0s, -0.74s;
}
.mommy span:nth-child(112) {
transform: translate3d(157.61531px, 168.14248px, 96.8789px);
color: #00ff3d;
}
.mommy span:nth-child(112):before {
animation-delay: 0s, -0.74667s;
}
.mommy span:nth-child(113) {
transform: translate3d(80.042px, 217.18782px, 94.4602px);
color: #00ff42;
}
.mommy span:nth-child(113):before {
animation-delay: 0s, -0.75333s;
}
.mommy span:nth-child(114) {
transform: translate3d(-10.89915px, 232.18845px, 92.03114px);
color: #00ff47;
}
.mommy span:nth-child(114):before {
animation-delay: 0s, -0.76s;
}
1016
.mommy span:nth-child(115) {
transform: translate3d(-100.86822px, 210.47299px, 89.59199px);
color: #00ff4d;
}
.mommy span:nth-child(115):before {
animation-delay: 0s, -0.76667s;
}
.mommy span:nth-child(116) {
transform: translate3d(-175.56116px, 155.19142px, 87.14301px);
color: #00ff52;
}
.mommy span:nth-child(116):before {
animation-delay: 0s, -0.77333s;
}
.mommy span:nth-child(117) {
transform: translate3d(-222.98983px, 74.86036px, 84.68448px);
color: #00ff57;
}
.mommy span:nth-child(117):before {
animation-delay: 0s, -0.78s;
}
.mommy span:nth-child(118) {
transform: translate3d(-235.4106px, -17.95182px, 82.21666px);
color: #00ff5c;
}
.mommy span:nth-child(118):before {
animation-delay: 0s, -0.78667s;
}
.mommy span:nth-child(119) {
transform: translate3d(-210.59045px, -108.5966px, 79.73983px);
color: #00ff61;
}
.mommy span:nth-child(119):before {
animation-delay: 0s, -0.79333s;
}
.mommy span:nth-child(120) {
transform: translate3d(-152.20336px, -182.6634px, 77.25425px);
color: #00ff66;
}
.mommy span:nth-child(120):before {
animation-delay: 0s, -0.8s;
}
.mommy span:nth-child(121) {
transform: translate3d(-69.28728px, -228.27656px, 74.7602px);
color: #00ff6b;
}
.mommy span:nth-child(121):before {
animation-delay: 0s, -0.80667s;
}
.mommy span:nth-child(122) {
1017
transform: translate3d(25.15819px, -238.0039px, 72.25795px);
color: #00ff70;
}
.mommy span:nth-child(122):before {
animation-delay: 0s, -0.81333s;
}
.mommy span:nth-child(123) {
transform: translate3d(116.21525px, -210.06966px, 69.74778px);
color: #00ff75;
}
.mommy span:nth-child(123):before {
animation-delay: 0s, -0.82s;
}
.mommy span:nth-child(124) {
transform: translate3d(189.41049px, -148.67346px, 67.22996px);
color: #00ff7a;
}
.mommy span:nth-child(124):before {
animation-delay: 0s, -0.82667s;
}
.mommy span:nth-child(125) {
transform: translate3d(233.0214px, -63.35866px, 64.70476px);
color: #00ff80;
}
.mommy span:nth-child(125):before {
animation-delay: 0s, -0.83333s;
}
.mommy span:nth-child(126) {
transform: translate3d(239.95828px, 32.47471px, 62.17247px);
color: #00ff85;
}
.mommy span:nth-child(126):before {
animation-delay: 0s, -0.84s;
}
.mommy span:nth-child(127) {
transform: translate3d(208.91878px, 123.68025px, 59.63336px);
color: #00ff8a;
}
.mommy span:nth-child(127):before {
animation-delay: 0s, -0.84667s;
}
.mommy span:nth-child(128) {
transform: translate3d(144.62674px, 195.76542px, 57.08772px);
color: #00ff8f;
}
.mommy span:nth-child(128):before {
animation-delay: 0s, -0.85333s;
}
.mommy span:nth-child(129) {
transform: translate3d(57.11222px, 237.20042px, 54.53581px);
color: #00ff94;
1018
}
.mommy span:nth-child(129):before {
animation-delay: 0s, -0.86s;
}
.mommy span:nth-child(130) {
transform: translate3d(-39.85726px, 241.26685px, 51.97792px);
color: #00ff99;
}
.mommy span:nth-child(130):before {
animation-delay: 0s, -0.86667s;
}
.mommy span:nth-child(131) {
transform: translate3d(-130.94838px, 207.14909px, 49.41434px);
color: #00ff9e;
}
.mommy span:nth-child(131):before {
animation-delay: 0s, -0.87333s;
}
.mommy span:nth-child(132) {
transform: translate3d(-201.69306px, 140.09077px, 46.84533px);
color: #00ffa3;
}
.mommy span:nth-child(132):before {
animation-delay: 0s, -0.88s;
}
.mommy span:nth-child(133) {
transform: translate3d(-240.79242px, 50.58726px, 44.27119px);
color: #00ffa8;
}
.mommy span:nth-child(133):before {
animation-delay: 0s, -0.88667s;
}
.mommy span:nth-child(134) {
transform: translate3d(-241.92587px, -47.26134px, 41.69219px);
color: #00ffad;
}
.mommy span:nth-child(134):before {
animation-delay: 0s, -0.89333s;
}
.mommy span:nth-child(135) {
transform: translate3d(-204.77491px, -137.97736px, 39.10862px);
color: #00ffb3;
}
.mommy span:nth-child(135):before {
animation-delay: 0s, -0.9s;
}
.mommy span:nth-child(136) {
transform: translate3d(-135.09558px, -207.16037px, 36.52076px);
color: #00ffb8;
}
.mommy span:nth-child(136):before {
1019
animation-delay: 0s, -0.90667s;
}
.mommy span:nth-child(137) {
transform: translate3d(-43.82449px, -243.77909px, 33.92889px);
color: #00ffbd;
}
.mommy span:nth-child(137):before {
animation-delay: 0s, -0.91333s;
}
.mommy span:nth-child(138) {
transform: translate3d(54.6423px, -241.93479px, 31.33331px);
color: #00ffc2;
}
.mommy span:nth-child(138):before {
animation-delay: 0s, -0.92s;
}
.mommy span:nth-child(139) {
transform: translate3d(144.72603px, -201.81357px, 28.73429px);
color: #00ffc7;
}
.mommy span:nth-child(139):before {
animation-delay: 0s, -0.92667s;
}
.mommy span:nth-child(140) {
transform: translate3d(212.13652px, -129.67347px, 26.13212px);
color: #00ffcc;
}
.mommy span:nth-child(140):before {
animation-delay: 0s, -0.93333s;
}
.mommy span:nth-child(141) {
transform: translate3d(246.14505px, -36.86584px, 23.52708px);
color: #00ffd1;
}
.mommy span:nth-child(141):before {
animation-delay: 0s, -0.94s;
}
.mommy span:nth-child(142) {
transform: translate3d(241.29625px, 61.95559px, 20.91946px);
color: #00ffd6;
}
.mommy span:nth-child(142):before {
animation-delay: 0s, -0.94667s;
}
.mommy span:nth-child(143) {
transform: translate3d(198.28528px, 151.15459px, 18.30955px);
color: #00ffdb;
}
.mommy span:nth-child(143):before {
animation-delay: 0s, -0.95333s;
}
1020
.mommy span:nth-child(144) {
transform: translate3d(123.85886px, 216.59309px, 15.69763px);
color: #00ffe0;
}
.mommy span:nth-child(144):before {
animation-delay: 0s, -0.96s;
}
.mommy span:nth-child(145) {
transform: translate3d(29.7542px, 247.87799px, 13.08399px);
color: #00ffe6;
}
.mommy span:nth-child(145):before {
animation-delay: 0s, -0.96667s;
}
.mommy span:nth-child(146) {
transform: translate3d(-69.15695px, 240.01608px, 10.46891px);
color: #00ffeb;
}
.mommy span:nth-child(146):before {
animation-delay: 0s, -0.97333s;
}
.mommy span:nth-child(147) {
transform: translate3d(-157.22479px, 194.21303px, 7.85269px);
color: #00fff0;
}
.mommy span:nth-child(147):before {
animation-delay: 0s, -0.98s;
}
.mommy span:nth-child(148) {
transform: translate3d(-220.5042px, 117.6881px, 5.2356px);
color: #00fff5;
}
.mommy span:nth-child(148):before {
animation-delay: 0s, -0.98667s;
}
.mommy span:nth-child(149) {
transform: translate3d(-248.96867px, 22.53324px, 2.61795px);
color: #00fffa;
}
.mommy span:nth-child(149):before {
animation-delay: 0s, -0.99333s;
}
.mommy span:nth-child(150) {
transform: translate3d(-238.10325px, -76.20266px, 0px);
color: cyan;
}
.mommy span:nth-child(150):before {
animation-delay: 0s, -1s;
}
.mommy span:nth-child(151) {
1021
transform: translate3d(-189.6225px, -162.90013px, -2.61795px);
color: #00faff;
}
.mommy span:nth-child(151):before {
animation-delay: 0s, -1.00667s;
}
.mommy span:nth-child(152) {
transform: translate3d(-111.1993px, -223.84661px, -5.2356px);
color: #00f5ff;
}
.mommy span:nth-child(152):before {
animation-delay: 0s, -1.01333s;
}
.mommy span:nth-child(153) {
transform: translate3d(-15.24718px, -249.41102px, -7.85269px);
color: #00f0ff;
}
.mommy span:nth-child(153):before {
animation-delay: 0s, -1.02s;
}
.mommy span:nth-child(154) {
transform: translate3d(83.04975px, -235.56982px, -10.46891px);
color: #00ebff;
}
.mommy span:nth-child(154):before {
animation-delay: 0s, -1.02667s;
}
.mommy span:nth-child(155) {
transform: translate3d(168.14604px, -184.54192px, -13.08399px);
color: #00e6ff;
}
.mommy span:nth-child(155):before {
animation-delay: 0s, -1.03333s;
}
.mommy span:nth-child(156) {
transform: translate3d(226.5999px, -104.43214px, -15.69763px);
color: #00e0ff;
}
.mommy span:nth-child(156):before {
animation-delay: 0s, -1.04s;
}
.mommy span:nth-child(157) {
transform: translate3d(249.20214px, -7.94054px, -18.30955px);
color: #00dbff;
}
.mommy span:nth-child(157):before {
animation-delay: 0s, -1.04667s;
}
.mommy span:nth-child(158) {
transform: translate3d(232.43092px, 89.65624px, -20.91946px);
color: #00d6ff;
1022
}
.mommy span:nth-child(158):before {
animation-delay: 0s, -1.05333s;
}
.mommy span:nth-child(159) {
transform: translate3d(179.0019px, 172.93004px, -23.52708px);
color: #00d1ff;
}
.mommy span:nth-child(159):before {
animation-delay: 0s, -1.06s;
}
.mommy span:nth-child(160) {
transform: translate3d(97.42765px, 228.74651px, -26.13212px);
color: #00ccff;
}
.mommy span:nth-child(160):before {
animation-delay: 0s, -1.06667s;
}
.mommy span:nth-child(161) {
transform: translate3d(0.65796px, 248.34232px, -28.73429px);
color: #00c7ff;
}
.mommy span:nth-child(161):before {
animation-delay: 0s, -1.07333s;
}
.mommy span:nth-child(162) {
transform: translate3d(-95.98132px, 228.70463px, -31.33331px);
color: #00c2ff;
}
.mommy span:nth-child(162):before {
animation-delay: 0s, -1.08s;
}
.mommy span:nth-child(163) {
transform: translate3d(-177.22193px, 173.03531px, -33.92889px);
color: #00bdff;
}
.mommy span:nth-child(163):before {
animation-delay: 0s, -1.08667s;
}
.mommy span:nth-child(164) {
transform: translate3d(-230.27188px, 90.22802px, -36.52076px);
color: #00b8ff;
}
.mommy span:nth-child(164):before {
animation-delay: 0s, -1.09333s;
}
.mommy span:nth-child(165) {
transform: translate3d(-246.83503px, -6.55607px, -39.10862px);
color: #00b3ff;
}
.mommy span:nth-child(165):before {
1023
animation-delay: 0s, -1.1s;
}
.mommy span:nth-child(166) {
transform: translate3d(-224.4119px, -101.98558px, -41.69219px);
color: #00adff;
}
.mommy span:nth-child(166):before {
animation-delay: 0s, -1.10667s;
}
.mommy span:nth-child(167) {
transform: translate3d(-166.67708px, -180.99396px, -44.27119px);
color: #00a8ff;
}
.mommy span:nth-child(167):before {
animation-delay: 0s, -1.11333s;
}
.mommy span:nth-child(168) {
transform: translate3d(-82.87638px, -231.16449px, -46.84533px);
color: #00a3ff;
}
.mommy span:nth-child(168):before {
animation-delay: 0s, -1.12s;
}
.mommy span:nth-child(169) {
transform: translate3d(13.6574px, -244.68694px, -49.41434px);
color: #009eff;
}
.mommy span:nth-child(169):before {
animation-delay: 0s, -1.12667s;
}
.mommy span:nth-child(170) {
transform: translate3d(107.63121px, -219.57645px, -51.97792px);
color: #0099ff;
}
.mommy span:nth-child(170):before {
animation-delay: 0s, -1.13333s;
}
.mommy span:nth-child(171) {
transform: translate3d(184.2209px, -159.96408px, -54.53581px);
color: #0094ff;
}
.mommy span:nth-child(171):before {
animation-delay: 0s, -1.14s;
}
.mommy span:nth-child(172) {
transform: translate3d(231.41593px, -75.41658px, -57.08772px);
color: #008fff;
}
.mommy span:nth-child(172):before {
animation-delay: 0s, -1.14667s;
}
1024
.mommy span:nth-child(173) {
transform: translate3d(241.90783px, 20.60248px, -59.63336px);
color: #008aff;
}
.mommy span:nth-child(173):before {
animation-delay: 0s, -1.15333s;
}
.mommy span:nth-child(174) {
transform: translate3d(214.22465px, 112.88217px, -62.17247px);
color: #0085ff;
}
.mommy span:nth-child(174):before {
animation-delay: 0s, -1.16s;
}
.mommy span:nth-child(175) {
transform: translate3d(152.93484px, 186.88025px, -64.70476px);
color: #0080ff;
}
.mommy span:nth-child(175):before {
animation-delay: 0s, -1.16667s;
}
.mommy span:nth-child(176) {
transform: translate3d(67.89294px, 231.02096px, -67.22996px);
color: #007aff;
}
.mommy span:nth-child(176):before {
animation-delay: 0s, -1.17333s;
}
.mommy span:nth-child(177) {
transform: translate3d(-27.34855px, 238.5106px, -69.74778px);
color: #0075ff;
}
.mommy span:nth-child(177):before {
animation-delay: 0s, -1.18s;
}
.mommy span:nth-child(178) {
transform: translate3d(-117.7044px, 208.38537px, -72.25795px);
color: #0070ff;
}
.mommy span:nth-child(178):before {
animation-delay: 0s, -1.18667s;
}
.mommy span:nth-child(179) {
transform: translate3d(-188.9523px, 145.62946px, -74.7602px);
color: #006bff;
}
.mommy span:nth-child(179):before {
animation-delay: 0s, -1.19333s;
}
.mommy span:nth-child(180) {
1025
transform: translate3d(-229.97749px, 60.35009px, -77.25425px);
color: #0066ff;
}
.mommy span:nth-child(180):before {
animation-delay: 0s, -1.2s;
}
.mommy span:nth-child(181) {
transform: translate3d(-234.51114px, -33.85389px, -79.73983px);
color: #0061ff;
}
.mommy span:nth-child(181):before {
animation-delay: 0s, -1.20667s;
}
.mommy span:nth-child(182) {
transform: translate3d(-202.08986px, -122.066px, -82.21666px);
color: #005cff;
}
.mommy span:nth-child(182):before {
animation-delay: 0s, -1.21333s;
}
.mommy span:nth-child(183) {
transform: translate3d(-138.08932px, -190.42027px, -84.68448px);
color: #0057ff;
}
.mommy span:nth-child(183):before {
animation-delay: 0s, -1.22s;
}
.mommy span:nth-child(184) {
transform: translate3d(-52.83268px, -228.28667px, -87.14301px);
color: #0052ff;
}
.mommy span:nth-child(184):before {
animation-delay: 0s, -1.22667s;
}
.mommy span:nth-child(185) {
transform: translate3d(40.07799px, -229.92832px, -89.59199px);
color: #004dff;
}
.mommy span:nth-child(185):before {
animation-delay: 0s, -1.23333s;
}
.mommy span:nth-child(186) {
transform: translate3d(125.93733px, -195.37159px, -92.03114px);
color: #0047ff;
}
.mommy span:nth-child(186):before {
animation-delay: 0s, -1.24s;
}
.mommy span:nth-child(187) {
transform: translate3d(191.27035px, -130.35691px, -94.4602px);
color: #0042ff;
1026
}
.mommy span:nth-child(187):before {
animation-delay: 0s, -1.24667s;
}
.mommy span:nth-child(188) {
transform: translate3d(225.95279px, -45.38519px, -96.8789px);
color: #003dff;
}
.mommy span:nth-child(188):before {
animation-delay: 0s, -1.25333s;
}
.mommy span:nth-child(189) {
transform: translate3d(224.78384px, 45.98178px, -99.28697px);
color: #0038ff;
}
.mommy span:nth-child(189):before {
animation-delay: 0s, -1.26s;
}
.mommy span:nth-child(190) {
transform: translate3d(188.26604px, 129.29127px, -101.68416px);
color: #0033ff;
}
.mommy span:nth-child(190):before {
animation-delay: 0s, -1.26667s;
}
.mommy span:nth-child(191) {
transform: translate3d(122.47564px, 191.49181px, -104.0702px);
color: #002eff;
}
.mommy span:nth-child(191):before {
animation-delay: 0s, -1.27333s;
}
.mommy span:nth-child(192) {
transform: translate3d(38.05169px, 222.98334px, -106.44482px);
color: #0029ff;
}
.mommy span:nth-child(192):before {
animation-delay: 0s, -1.28s;
}
.mommy span:nth-child(193) {
transform: translate3d(-51.52785px, 219.10214px, -108.80777px);
color: #0024ff;
}
.mommy span:nth-child(193):before {
animation-delay: 0s, -1.28667s;
}
.mommy span:nth-child(194) {
transform: translate3d(-132.10323px, 180.81056px, -111.15879px);
color: #001fff;
}
.mommy span:nth-child(194):before {
1027
animation-delay: 0s, -1.29333s;
}
.mommy span:nth-child(195) {
transform: translate3d(-191.07704px, 114.48954px, -113.49762px);
color: #001aff;
}
.mommy span:nth-child(195):before {
animation-delay: 0s, -1.3s;
}
.mommy span:nth-child(196) {
transform: translate3d(-219.38891px, 30.87561px, -115.82401px);
color: #0014ff;
}
.mommy span:nth-child(196):before {
animation-delay: 0s, -1.30667s;
}
.mommy span:nth-child(197) {
transform: translate3d(-212.9103px, -56.6806px, -118.13769px);
color: #000fff;
}
.mommy span:nth-child(197):before {
animation-delay: 0s, -1.31333s;
}
.mommy span:nth-child(198) {
transform: translate3d(-173.0442px, -134.35138px, -120.43842px);
color: #000aff;
}
.mommy span:nth-child(198):before {
animation-delay: 0s, -1.32s;
}
.mommy span:nth-child(199) {
transform: translate3d(-106.44313px, -190.02159px, -122.72594px);
color: #0005ff;
}
.mommy span:nth-child(199):before {
animation-delay: 0s, -1.32667s;
}
.mommy span:nth-child(200) {
transform: translate3d(-23.89954px, -215.18321px, -125px);
color: blue;
}
.mommy span:nth-child(200):before {
animation-delay: 0s, -1.33333s;
}
.mommy span:nth-child(201) {
transform: translate3d(61.40643px, -206.23785px, -127.26035px);
color: #0500ff;
}
.mommy span:nth-child(201):before {
animation-delay: 0s, -1.34s;
}
1028
.mommy span:nth-child(202) {
transform: translate3d(136.01672px, -165.00743px, -129.50675px);
color: #0a00ff;
}
.mommy span:nth-child(202):before {
animation-delay: 0s, -1.34667s;
}
.mommy span:nth-child(203) {
transform: translate3d(188.32419px, -98.38113px, -131.73895px);
color: #0f00ff;
}
.mommy span:nth-child(203):before {
animation-delay: 0s, -1.35333s;
}
.mommy span:nth-child(204) {
transform: translate3d(210.3829px, -17.165px, -133.9567px);
color: #1400ff;
}
.mommy span:nth-child(204):before {
animation-delay: 0s, -1.36s;
}
.mommy span:nth-child(205) {
transform: translate3d(199.11668px, 65.67394px, -136.15976px);
color: #1a00ff;
}
.mommy span:nth-child(205):before {
animation-delay: 0s, -1.36667s;
}
.mommy span:nth-child(206) {
transform: translate3d(156.74204px, 137.08316px, -138.34789px);
color: #1f00ff;
}
.mommy span:nth-child(206):before {
animation-delay: 0s, -1.37333s;
}
.mommy span:nth-child(207) {
transform: translate3d(90.34827px, 185.98678px, -140.52084px);
color: #2400ff;
}
.mommy span:nth-child(207):before {
animation-delay: 0s, -1.38s;
}
.mommy span:nth-child(208) {
transform: translate3d(10.71222px, 205.00762px, -142.67839px);
color: #2900ff;
}
.mommy span:nth-child(208):before {
animation-delay: 0s, -1.38667s;
}
.mommy span:nth-child(209) {
1029
transform: translate3d(-69.45406px, 191.58084px, -144.82029px);
color: #2e00ff;
}
.mommy span:nth-child(209):before {
animation-delay: 0s, -1.39333s;
}
.mommy span:nth-child(210) {
transform: translate3d(-137.53764px, 148.29086px, -146.94631px);
color: #3300ff;
}
.mommy span:nth-child(210):before {
animation-delay: 0s, -1.4s;
}
.mommy span:nth-child(211) {
transform: translate3d(-183.01446px, 82.38902px, -149.05622px);
color: #3800ff;
}
.mommy span:nth-child(211):before {
animation-delay: 0s, -1.40667s;
}
.mommy span:nth-child(212) {
transform: translate3d(-199.0798px, 4.57997px, -151.14978px);
color: #3d00ff;
}
.mommy span:nth-child(212):before {
animation-delay: 0s, -1.41333s;
}
.mommy span:nth-child(213) {
transform: translate3d(-183.66636px, -72.72019px, -153.22676px);
color: #4200ff;
}
.mommy span:nth-child(213):before {
animation-delay: 0s, -1.42s;
}
.mommy span:nth-child(214) {
transform: translate3d(-139.69754px, -137.37017px, -155.28695px);
color: #4700ff;
}
.mommy span:nth-child(214):before {
animation-delay: 0s, -1.42667s;
}
.mommy span:nth-child(215) {
transform: translate3d(-74.54742px, -179.4155px, -157.3301px);
color: #4d00ff;
}
.mommy span:nth-child(215):before {
animation-delay: 0s, -1.43333s;
}
.mommy span:nth-child(216) {
transform: translate3d(1.19468px, -192.62461px, -159.356px);
color: #5200ff;
1030
}
.mommy span:nth-child(216):before {
animation-delay: 0s, -1.44s;
}
.mommy span:nth-child(217) {
transform: translate3d(75.44839px, -175.41113px, -161.36442px);
color: #5700ff;
}
.mommy span:nth-child(217):before {
animation-delay: 0s, -1.44667s;
}
.mommy span:nth-child(218) {
transform: translate3d(136.57388px, -131.00637px, -163.35515px);
color: #5c00ff;
}
.mommy span:nth-child(218):before {
animation-delay: 0s, -1.45333s;
}
.mommy span:nth-child(219) {
transform: translate3d(175.20129px, -66.86683px, -165.32797px);
color: #6100ff;
}
.mommy span:nth-child(219):before {
animation-delay: 0s, -1.46s;
}
.mommy span:nth-child(220) {
transform: translate3d(185.66977px, 6.57652px, -167.28265px);
color: #6600ff;
}
.mommy span:nth-child(220):before {
animation-delay: 0s, -1.46667s;
}
.mommy span:nth-child(221) {
transform: translate3d(166.85462px, 77.61744px, -169.21899px);
color: #6b00ff;
}
.mommy span:nth-child(221):before {
animation-delay: 0s, -1.47333s;
}
.mommy span:nth-child(222) {
transform: translate3d(122.26205px, 135.14509px, -171.13678px);
color: #7000ff;
}
.mommy span:nth-child(222):before {
animation-delay: 0s, -1.48s;
}
.mommy span:nth-child(223) {
transform: translate3d(59.38969px, 170.38626px, -173.03579px);
color: #7500ff;
}
.mommy span:nth-child(223):before {
1031
animation-delay: 0s, -1.48667s;
}
.mommy span:nth-child(224) {
transform: translate3d(-11.53238px, 178.24549px, -174.91584px);
color: #7a00ff;
}
.mommy span:nth-child(224):before {
animation-delay: 0s, -1.49333s;
}
.mommy span:nth-child(225) {
transform: translate3d(-79.20897px, 158.03778px, -176.7767px);
color: #8000ff;
}
.mommy span:nth-child(225):before {
animation-delay: 0s, -1.5s;
}
.mommy span:nth-child(226) {
transform: translate3d(-133.08328px, 113.50942px, -178.61817px);
color: #8500ff;
}
.mommy span:nth-child(226):before {
animation-delay: 0s, -1.50667s;
}
.mommy span:nth-child(227) {
transform: translate3d(-164.98787px, 52.15734px, -180.44006px);
color: #8a00ff;
}
.mommy span:nth-child(227):before {
animation-delay: 0s, -1.51333s;
}
.mommy span:nth-child(228) {
transform: translate3d(-170.38425px, -16.03132px, -182.24216px);
color: #8f00ff;
}
.mommy span:nth-child(228):before {
animation-delay: 0s, -1.52s;
}
.mommy span:nth-child(229) {
transform: translate3d(-149.00273px, -80.20757px, -184.02427px);
color: #9400ff;
}
.mommy span:nth-child(229):before {
animation-delay: 0s, -1.52667s;
}
.mommy span:nth-child(230) {
transform: translate3d(-104.79329px, -130.39115px, -185.78621px);
color: #9900ff;
}
.mommy span:nth-child(230):before {
animation-delay: 0s, -1.53333s;
}
1032
.mommy span:nth-child(231) {
transform: translate3d(-45.20979px, -159.02645px, -187.52777px);
color: #9e00ff;
}
.mommy span:nth-child(231):before {
animation-delay: 0s, -1.54s;
}
.mommy span:nth-child(232) {
transform: translate3d(20.04477px, -162.12067px, -189.24876px);
color: #a300ff;
}
.mommy span:nth-child(232):before {
animation-delay: 0s, -1.54667s;
}
.mommy span:nth-child(233) {
transform: translate3d(80.60086px, -139.79263px, -190.94901px);
color: #a800ff;
}
.mommy span:nth-child(233):before {
animation-delay: 0s, -1.55333s;
}
.mommy span:nth-child(234) {
transform: translate3d(127.07455px, -96.15817px, -192.62831px);
color: #ad00ff;
}
.mommy span:nth-child(234):before {
animation-delay: 0s, -1.56s;
}
.mommy span:nth-child(235) {
transform: translate3d(152.52514px, -38.58552px, -194.28649px);
color: #b300ff;
}
.mommy span:nth-child(235):before {
animation-delay: 0s, -1.56667s;
}
.mommy span:nth-child(236) {
transform: translate3d(153.49134px, 23.54666px, -195.92336px);
color: #b800ff;
}
.mommy span:nth-child(236):before {
animation-delay: 0s, -1.57333s;
}
.mommy span:nth-child(237) {
transform: translate3d(130.45142px, 80.37952px, -197.53875px);
color: #bd00ff;
}
.mommy span:nth-child(237):before {
animation-delay: 0s, -1.58s;
}
.mommy span:nth-child(238) {
1033
transform: translate3d(87.64806px, 123.14249px, -199.13248px);
color: #c200ff;
}
.mommy span:nth-child(238):before {
animation-delay: 0s, -1.58667s;
}
.mommy span:nth-child(239) {
transform: translate3d(32.3213px, 145.50976px, -200.70437px);
color: #c700ff;
}
.mommy span:nth-child(239):before {
animation-delay: 0s, -1.59333s;
}
.mommy span:nth-child(240) {
transform: translate3d(-26.51359px, 144.53459px, -202.25425px);
color: #cc00ff;
}
.mommy span:nth-child(240):before {
animation-delay: 0s, -1.6s;
}
.mommy span:nth-child(241) {
transform: translate3d(-79.53741px, 121.02362px, -203.78195px);
color: #d100ff;
}
.mommy span:nth-child(241):before {
animation-delay: 0s, -1.60667s;
}
.mommy span:nth-child(242) {
transform: translate3d(-118.60709px, 79.30626px, -205.2873px);
color: #d600ff;
}
.mommy span:nth-child(242):before {
animation-delay: 0s, -1.61333s;
}
.mommy span:nth-child(243) {
transform: translate3d(-138.0087px, 26.45198px, -206.77014px);
color: #db00ff;
}
.mommy span:nth-child(243):before {
animation-delay: 0s, -1.62s;
}
.mommy span:nth-child(244) {
transform: translate3d(-135.29038px, -28.92492px, -208.23031px);
color: #e000ff;
}
.mommy span:nth-child(244):before {
animation-delay: 0s, -1.62667s;
}
.mommy span:nth-child(245) {
transform: translate3d(-111.55409px, -78.07154px, -209.66764px);
color: #e600ff;
1034
}
.mommy span:nth-child(245):before {
animation-delay: 0s, -1.63333s;
}
.mommy span:nth-child(246) {
transform: translate3d(-71.17508px, -113.4835px, -211.08198px);
color: #eb00ff;
}
.mommy span:nth-child(246):before {
animation-delay: 0s, -1.64s;
}
.mommy span:nth-child(247) {
transform: translate3d(-21.01034px, -130.05274px, -212.47317px);
color: #f000ff;
}
.mommy span:nth-child(247):before {
animation-delay: 0s, -1.64667s;
}
.mommy span:nth-child(248) {
transform: translate3d(30.76289px, -125.80001px, -213.84107px);
color: #f500ff;
}
.mommy span:nth-child(248):before {
animation-delay: 0s, -1.65333s;
}
.mommy span:nth-child(249) {
transform: translate3d(75.98209px, -102.0878px, -215.18551px);
color: #fa00ff;
}
.mommy span:nth-child(249):before {
animation-delay: 0s, -1.66s;
}
.mommy span:nth-child(250) {
transform: translate3d(107.78986px, -63.29571px, -216.50635px);
color: magenta;
}
.mommy span:nth-child(250):before {
animation-delay: 0s, -1.66667s;
}
.mommy span:nth-child(251) {
transform: translate3d(121.67496px, -16.02689px, -217.80345px);
color: #ff00fa;
}
.mommy span:nth-child(251):before {
animation-delay: 0s, -1.67333s;
}
.mommy span:nth-child(252) {
transform: translate3d(116.10599px, 32.01269px, -219.07667px);
color: #ff00f5;
}
.mommy span:nth-child(252):before {
1035
animation-delay: 0s, -1.68s;
}
.mommy span:nth-child(253) {
transform: translate3d(92.66963px, 73.27247px, -220.32586px);
color: #ff00f0;
}
.mommy span:nth-child(253):before {
animation-delay: 0s, -1.68667s;
}
.mommy span:nth-child(254) {
transform: translate3d(55.70792px, 101.54717px, -221.55089px);
color: #ff00eb;
}
.mommy span:nth-child(254):before {
animation-delay: 0s, -1.69333s;
}
.mommy span:nth-child(255) {
transform: translate3d(11.52974px, 112.91048px, -222.75163px);
color: #ff00e6;
}
.mommy span:nth-child(255):before {
animation-delay: 0s, -1.7s;
}
.mommy span:nth-child(256) {
transform: translate3d(-32.66259px, 106.25174px, -223.92794px);
color: #ff00e0;
}
.mommy span:nth-child(256):before {
animation-delay: 0s, -1.70667s;
}
.mommy span:nth-child(257) {
transform: translate3d(-69.94921px, 83.3441px, -225.07969px);
color: #ff00db;
}
.mommy span:nth-child(257):before {
animation-delay: 0s, -1.71333s;
}
.mommy span:nth-child(258) {
transform: translate3d(-94.77922px, 48.44996px, -226.20676px);
color: #ff00d6;
}
.mommy span:nth-child(258):before {
animation-delay: 0s, -1.72s;
}
.mommy span:nth-child(259) {
transform: translate3d(-103.79637px, 7.54446px, -227.30903px);
color: #ff00d1;
}
.mommy span:nth-child(259):before {
animation-delay: 0s, -1.72667s;
}
1036
.mommy span:nth-child(260) {
transform: translate3d(-96.28148px, -32.7039px, -228.38636px);
color: #ff00cc;
}
.mommy span:nth-child(260):before {
animation-delay: 0s, -1.73333s;
}
.mommy span:nth-child(261) {
transform: translate3d(-74.15521px, -66.02203px, -229.43866px);
color: #ff00c7;
}
.mommy span:nth-child(261):before {
animation-delay: 0s, -1.74s;
}
.mommy span:nth-child(262) {
transform: translate3d(-41.55829px, -87.51245px, -230.46579px);
color: #ff00c2;
}
.mommy span:nth-child(262):before {
animation-delay: 0s, -1.74667s;
}
.mommy span:nth-child(263) {
transform: translate3d(-4.09393px, -94.37144px, -231.46765px);
color: #ff00bd;
}
.mommy span:nth-child(263):before {
animation-delay: 0s, -1.75333s;
}
.mommy span:nth-child(264) {
transform: translate3d(32.13114px, -86.2399px, -232.44412px);
color: #ff00b8;
}
.mommy span:nth-child(264):before {
animation-delay: 0s, -1.76s;
}
.mommy span:nth-child(265) {
transform: translate3d(61.50369px, -65.14614px, -233.39511px);
color: #ff00b3;
}
.mommy span:nth-child(265):before {
animation-delay: 0s, -1.76667s;
}
.mommy span:nth-child(266) {
transform: translate3d(79.77582px, -35.06741px, -234.3205px);
color: #ff00ad;
}
.mommy span:nth-child(266):before {
animation-delay: 0s, -1.77333s;
}
.mommy span:nth-child(267) {
1037
transform: translate3d(84.676px, -1.19826px, -235.22019px);
color: #ff00a8;
}
.mommy span:nth-child(267):before {
animation-delay: 0s, -1.78s;
}
.mommy span:nth-child(268) {
transform: translate3d(76.17201px, 30.94196px, -236.09409px);
color: #ff00a3;
}
.mommy span:nth-child(268):before {
animation-delay: 0s, -1.78667s;
}
.mommy span:nth-child(269) {
transform: translate3d(56.3591px, 56.41003px, -236.9421px);
color: #ff009e;
}
.mommy span:nth-child(269):before {
animation-delay: 0s, -1.79333s;
}
.mommy span:nth-child(270) {
transform: translate3d(29.00971px, 71.60067px, -237.76413px);
color: #ff0099;
}
.mommy span:nth-child(270):before {
animation-delay: 0s, -1.8s;
}
.mommy span:nth-child(271) {
transform: translate3d(-1.12536px, 74.75173px, -238.56008px);
color: #ff0094;
}
.mommy span:nth-child(271):before {
animation-delay: 0s, -1.80667s;
}
.mommy span:nth-child(272) {
transform: translate3d(-29.13721px, 66.12287px, -239.32987px);
color: #ff008f;
}
.mommy span:nth-child(272):before {
animation-delay: 0s, -1.81333s;
}
.mommy span:nth-child(273) {
transform: translate3d(-50.7598px, 47.83508px, -240.07342px);
color: #ff008a;
}
.mommy span:nth-child(273):before {
animation-delay: 0s, -1.82s;
}
.mommy span:nth-child(274) {
transform: translate3d(-63.02055px, 23.41531px, -240.79064px);
color: #ff0085;
1038
}
.mommy span:nth-child(274):before {
animation-delay: 0s, -1.82667s;
}
.mommy span:nth-child(275) {
transform: translate3d(-64.6414px, -2.86271px, -241.48146px);
color: #ff0080;
}
.mommy span:nth-child(275):before {
animation-delay: 0s, -1.83333s;
}
.mommy span:nth-child(276) {
transform: translate3d(-56.1374px, -26.72093px, -242.14579px);
color: #ff007a;
}
.mommy span:nth-child(276):before {
animation-delay: 0s, -1.84s;
}
.mommy span:nth-child(277) {
transform: translate3d(-39.61365px, -44.57462px, -242.78357px);
color: #ff0075;
}
.mommy span:nth-child(277):before {
animation-delay: 0s, -1.84667s;
}
.mommy span:nth-child(278) {
transform: translate3d(-18.31186px, -54.0711px, -243.39473px);
color: #ff0070;
}
.mommy span:nth-child(278):before {
animation-delay: 0s, -1.85333s;
}
.mommy span:nth-child(279) {
transform: translate3d(4.00264px, -54.38873px, -243.97919px);
color: #ff006b;
}
.mommy span:nth-child(279):before {
animation-delay: 0s, -1.86s;
}
.mommy span:nth-child(280) {
transform: translate3d(23.70033px, -46.26012px, -244.5369px);
color: #ff0066;
}
.mommy span:nth-child(280):before {
animation-delay: 0s, -1.86667s;
}
.mommy span:nth-child(281) {
transform: translate3d(37.87885px, -31.73277px, -245.06779px);
color: #ff0061;
}
.mommy span:nth-child(281):before {
1039
animation-delay: 0s, -1.87333s;
}
.mommy span:nth-child(282) {
transform: translate3d(44.78978px, -13.72445px, -245.57181px);
color: #ff005c;
}
.mommy span:nth-child(282):before {
animation-delay: 0s, -1.88s;
}
.mommy span:nth-child(283) {
transform: translate3d(44.03808px, 4.5371px, -246.0489px);
color: #ff0057;
}
.mommy span:nth-child(283):before {
animation-delay: 0s, -1.88667s;
}
.mommy span:nth-child(284) {
transform: translate3d(36.53495px, 20.08572px, -246.49901px);
color: #ff0052;
}
.mommy span:nth-child(284):before {
animation-delay: 0s, -1.89333s;
}
.mommy span:nth-child(285) {
transform: translate3d(24.22859px, 30.6995px, -246.92209px);
color: #ff004d;
}
.mommy span:nth-child(285):before {
animation-delay: 0s, -1.9s;
}
.mommy span:nth-child(286) {
transform: translate3d(9.67546px, 35.21578px, -247.31808px);
color: #ff0047;
}
.mommy span:nth-child(286):before {
animation-delay: 0s, -1.90667s;
}
.mommy span:nth-child(287) {
transform: translate3d(-4.46118px, 33.63432px, -247.68696px);
color: #ff0042;
}
.mommy span:nth-child(287):before {
animation-delay: 0s, -1.91333s;
}
.mommy span:nth-child(288) {
transform: translate3d(-15.89051px, 27.00496px, -248.02868px);
color: #ff003d;
}
.mommy span:nth-child(288):before {
animation-delay: 0s, -1.92s;
}
1040
.mommy span:nth-child(289) {
transform: translate3d(-23.06603px, 17.13527px, -248.34319px);
color: #ff0038;
}
.mommy span:nth-child(289):before {
animation-delay: 0s, -1.92667s;
}
.mommy span:nth-child(290) {
transform: translate3d(-25.38976px, 6.18446px, -248.63047px);
color: #ff0033;
}
.mommy span:nth-child(290):before {
animation-delay: 0s, -1.93333s;
}
.mommy span:nth-child(291) {
transform: translate3d(-23.22254px, -3.77318px, -248.89049px);
color: #ff002e;
}
.mommy span:nth-child(291):before {
animation-delay: 0s, -1.94s;
}
.mommy span:nth-child(292) {
transform: translate3d(-17.7122px, -11.13112px, -249.12321px);
color: #ff0029;
}
.mommy span:nth-child(292):before {
animation-delay: 0s, -1.94667s;
}
.mommy span:nth-child(293) {
transform: translate3d(-10.48481px, -15.01027px, -249.32862px);
color: #ff0024;
}
.mommy span:nth-child(293):before {
animation-delay: 0s, -1.95333s;
}
.mommy span:nth-child(294) {
transform: translate3d(-3.2681px, -15.35367px, -249.50668px);
color: #ff001f;
}
.mommy span:nth-child(294):before {
animation-delay: 0s, -1.96s;
}
.mommy span:nth-child(295) {
transform: translate3d(2.47457px, -12.84785px, -249.65738px);
color: #ff001a;
}
.mommy span:nth-child(295):before {
animation-delay: 0s, -1.96667s;
}
.mommy span:nth-child(296) {
1041
transform: translate3d(5.82689px, -8.69744px, -249.78071px);
color: #ff0014;
}
.mommy span:nth-child(296):before {
animation-delay: 0s, -1.97333s;
}
.mommy span:nth-child(297) {
transform: translate3d(6.56624px, -4.30688px, -249.87664px);
color: #ff000f;
}
.mommy span:nth-child(297):before {
animation-delay: 0s, -1.98s;
}
.mommy span:nth-child(298) {
transform: translate3d(5.15053px, -0.94001px, -249.94517px);
color: #ff000a;
}
.mommy span:nth-child(298):before {
animation-delay: 0s, -1.98667s;
}
.mommy span:nth-child(299) {
transform: translate3d(2.55514px, 0.56998px, -249.98629px);
color: #ff0005;
}
.mommy span:nth-child(299):before {
animation-delay: 0s, -1.99333s;
}
.mommy span:nth-child(300) {
transform: translate3d(0px, 0px, -250px);
color: red;
}
.mommy span:nth-child(300):before {
animation-delay: 0s, -2s;
}
@keyframes rotate {
to {
transform: rotateY(360deg);
}
}
@keyframes invertRotate {
to {
transform: rotateY(-360deg);
}
}
@keyframes scale {
0%, 45%,55% {
box-shadow: 0 0 10px 0px currentColor;
}
50% {
box-shadow: 0 0 10px 5px currentColor;
}
}
</style></head><body>
1042
<div class="mommy">
<div
class="daddy"><span></span><span></span><span></span><span></span><span></span><span></span><span
></span><span></span><span></span><span></span><span></span><span></span><span></span><span></spa
n><span></span><span></span><span></span><span></span><span></span><span></span><span></span><spa
n></span><span></span><span></span><span></span><span></span><span></span><span></span><span></sp
an><span></span><span></span><span></span><span></span><span></span><span></span><span></span><sp
an></span><span></span><span></span><span></span><span></span><span></span><span></span><span></s
pan><span></span><span></span><span></span><span></span><span></span><span></span><span></span><s
pan></span><span></span><span></span><span></span><span></span><span></span><span></span><span></
span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><
span></span><span></span><span></span><span></span><span></span><span></span><span></span><span><
/span><span></span><span></span><span></span><span></span><span></span><span></span><span></span>
<span></span><span></span><span></span><span></span><span></span><span></span><span></span><span>
</span><span></span><span></span><span></span><span></span><span></span><span></span><span></span
><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span
></span><span></span><span></span><span></span><span></span><span></span><span></span><span></spa
n><span></span><span></span><span></span><span></span><span></span><span></span><span></span><spa
n></span><span></span><span></span><span></span><span></span><span></span><span></span><span></sp
an><span></span><span></span><span></span><span></span><span></span><span></span><span></span><sp
an></span><span></span><span></span><span></span><span></span><span></span><span></span><span></s
pan><span></span><span></span><span></span><span></span><span></span><span></span><span></span><s
pan></span><span></span><span></span><span></span><span></span><span></span><span></span><span></
span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><
span></span><span></span><span></span><span></span><span></span><span></span><span></span><span><
/span><span></span><span></span><span></span><span></span><span></span><span></span><span></span>
<span></span><span></span><span></span><span></span><span></span><span></span><span></span><span>
</span><span></span><span></span><span></span><span></span><span></span><span></span><span></span
><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span
></span><span></span><span></span><span></span><span></span><span></span><span></span><span></spa
n><span></span><span></span><span></span><span></span><span></span><span></span><span></span><spa
n></span><span></span><span></span><span></span><span></span><span></span><span></span><span></sp
an><span></span><span></span><span></span><span></span><span></span><span></span><span></span><sp
an></span><span></span><span></span><span></span><span></span><span></span><span></span><span></s
pan><span></span><span></span><span></span><span></span><span></span><span></span><span></span><s
pan></span><span></span><span></span><span></span><span></span><span></span><span></span><span></
span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><
span></span><span></span><span></span><span></span><span></span><span></span><span></span><span><
/span><span></span><span></span><span></span><span></span><span></span><span></span><span></span>
<span></span><span></span><span></span><span></span><span></span><span></span><span></span><span>
</span><span></span><span></span><span></span><span></span><span></span><span></span><span></span
><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span
></span><span></span>
</div>
</div>
*****************************************************************************
1043
<style class="cp-pen-styles">
body {
background: #1A181B;
overflow-x: hidden;
}
img {
width: 50%;
height: auto;
}
hr {
width: 80%;
height: 3px;
border: 0;
background: #00cdb2;
}
h1 {
font-size: calc(30px + 4vw);
position: relative;
font-weight: 900;
margin: 0 0 0 50%;
-webkit-transform: translate(-45%, -100%);
transform: translate(-45%, -100%);
outline: none;
text-decoration: none;
color: #552480;
width: 100%;
overflow: hidden;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
.single-line {
width: 100%;
font-family: 'Roboto', sans-serif;
max-width: 960px;
margin: 0 auto;
}
.single-line h1:before {
content: attr(data-letters);
position: absolute;
z-index: 2;
overflow: hidden;
white-space: nowrap;
width: 45%;
color: #00cdb2;
}
.single-line h1 span {
display: block;
}
.single-line h1 span:before {
content: "";
width: 25%;
border-bottom: 8px solid #4d2174;
position: absolute;
display: block;
1044
bottom: 0;
}
.the-long-way h1 {
-webkit-transform: translate(-50%, -100%);
transform: translate(-50%, -100%);
}
.the-long-way h1:before {
content: attr(data-letters);
position: absolute;
z-index: 2;
overflow: hidden;
white-space: nowrap;
width: 50%;
color: #00cdb2;
}
.the-long-way h1 .wrap {
width: 50%;
position: absolute;
top: 0;
display: block;
height: 200px;
overflow: hidden;
}
.the-long-way h1 .split {
width: 200%;
position: absolute;
color: #00cdb2;
}
.the-long-way h1 .split:after {
content: attr(data-letters);
position: absolute;
z-index: 10;
overflow: hidden;
width: 100%;
display: block;
color: #00cdb2;
top: 0;
}
.clip-it h1:before {
content: attr(data-letters);
position: absolute;
z-index: 2;
overflow: hidden;
width: 100%;
-webkit-clip-path: polygon(0 0, 45% 0, 45% 100%, 0% 100%);
clip-path: polygon(0 0, 45% 0, 45% 100%, 0% 100%);
color: #00cdb2;
}
.clip-it h1 span {
display: block;
}
.clip-it h1 span:before {
content: "";
width: 25%;
border-bottom: 8px solid #4d2174;
position: absolute;
1045
display: block;
bottom: 0;
}
p {
text-align: center;
color: #fff;
padding: 2em;
letter-spacing: 0.0525em;
font-weight: 300;
}
strong {
font-weight: 900;
}
</style></head><body>
<div class="single-line">
<p><strong>Single Line:</strong>
<br> Works like a charm!<br/> Scale the viewport to see the text overlap shift 😊</p>
<img src="http://media.boingboing.net/wp-content/uploads/2014/06/giphy-13.gif" />
<h1 data-letters="The final frontier"><span>The final frontier</span></h1>
</div>
<hr>
<div class="clip-it">
<p><strong>The Long Words:</strong>
<br>Pros: All the pros! Cons: Browser support for Clip-path</p>
<img src="http://media.boingboing.net/wp-content/uploads/2014/06/giphy-13.gif" />
<hr>
<div class="the-long-way">
<p><strong>The Long Words:</strong> Pros: more browser support. Cons: Duplicate Content, fixed
height</p>
<img src="http://media.boingboing.net/wp-content/uploads/2014/06/giphy-13.gif" />
<h1 data-letters="The final frontier is outer space">
The final frontier is outer space
<span class="wrap" aria-hidden="true">
<span class="split" data-letters="The final frontier is outer space">The final frontier is
outer space</span
</span>
</h1>
</div>
*************************************************************************************************
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code
as cleverly as possible, you are, by definition, not smart enough to debug it.
1046
Brian Kernighan and P.J. Plauger, The Elements of Programming Style
Yuan-Ma had written a small program that used many global variables and shoddy shortcuts.
Reading it, a student asked, ‘You warned us against these techniques, yet I find them in your
program. How can this be?’ The master said, ‘There is no need to fetch a water hose when the
house is not on fire.’
<script>
var a, d;
try {
var a = 0;
var d = 45/0;
adddlert("Welcome guest!");
}
catch(err) {
alert("There was an error on this page.\n\n")
}
</script>
*************************************************************************************************
Python is a very powerful high-level language (like C, C++, Perl, and Java), object-oriented programming scripting
language designed by Dutch programmer “Guido van Rossum” in the early 1990s (often referred to as a “glue”
language, meaning that it is capable to work in mixed-language environment) which is easy to understand, easy to
use, write, modify and debug and quick to learn and run on open source operating systems like Linux, Windows,
Macintosh, Solaris, FreeBSD, OS/2, Amiga, AROS, AS/400 and is employed to perform automated testing of
applications (i.e., to execute tests of applications, report outcomes and compare results with earlier test runs) and to
increase the effectiveness and speed of software testing.
1047
print "Hello World!\n"
Hello World!
print "Hello World!\n" → implies the statement that make provision to print
Hello World!
on the screen.
(a)
print "Hello World!\n"
print "Hello World!\n"
(b)
(c)
What is the mistake in the following program:
Program 1.2
Python program to add two numbers:
number1=2
number2=3
print "The sum of {0} and {1} is {2}".format(number1, number2, float (number1) + float (number2))
print "The sum of {0} and {1} is {2}".format(number1, number2, float (number1) + float (number2)) → implies the
statement that make provision to print
1048
The sum of 2 and 3 is 5.0
on the screen.
Note:
If you replace the statement
print "The sum of {0} and {1} is {2}".format(number1, number2, float (number1) + float (number2))
by the statement
print "The sum of {1} and {2} is {3}".format(number1, number2, float (number1) + float (number2))
Then
Runtime error or IndexError: tuple index out of range
will be displayed on the screen.
If you want to enter the values for number1 and number2 through keyboard, then you need to replace the statements
number1 = 2
number2 = 3
by the statements
Program 1.3
Python program to subtract two numbers:
1049
If you enter 4
The difference of 6 and 4 is 2.0 will be displayed on the screen.
Program 1.4
Python program to divide two numbers:
Program 1.5
Python program to multiply two numbers:
Program 1.6
Python program to find the area of a circle:
Program 1.7
Python program to find the square root of a number:
1050
print "The square root of the entered number is {0}".format(number1 ** 0.5)
Output on the screen:
Please Enter the number:
If you enter 4
The square root of the entered number is 2.0 will be displayed on the screen.
½=0.5
** → implies: exponent operator
number1 ** 0.5 → implies:
number1 ** ½ (which implies number1 to the power of ½ )
Program 1.8
Python program to find the square of a number
number1=1
print (" {0}".format(number1 ** 1.633))
Program 1.9
Python program to find the incremented and decremented values of the entered number:
(a)
x = 13
if x < 10:
1051
print ("Good morning")
elif x<12:
print ("Soon time for lunch")
elif x<18:
print ("Good day")
elif x<22:
print ("Good evening")
else:
print ("Good night")
(b)
n1 = [0 for i in range(15)]
print (n1)
(c)
for k in range(1,10):
print(k)
(d)
for day in ["Sunday","Monday","Tuesday","Wednesday","Thursday", "Friday","Saturday"]:
print(day)
(e)
n = 10
sum = 0
for i in range(1,n):
sum = sum + i
print (sum)
(f)
for k in range(1,11):
print("5 x {0} = {1}".format(k, 5*k))
*******************************END*******************************
1052
This is an authorized free edition from
www.obooko.com
Although you do not have to pay for this e-book, the author’s intellectual property
rights remain fully protected by international Copyright law. You are licensed to use
this digital copy strictly for your personal enjoyment only: it must not be
redistributed commercially or offered for sale in any form. If you paid for this free
edition, or to gain access to it, we suggest you demand an immediate refund and
report the transaction to the author and obooko.