0% found this document useful (0 votes)
0 views4 pages

Programming 1 Laboratory and Lecture

Chapter 3 discusses the importance of algorithms in solving complex problems efficiently across various fields such as computer science, mathematics, and artificial intelligence. It introduces pseudocode as a high-level description of algorithms and explains the structure of a simple Java program, including the main method and data types. The chapter also covers variable declaration, constants, and basic arithmetic operators in programming.

Uploaded by

Shane Pastor
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views4 pages

Programming 1 Laboratory and Lecture

Chapter 3 discusses the importance of algorithms in solving complex problems efficiently across various fields such as computer science, mathematics, and artificial intelligence. It introduces pseudocode as a high-level description of algorithms and explains the structure of a simple Java program, including the main method and data types. The chapter also covers variable declaration, constants, and basic arithmetic operators in programming.

Uploaded by

Shane Pastor
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

CHAPTER 3: PLANNING THE SOLUTION

What is the need for algorithms?


3.1 ALGORITHMS 1. Algorithms are necessary for solving
complex problems efficiently and effectively.
What is an Algorithm? 2. They help to automate processes and
• “A set of rules to be followed in make them more reliable, faster, and easier
calculations or other problem-solving to perform.
operations” Or “A procedure for solving a 3. Algorithms also enable computers to
mathematical problem in a finite number of perform tasks that would be difficult or
steps that frequently involves recursive impossible for humans to do manually
operations “. . 4. They are used in various fields such as
mathematics, computer science,
• refers to a sequence of finite steps to engineering, finance, and many others to
solve a particular problem. optimize processes, analyze data, make
predictions, and provide solutions to
• can be simple and complex depending on problems
what you want to achieve.
Properties of Algorithm:
Use of the Algorithms: • It should terminate after a finite time.
1. Computer Science: Algorithms form • It should produce at least one output.
the basis of computer programming and are • It should take zero or more input.
used to solve problems ranging from simple • It should be deterministic means giving
sorting and searching to complex tasks the same output for the same input case.
such as artificial intelligence and machine • Every step in the algorithm must be
learning effective i.e. every step should do some
2. Mathematics: Algorithms are used to work.
solve mathematical problems, such as
finding the optimal solution to a system of 3.2 PSEUDOCODE
linear equations or finding the shortest path ● a term used for programming and
in a graph. algorithm-based fields is referred to
3. Operations Research: Algorithms are as pseudocode
used to optimize and make decisions in ● a high-level description of a
fields such as transportation, logistics, and computer program or algorithm that
resource allocation. uses simple, English-like statements
4. Artificial Intelligence: Algorithms are to outline the basic logic of the
the foundation of artificial intelligence and program
machine learning, and are used to develop
intelligent systems that can perform tasks Algorithm
such as image recognition, natural language ● It is an organized, logical sequence
processing, and decision-making. of actions or attitudes towards a
5. Data Science: Algorithms are used to particular problem.
analyze, process, and extract insights from ● . In order to solve a problem, a
large amounts of data in fields such as programmer implements an
marketing, finance, and healthcare algorithm. The algorithm is
expressed using natural verbal but • Creating the program
few technical observations. • Compiling the program
• Running the program
Pseudocode
● it is written in the form of annotations The “Hello World!” program consists of
and informational text that is written three primary components: the HelloWorld
in plain English only. class definition, the main method, and
● Just like programming languages, it source code comments.
doesn't have any syntax, so it cannot
be compiled or interpreted by the 1. Class Definition -This line uses the
compiler keyword class to declare that a new class is
being defined.
What is a Flowchart? is a graphical
representation of an algorithm. 2. HelloWorld -It is an identifier that is the
Programmers often use it as a name of the class.
program-planning tool to solve a problem. It
makes use of symbols which are connected 3. main Method The main
among them to indicate the flow of function(method) is the entry point of your
information and processing. Java application, and it’s mandatory in a
Java program. whose signature in Java is
The process of drawing a flowchart for an
algorithm is known as “flowcharting”. public static void main(String[] args):

Explanation of the above syntax:


• public: So that JVM can execute the
Java Hello World Program method from anywhere.
• static: The main method is to be called
● Java is one of the most popular and without an object. The modifiers are public
widely used programming languages and static can be written in either order.
and platforms • void: The main method doesn’t return
● Java is fast, reliable, and secure. anything.
● Java is used in every nook and • main(): Name configured in the JVM. The
corner from desktop to web main method must be inside the class
applications, scientific definition. The compiler executes the codes
supercomputers to gaming consoles, starting always from the main function.
cell phones to the Internet. In this • String[]: The main method accepts a single
article, we will learn how to write a argument, i.e., an array of elements of type
simple Java Program. String.

Steps to Implement Java Program The next line of code is shown here. Notice
that it occurs inside the main() method.
Implementation of a Java application
program involves the following steps. They System.out.println("Hello, World");
include:
This line outputs the string “Hello, World” Char- a single character
followed by a new line on the screen. Boolean -a boolean character (true or false)
Output is accomplished by the built-in
println( ) method. The eight data types in Table are called
primitive because they are simple and
Comments uncomplicated.
They can either be multiline or single-line Primitive types also serve as the building
comments. blocks for more complex data types, called
reference types, which hold memory
// This is a simple Java program. addresses.
// Call this file "HelloWorld.java".
Declaring Variables
Declaring and Using Constants and A variable declaration is a statement that
Variables reserves a named memory location and
includes the following:
A data item is constant when its value • A data type that identifies the type of data
cannot be changed while a program is that the variable will store
running. For example, when you include the • An identifier that is the variable’s name
following statement in a Java class, the • An optional assignment operator and
number 459 is a constant: assigned value, if you want a variable to
contain an initial value • An ending
System.out.println(459); semicolon

Every time an application containing the Variable names must be legal Java
constant 459 is executed, the value 459 is identifiers.
displayed. Programmers refer to a number a variable name must start with a letter,
such as 459 in several ways: cannot contain spaces, and cannot be a
• It is a literal constant because its value is reserved keyword.
taken literally at each use.
• It is a numeric constant as opposed to a Camel casing- Beginning an identifier with
character or string constant. a lowercase letter and capitalizing
• It is an unnamed constant as opposed to subsequent words within the identifier
a named one because no identifier is
associated with it. An assignment made when you declare a
variable is an initialization
A variable- is a named memory location
that can store a value. Associativity refers to the order in which
values are used with operators.
Byte - bytelength integer
Short - short integer An identifier that can appear on the left side
Int - integer of an assignment operator sometimes is
Long- long integer referred to as an lvalue
Float- single precision floating point
Double- double precision floating point
an item that can appear only on the right
side of an assignment operator is an rvalue.

Uninitialized variable Is when you declare


a variable within a method but do not assign
a value to it

Arithmetic Operators

+ Adds two numbers

- Subtracts two numbers

* Multiplies two numbers

/ Divides two numbers

% Divides two numbers and


returns the remainder

You might also like