Unit 1 Introductory Fortran Concept

Total Page:16

File Type:pdf, Size:1020Kb

Unit 1 Introductory Fortran Concept UNIT 1 INTRODUCTORY FORTRAN CONCEPT Structure 1.0 Introduction 1.1 Objectives 1.2 Character Set, Constants and Variables 1.2.1 Character Set 1.2.2 Constant and Variables 1.2.3 Numerical Constants and Variables 1.3 Data Types 1.3.1 Integer Dua Types 1.3.2 Real Data Types 1.3.3 Double Precision Data Types 1.3.4 Complex Data Types 1.3.5 Logical Data vpes 1.3.6 Character Data Types 1.4 Subscripted Variables and Simple Fortran Functims 1.4.1 Subscripted Variables 1.4.2 Simple FORTRAN Functions 1.5 FORTRAN Expressions 1.5.1 Design and Evaluation of Arithmetic Expressions 1.5.2 Integcr Mode Expressions 1.5.3 Real Mode Expressions 1.5.4 Complex Mode Expressions 1.5.5 Mixed Mode Expressions 1.5.6 Logical Expressions L .7 Relational Logical Expressions Xaming FORTRAN hograrnmes I 4ssignmcnt Statement I ., FORTRAN Commands 1.8.1 Format froe READ Command 1.8.2 Format Free PRINT Command 1.8.3 Naming Constants 1.8.4 COMMENT Command 1.8.5 Ending Programs 1.8.6 Character Expressions and Assignment 1.9 Summary 1.10 Model Answers I 1.0 INTRODUCTION You know that data may be characterized as numeric or non-numeric. Numeric entities -such as constants, variables, functions ..- used in arithmetic computations. FORTRAN 77 allows a wide variety of numeric data types, such as integer, real. double precision and complex. Similarly, .datatypcs, such as logical (bolean) and character are available for non-numaic computing. Character data type is vcry useful for text-processing applications. Here, we shall present different data types, constants and variable as available in FORTFUN 77.- FORTRAN permits the use of a wide class of quantities, like integer, real, complex. double precision, logical and character. The type of constant., variables and functions which constitute the expression define its type. We shdl explain the definition consuuction and evaluation of expression and design of statements. After reading this unit, you will be able to use FORTRAN Character Set to &fine constants and variables FORTRAN 77 and FORTRAN 90 use FORTRAN character Set to define subscripted variables and other data types use FORTRAN expressions viz.: Arithmetical, Logical and Character name a FORTRAN Program give simple Input/Output Commands. 1.2 CHARACTER SET, CONSTANTS AND VARIABLES we will learn about the notations and characters which are specially meant for and the way in which the constant and variables are defined in FORTRAN 77. 1.2.1 The FORTRAN 77 Character set is : Alphabetic characters A-Z Numeric characters 0-9 Special characters (Decimal) . (Comma) ( (Left Parenthesis) ) (Right parenthesis) + (Plus) $ (Currency.~ymbol,dollar) Blank (A ) 8 (Quote) - (Equals) (Colon) # (Space) The alphabetic and numeric characters are collectively referred to as Alphanumeric characters. All FORTRAN quantities, names, statements and data are constructed using characters from the character set with the help of certain predefined rules of FORTRAN. There are certain I words which identify statements and FORTRAN supplied functions. Such words are ref- to as Key words. Examples of Keywords are: I&AD, JF, DO,DOUBLE PRECISION. and so on. I Keywords must be spelt and written as defined by the language. FORTRAN key words are not reserved words (reserved words are used only for specific purposes). They are recognized as key words by the compiler only when they appear at their proper place and context. Otherwise they may be used as ordinary FORTRAN names. 1.2.2 Constants and Variables Variables and constants are defined similarly in FORWas was in BASIC language. However, rules of defining are specif- to FORTRAN,though similarity also exists. 'Ihese are : A variable must have a name. The variable name refers to specific memory locations where its value is stored. The name of a variable may consist of upto six characters (some implementations may allow more than six characters). The fmt character must be alphabetic Special characters (such as &, #, $, etc.) are not allowed to appear in the variable name. Blank spaces in a name are ignored. A vuiablc cannot be used in computations unless it has been assigned a value i.e. initialized. A conslult is 3 quantity which remains unchanged during computations.in a program. FORTRAN 77 pcnnits the following kinds of constants and variables : Nuillcrical Logical Character Jnboductoy FORTRAN 1.2.3 Numerical constants and variables Concept Constants and variables used in arithmetic expressions are referred to as Numeric. They are of two kinds: (a) Integer (b) Real Single precision Double predision Complex I 1.3 DATA TYPES t ' Data in FORTRAN could be classifitxi into six type viz. Integer. Real, Double Precision, Complex, Lagical and Character. This &tion shows how constant and variables of each data type is represented in FORTRAN. 1.3.1 Integer Data Types Integer data type signifies a class of entities that are integral in nature. They can be constants, variables or expressions. Integer Constant: An integer constant is a number without a decimal. It may be positive, negative or zero. Positive sign may or may not appear before the number but the negative sign always precedes the number. The magnitude of the number must not exceed the allowed I maximum which varies from computer to computer, In systems with word size = 32 bits. 1 maximum value allowed for a constant is (z3'- 2) = 2147483641. No commas are allowed to appear in constants. Examples of integer constants are: Integer Variables :An integer variable is an entity which can assume only integer constant as its value at any point in the calculations. For a variable to be integer, the first character of the name should begin with either of the letters : I, J, K. L, M. N, (This is a FORW convention and can be overridden.) Examples of integer variables are: MATRIX N123A INTGR MAM Another way to dkclare variables extlicitly as integer is via the declaration INTEGER. Its syntax is INTEGER list Where list is name of variables that has been specified as INTEGER type. An example is INTEGER RP, DEPTH, PT Now variables R, DEFTH and PT,though do not begin with any of the letters I - N, are treated as integer. 1.3.2 Real Data Types Real data types refers to a class of entities that are not integral in nature. They may be constants, variables or expressions. ' Real Constants :A real constant is a number with a decimal point which may appear anywhere in the number. The number may be positive, negative or zero. Unsigned constant is taken as positive. Cornmasare not allowed to appear in the constant. Example are: The presence of a decimal informs the system that the number is real. Real constants are also written with an exponent Q. For instance 12.34 = 0.1234~lo2 = 1.234 x 10' = 1234.x The decimal part is called the mantissa and power part is call@+the exponent. In FORTWIN, these numbers are written as: 12.34 = 0.1234B2~1.234E+1=1234&2 and so on. Here E+" stands for 10'" .When the decimal is on the extreme left (as in 0.1234~lo2) the number is said to be in the 'normalized' form. All real numbers are stored in the computer storage in this form. The need for writing numbers in exponent form arises because FORTRAN dots not allow subscripts or superscripts to appear with numbers. Only exponent is permitted. The value of exponent (n) must always be integer or zero. The magnitude of the exponent varies from computer to computer and depends on the word size. Real Variables :A real variable can assume only a real constant as its value. The name of a real variable begins with any of the letters A - H and 0 - Z. This is by convention and can be over ridden. Examples of real variables are : AIT BIM ALPHA T32QR PRITI The declaration REAL can be used to declare variables of type real as: REAL LIST Where list is the name of variables that are to be declared as type real. An example is : REAL JK. BANGLE. UP 1.3.3 Double Precision Data Types FORTRAN Defines both constants and variables having precision twice that of the nonnal real data types. These are explained below : Dduble Precision Constants :These are real constants which are coded in the exponential form with a letter D, instead of letter E. As for example: 12.357894213D+07, -0.321456987D-1-02, +.35724 D - 20 and so on. The number of digits in a double precision constant is always greater than that for a real single precision constant. The maximum magnitude of a double precision constant also varies from computer to computer. We shall assume that the double precision constant consists of 14 places of decimals. Some examples of double precision mode constants are: Double hecision Variables : These are real variables which occupy double the memory than the single precision variables. For a variable to be double precision, information has to bt: supplied. This is done by using the specification DOUBLE PRECISION which is followed by the list of variables which we want to be of double precision mode. This is done as follows : DOUBLE PRECIS1,ON list where DOUBLE PRECISION are keywords, must be written as and list represents variable names, each separated from the other by a comma. Variables which follow DOUBLE PRECISION words are treated as of double precision mode, irrespective of whether they begin with letters I -N or A-H, 0-Z. Consider DOUBLE PRECISION A, I, J, RUM Variables A, I, J, RUM have been declared to be of double precision mde. As many variables as necessary may be included in a single specification.
Recommended publications
  • Chapter 7 Expressions and Assignment Statements
    Chapter 7 Expressions and Assignment Statements Chapter 7 Topics Introduction Arithmetic Expressions Overloaded Operators Type Conversions Relational and Boolean Expressions Short-Circuit Evaluation Assignment Statements Mixed-Mode Assignment Chapter 7 Expressions and Assignment Statements Introduction Expressions are the fundamental means of specifying computations in a programming language. To understand expression evaluation, need to be familiar with the orders of operator and operand evaluation. Essence of imperative languages is dominant role of assignment statements. Arithmetic Expressions Their evaluation was one of the motivations for the development of the first programming languages. Most of the characteristics of arithmetic expressions in programming languages were inherited from conventions that had evolved in math. Arithmetic expressions consist of operators, operands, parentheses, and function calls. The operators can be unary, or binary. C-based languages include a ternary operator, which has three operands (conditional expression). The purpose of an arithmetic expression is to specify an arithmetic computation. An implementation of such a computation must cause two actions: o Fetching the operands from memory o Executing the arithmetic operations on those operands. Design issues for arithmetic expressions: 1. What are the operator precedence rules? 2. What are the operator associativity rules? 3. What is the order of operand evaluation? 4. Are there restrictions on operand evaluation side effects? 5. Does the language allow user-defined operator overloading? 6. What mode mixing is allowed in expressions? Operator Evaluation Order 1. Precedence The operator precedence rules for expression evaluation define the order in which “adjacent” operators of different precedence levels are evaluated (“adjacent” means they are separated by at most one operand).
    [Show full text]
  • A Concurrent PASCAL Compiler for Minicomputers
    512 Appendix A DIFFERENCES BETWEEN UCSD'S PASCAL AND STANDARD PASCAL The PASCAL language used in this book contains most of the features described by K. Jensen and N. Wirth in PASCAL User Manual and Report, Springer Verlag, 1975. We refer to the PASCAL defined by Jensen and Wirth as "Standard" PASCAL, because of its widespread acceptance even though no international standard for the language has yet been established. The PASCAL used in this book has been implemented at University of California San Diego (UCSD) in a complete software system for use on a variety of small stand-alone microcomputers. This will be referred to as "UCSD PASCAL", which differs from the standard by a small number of omissions, a very small number of alterations, and several extensions. This appendix provides a very brief summary Of these differences. Only the PASCAL constructs used within this book will be mentioned herein. Documents are available from the author's group at UCSD describing UCSD PASCAL in detail. 1. CASE Statements Jensen & Wirth state that if there is no label equal to the value of the case statement selector, then the result of the case statement is undefined. UCSD PASCAL treats this situation by leaving the case statement normally with no action being taken. 2. Comments In UCSD PASCAL, a comment appears between the delimiting symbols "(*" and "*)". If the opening delimiter is followed immediately by a dollar sign, as in "(*$", then the remainder of the comment is treated as a directive to the compiler. The only compiler directive mentioned in this book is (*$G+*), which tells the compiler to allow the use of GOTO statements.
    [Show full text]
  • Operators and Expressions
    UNIT – 3 OPERATORS AND EXPRESSIONS Lesson Structure 3.0 Objectives 3.1 Introduction 3.2 Arithmetic Operators 3.3 Relational Operators 3.4 Logical Operators 3.5 Assignment Operators 3.6 Increment and Decrement Operators 3.7 Conditional Operator 3.8 Bitwise Operators 3.9 Special Operators 3.10 Arithmetic Expressions 3.11 Evaluation of Expressions 3.12 Precedence of Arithmetic Operators 3.13 Type Conversions in Expressions 3.14 Operator Precedence and Associability 3.15 Mathematical Functions 3.16 Summary 3.17 Questions 3.18 Suggested Readings 3.0 Objectives After going through this unit you will be able to: Define and use different types of operators in Java programming Understand how to evaluate expressions? Understand the operator precedence and type conversion And write mathematical functions. 3.1 Introduction Java supports a rich set of operators. We have already used several of them, such as =, +, –, and *. An operator is a symbol that tells the computer to perform certain mathematical or logical manipulations. Operators are used in programs to manipulate data and variables. They usually form a part of mathematical or logical expressions. Java operators can be classified into a number of related categories as below: 1. Arithmetic operators 2. Relational operators 1 3. Logical operators 4. Assignment operators 5. Increment and decrement operators 6. Conditional operators 7. Bitwise operators 8. Special operators 3.2 Arithmetic Operators Arithmetic operators are used to construct mathematical expressions as in algebra. Java provides all the basic arithmetic operators. They are listed in Tabled 3.1. The operators +, –, *, and / all works the same way as they do in other languages.
    [Show full text]
  • Types of Operators Description Arithmetic Operators These Are
    UNIT II OPERATORS Types of Operators Description These are used to perform mathematical calculations like addition, subtraction, Arithmetic_operators multiplication, division and modulus These are used to assign the values for Assignment_operators the variables in C programs. These operators are used to compare the Relational operators value of two variables. These operators are used to perform logical operations on the given two Logical operators variables. These operators are used to perform bit Bit wise operators operations on given two variables. Conditional operators return one value Conditional (ternary) if condition is true and returns another operators value is condition is false. These operators are used to either Increment/decrement increase or decrease the value of the operators variable by one. Special operators &, *, sizeof( ) and ternary operator ARITHMETIC OPERATORS IN C: C Arithmetic operators are used to perform mathematical calculations like addition, subtraction, multiplication, division and modulus in C programs. Arithmetic Operators/Operation Example + (Addition) A+B – (Subtraction) A-B * (multiplication) A*B / (Division) A/B % (Modulus) A%B EXAMPLE PROGRAM FOR C ARITHMETIC OPERATORS: // Working of arithmetic operators #include <stdio.h> int main() { int a = 9,b = 4, c; c = a+b; printf("a+b = %d \n",c); c = a-b; printf("a-b = %d \n",c); c = a*b; printf("a*b = %d \n",c); c = a/b; printf("a/b = %d \n",c); c = a%b; printf("Remainder when a divided by b = %d \n",c); return 0; } Output a+b = 13 a-b = 5 a*b = 36 a/b = 2 Remainder when a divided by b=1 Assignment Operators The Assignment Operator evaluates an expression on the right of the expression and substitutes it to the value or variable on the left of the expression.
    [Show full text]
  • Brief Overview of Python Programming Language
    Brief Overview Chapter of Python 3 In this chapter » Introduction to Python » Python Keywords “Don't you hate code that's not properly » Identifiers indented? Making it [indenting] part of » Variables the syntax guarantees that all code is » Data Types properly indented.” » Operators » Expressions — G. van Rossum » Input and Output » Debugging » Functions » if..else Statements » 3.1 INTRODUCTION TO PYTHON for Loop » Nested Loops An ordered set of instructions or commands to be executed by a computer is called a program. The language used to specify those set of instructions to the computer is called a programming language for example Python, C, C++, Java, etc. This chapter gives a brief overview of Python programming language. Python is a very popular and easy to learn programming language, created by Guido van Rossum in 1991. It is used in a variety of fields, including software development, web development, scientific computing, big data 2021-22 Chap 3.indd 31 19-Jul-19 3:16:31 PM 32 INFORMATICS PRACTICES – CLASS XI and Artificial Intelligence. The programs given in this book are written using Python 3.7.0. However, one can install any version of Python 3 to follow the programs given. Download Python 3.1.1 Working with Python The latest version of To write and run (execute) a Python program, we need Python is available on the to have a Python interpreter installed on our computer official website: or we can use any online Python interpreter. The https://www.python. interpreter is also called Python shell. A sample screen org/ of Python interpreter is shown in Figure 3.1.
    [Show full text]
  • Syntax of Mini-Pascal (Spring 2016)
    Syntax of Mini-Pascal (Spring 2016) Mini-Pascal is a simplified (and slightly modified) subset of Pascal. Generally, the meaning of the features of Mini-Pascal programs are similar to their semantics in other common imperative languages, such as C. 1. Mini-Pascal allows nested functions and procedures, i.e. subroutines which are defined within another. A nested function is invisible outside of its immediately enclosing function (procedure / block), but can access preceding visible local objects (data, functions, etc.) of its enclosing functions (procedures / blocks). Within the same scope (procedure / function / block), identifiers must be unique but it is OK to redefine a name in an inner scope. 2. A var parameter is passed by reference , i.e. its address is passed, and inside the subroutine the parameter name acts as a synonym for the variable given as an argument. A called procedure or function can freely read and write a variable that the caller passed in the argument list. 3. Mini-Pascal includes a C-style assert statement (if an assertion fails the system prints out a diagnostic message and halts execution). 4. The Mini-Pascal operation a.size only applies to values of type array of T (where T is a type). There are only one-dimensional arrays. Array types are compatible only if they have the same element type. Arrays' indices begin with zero. The compatibility of array indices and array sizes is usually checked at run time. 5. By default, variables in Pascal are not initialized (with zero or otherwise); so they may initially contain rubbish values.
    [Show full text]
  • What Is Python ?
    Class-XI Computer Science Python Fundamentals Notes What is python ? Python is object oriented high level computer language developed by Guido Van Rossum in 1990s . It was named after a British TV show namely ‘Monty Python’s Flying circus’. Python is a programming language, as are C, Fortran, BASIC, PHP, etc. Some specific features of Python are as follows: • an interpreted (as opposed to compiled) language. Contrary to e.g. C or Fortran, one does not compile Python code before executing it. In addition, Python can be used interactively: many Python interpreters are available, from which commands and scripts can be executed. • a free software released under an open-source license: Python can be used and distributed free of charge, even for building commercial software. • multi-platform: Python is available for all major operating systems, Windows, Linux/Unix, MacOS X, most likely your mobile phone OS, etc. • a very readable language with clear non-verbose syntax • a language for which a large variety of high-quality packages are available for various applications, from web frameworks to scientific computing. • a language very easy to interface with other languages, in particular C and C++. • Some other features of the language are illustrated just below. For example, Python is an object-oriented language, with dynamic typing (the same variable can contain objects of different types during the course of a program). Python character set: • Letters : A-Z , a-z • Digits : 0-9 • Special symbols : space,+,-,*,/,** etc. • Whitespace : blank space, tabs(->),carriage return, newline, formfeed • Other characters :python can process all ASCII and unicode characters as part of data PYTHON TERMINOLOGY : Tokens: A smallest individual unit in a program is known as tokens.
    [Show full text]
  • Software II: Principles of Programming Languages Why Expressions?
    Software II: Principles of Programming Languages Lecture 7 – Expressions and Assignment Statements Why Expressions? • Expressions are the fundamental means of specifying computations in a programming language • To understand expression evaluation, need to be familiar with the orders of operator and operand evaluation • Essence of imperative languages is dominant role of assignment statements 1 Arithmetic Expressions • Arithmetic evaluation was one of the motivations for the development of the first programming languages • Arithmetic expressions consist of operators, operands, parentheses, and function calls Arithmetic Expressions: Design Issues • Design issues for arithmetic expressions – Operator precedence rules? – Operator associativity rules? – Order of operand evaluation? – Operand evaluation side effects? – Operator overloading? – Type mixing in expressions? 2 Arithmetic Expressions: Operators • A unary operator has one operand • A binary operator has two operands • A ternary operator has three operands Arithmetic Expressions: Operator Precedence Rules • The operator precedence rules for expression evaluation define the order in which “adjacent” operators of different precedence levels are evaluated • Typical precedence levels – parentheses – unary operators – ** (if the language supports it) – *, / – +, - 3 Arithmetic Expressions: Operator Associativity Rule • The operator associativity rules for expression evaluation define the order in which adjacent operators with the same precedence level are evaluated • Typical associativity
    [Show full text]
  • Introduction to C++
    Introduction to C++ CLASS- 4 Expressions, OOPS Concepts Anshuman Dixit Expressions C++ contains expressions, which can consist of one or more operands, zero or more operators to compute a value. Every expression produces some value which is assigned to the variable with the help of an assignment operator. Ex- (a+b) - c 4a2 - 5b +c (a+b) * (x+y) Anshuman Dixit Expressions An expression can be of following types: • Constant expressions • Integral expressions • Float expressions • Pointer expressions • Relational expressions • Logical expressions • Bitwise expressions • Special assignment expressions Anshuman Dixit Constant expressions A constant expression is an expression that consists of only constant values. It is an expression whose value is determined at the compile-time but evaluated at the run-time. It can be composed of integer, character, floating-point, and enumeration constants. Ex- Expression containing constant Constant value x = (2/3) * 4 (2/3) * 4 extern int y = 67 67 int z = 43 43 Anshuman Dixit Integral and Float Expressions An integer expression is an expression that produces the integer value as output after performing all the explicit and implicit conversions. Ex- (x * y) -5 (where x and y are integers) Float Expressions: A float expression is an expression that produces floating-point value as output after performing all the explicit and implicit conversions. Anshuman Dixit Pointer and relationship Expressions A pointer expression is an expression that produces address value as an output. Ex- &x, ptr, ptr++, ptr-- Relational Expressions- A relational expression is an expression that produces a value of type bool, which can be either true or false.
    [Show full text]
  • Evaluation of Relational Operators and Query Optimization Kathleen Durant Phd CS 3200
    Evaluation of relational operators and query optimization Kathleen Durant PhD CS 3200 1 Introduction • In network and hierarchical DBMSs, low-level procedural query language is generally embedded in high-level programming language. • Programmer’s responsibility to select most appropriate execution strategy. • With declarative languages such as SQL, user specifies what data is required rather than how it is to be retrieved. • Relieves user of knowing what constitutes good execution strategy. Pearson Education © 2014 2 Introduction • Also gives DBMS more control over system performance. • Two main techniques for query optimization: • heuristic rules that order operations in a query; • comparing different strategies based on relative costs, and selecting one that minimizes resource usage. • Disk access tends to be dominant cost in query processing for centralized DBMS. Pearson Education © 2014 3 Query Processing Activities involved in retrieving data from the database. • Aims of QP: • transform query written in high-level language (e.g. SQL), into correct and efficient execution strategy expressed in low-level language (implementing RA); • execute strategy to retrieve required data. Pearson Education © 2014 4 Why is it important? • Now that we know about the benefits of indexes, how does the DBMS know when to use them? • An SQL query can be implemented in many ways, but which one is best? • Perform selection before or after join etc. • Many ways of physically implementing a join (or other relational operator), how to choose the right one? • The DBMS does this automatically, but we need to understand it to know what performance to expect 5 Query Evaluation • SQL query is implemented by a query plan • Tree of relational operators • Each internal node operates on its children • Can choose different operator implementations • Two main issues in query optimization: • For a given query, what plans are considered? • Algorithm to search plan space for cheapest (estimated) plan.
    [Show full text]
  • Fortran 90 Standard Statement Keywords
    APPENDIX A FORTRAN 90 STANDARD STATEMENT KEYWORDS For a given dialect of Fortran, there is normally some sort of refer­ ence document that formally specifies the valid syntax for each variety of statement. For most categories of statements, the syntax rules dic­ tate the appearance of fixed sequences of letters, traditionally known as keywords, at specified places in the statement. In particular, most state­ ments are required to begin with a keyword made up of a sequence of letters that constitute an ordinary word in the English language. Exam­ ples of such words are DO, END, and INTEGER. Some statements begin with a pair of keywords (for example, GO TO, DOUBLE PRECISION, ELSE IF). Furthermore, the term "keyword" encompasses certain sequences of letters appearing to the left of an equal sign (=) in a parenthesized list in certain (mostly I/O) statements. Consider, for example, the following statement: READ (UNIT = 15, FMT = "(A)", lOSTAT = ios) buf Here, the initial sequence of letters READ is, of course, a keyword, but also UNIT, FMT, and 10STAT are considered to be keywords, even though FMT and 10STAT are not English words. And, there are additional situ­ ations in Fortran where a particular sequence of letters appearing in a particular context is characterized as being a keyword. In Fortran 90, the sort of sequence of letters that has traditionally been called a "keyword" has been redesignated as a statement key­ word. The modifier "statement" has been prepended to distinguish the traditional sort of keyword from the Fortran 90 "argument keyword" as described in Section 13.9.
    [Show full text]
  • Boolean Data and Relational Operators
    BOOLEAN DATA AND RELATIONAL OPERATORS George Boole (1815-1864) was a British mathematician who invented the Boolean algebra, which is the basis of computer arithmetic for all modern computers. Because of this, we now consider Boole one of the founders of computer science even though electronic computers did not exist when he was alive. Boolean algebra involves “arithmetic” similar to that of numbers that you learned in school, except that a Boolean operation is either true or false. Java represents these two truth values using the keywords true and false, respectively. A variable of the built-in data type boolean can hold either the value true or false stored as an 8-bit integer. Example boolean done = false; boolean success = true; A relational operator takes two non-Boolean primitive operands, compares them and yields true or false. Relational Operators Symbol Operation Precedence Association < Less than <= Less than or equal to 6 Cannot be cascaded > Greater than >= Greater than or equal to See the topic Data Types and Operators → Introduction to Java Data Types and Operators Boolean Data and Relational Operators Page 1 Examples Assume x is initialized to 12.5. x < 12.0 is false x > 12.0 is true x <= 12.5 is true x <= 12.0 is false x >= 12.5 is true x >= 12.0 is true A relational operator is evaluated after all arithmetic operators and before any assignment operator. Example The follow statement determines if a student got 75% or better on a test boolean passedTest = (total-numberWrong) / total >= 0.75; Relational operators cannot be cascaded.
    [Show full text]