“Introduction to Programming With Java”

Slides:



Advertisements
Similar presentations
AP Computer Science Anthony Keen. Computer 101 What happens when you turn a computer on? –BIOS tries to start a system loader –A system loader tries to.
Advertisements

Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 3: Flow Control I: For Loops.
Variables, Expressions and Arithmetic Operators in JAVA
Arrays. What is an array An array is used to store a collection of data It is a collection of variables of the same type.
Chapter 7 User-Defined Methods. Chapter Objectives  Understand how methods are used in Java programming  Learn about standard (predefined) methods and.
10-Jun-15 Introduction to Primitives. 2 Overview Today we will discuss: The eight primitive types, especially int and double Declaring the types of variables.
Variables Pepper. Variable A variable –box –holds a certain type of value –value inside the box can change Example –A = 2B+1 –Slope = change in y / change.
Introduction to Primitives. Overview Today we will discuss: –The eight primitive types, especially int and double –Declaring the types of variables –Operations.
Some basic I/O.
Java An introduction. Example 1 public class Example1 { public static void main (String [] args) { System.out.println (“This is the first example”); int.
Fundamental Programming Structures in Java: Comments, Data Types, Variables, Assignments, Operators.
Copyright 2008 by Pearson Education 1 Building Java Programs Chapter 2 Lecture 2-1: Expressions and Variables reading:
COMP 14: Primitive Data and Objects May 24, 2000 Nick Vallidis.
1 The First Step Learning objectives write Java programs that display text on the screen. distinguish between the eight built-in scalar types of Java;
03/16/ What is an Array?... An array is an object that stores list of items. Each slot of an array holds an individual element. Characteristics.
“Introduction to Programming With Java”
Introduction to Information and Computer Science Computer Programming Lecture c This material (Comp4_Unit5c), was developed by Oregon Health and Science.
DAT602 Database Application Development Lecture 5 JAVA Review.
Welcome to the Lecture Series on “Introduction to Programming With Java”
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
“Introduction to Programming With Java” Lecture - 6 U MESH P ATIL
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
The basics of the array data structure. Storing information Computer programs (and humans) cannot operate without information. Example: The array data.
1 CSC 110AA Introduction to Computer Science for Majors - Spring 2003 Class 5 Chapter 2 Type Casting, Characters, and Arithmetic Operators.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 2: Variables & Data Types.
College Board A.P. Computer Science A Topics Program Design - Read and understand a problem's description, purpose, and goals. Procedural Constructs.
An Introduction to Java – Part 1 Dylan Boltz. What is Java?  An object-oriented programming language  Developed and released by Sun in 1995  Designed.
Copyright 2008 by Pearson Education 1 Building Java Programs Chapter 2 Lecture 2-1: Expressions and Variables reading:
03 August 2004 NLP-AI Java Lecture No. 4 Operators & Decision Constructs Satish Dethe.
College Board A.P. Computer Science A Topics Program Design - Read and understand a problem's description, purpose, and goals. Procedural Constructs -
1 CS 007: Introduction to Computer Programming Ihsan Ayyub Qazi.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
Component 4: Introduction to Information and Computer Science Unit 5: Overview of Programming Languages, Including Basic Programming Concepts Lecture 3.
Review TEST 2 Chapters 4,5,7. QUESTION For which type of operands does the == operator always work correctly: (a) int, (b) double, or (c) String?
CSC 1051 M.A. Papalaskari, Villanova University Algorithms Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
Copyright 2010 by Pearson Education 1 Building Java Programs Chapter 2 Lecture 2-1: Expressions and Variables reading:
1 More data types Character and String –Non-numeric variables –Examples: char orange; String something; –orange and something are variable names –Note.
Introduction to Computational Modeling of Social Systems Prof. Lars-Erik Cederman Center for Comparative and International Studies (CIS) Seilergraben 49,
1 Chapter 2: Java Fundamentals cont’d Spring Lory Al Moakar.
CSM-Java Programming-I Spring,2005 Fundamental Data Types Lesson - 2.
1 Building Java Programs Chapter 2 Lecture 2-1: Expressions and Variables reading:
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Agenda Comments Identifiers Keywords Syntax and Symentics Indentation Variables Datatype Operator.
Computer Programming with Java Chapter 2 Primitive Types, Assignment, and Expressions.
© 2007 Pearson Addison-Wesley. All rights reserved2-1 Character Strings A string of characters can be represented as a string literal by putting double.
CS 106 Introduction to Computer Science I 09 / 10 / 2007 Instructor: Michael Eckmann.
A Introduction to Computing II Lecture 1: Java Review Fall Session 2000.
Lecture 10. Review (Char) Character is one of primitive data types of variable (such as integer and double) –Character variable contains one character.
Computer Science A 1. Course plan Introduction to programming Basic concepts of typical programming languages. Tools: compiler, editor, integrated editor,
1 Lecture # 2. * Introducing Programming with an Example * Identifiers, Variables, and Constants * Primitive Data Types * Byte, short, int, long, float,
Introduction to programming in java Lecture 22 Arrays – Part 2 and Assignment No. 3.
Introduction to programming in java Lecture 21 Arrays – Part 1.
Primitive data types Lecture 03. Review of Last Lecture Write a program that prints the multiplication table of 5. class MultiplicationTable { public.
CompSci 230 S Programming Techniques
Some Assignments  Write a program which prints the following information about at least 5 persons: NAME MAIL-ID EMPLOYEE-CODE PHONE Eg. Umesh
CSC111 Quick Revision.
Chapter 7 User-Defined Methods.
Lecture 2: Data Types, Variables, Operators, and Expressions
Introduction to programming in java
Chapter 2.
مساق: خوارزميات ومبادئ البرمجة الفصل الدراسي الثاني 2016/2015
An Introduction to Java – Part I, language basics
Building Java Programs
Java Tutotrial for [NLP-AI] 2
Introduction to Primitives
Fundamental OOP Programming Structures in Java: Comments, Data Types, Variables, Assignments, Operators.
In this class, we will cover:
Building Java Programs
Building Java Programs
Building Java Programs
Presentation transcript:

“Introduction to Programming With Java” Lecture – 5 UMESH PATIL (umesh@cse.iitb.ac.in) nlp-ai@cse.iitb

Contents for Today’s Lecture Quick recap of the syllabus covered so far. Solutions to previous assignments. Some programing practice. Introduction to Arrays. nlp-ai@cse.iitb

Recap Structure of Java Program: class class-name { public static void main(String args[]) { statements; } } Printing messages to the screen: System.out.println(“Hello World”); System.out.print(“Hello World”); nlp-ai@cse.iitb

Recap… Data Types: Numbers – int (whole no.s), double (no.s with decimal point) eg. int i = 23; double d = 33.23 Character – char eg. char c = ‘a’; String – String eg. String s = “Hi”; Boolean – boolean eg. boolean b = false; Variable declaration: data-type variable-name eg. int i = 23; nlp-ai@cse.iitb

Recap… Expression: An expression is a combination of literals (like 100), operators (like +), variables and parentheses used to calculate a value. eg. 2 + 6 / (2 – 9) Operators: Arithmetic – eg. ‘-’, ‘+’, ‘/’, ‘++’ etc. Relational – eg. ‘<’, ‘>=’, ‘!=’ etc. Conditional – eg. ‘&&’ (AND), ‘||’ (OR) Control constructs like‘if’ and ‘if else’: nlp-ai@cse.iitb

Assignment Write a program that averages the synsets created for three months April, May and June. Declare and initialize variable to the synset entered for each month. Compute the average and write out the results, something like this: Synsets Entered for April: 12 Synsets Entered for May : 14 Synsets Entered for June: 8 Average Synset Entered: 11.333333 nlp-ai@cse.iitb

Solution class synset { public static void main(String args[]) { int april = 12; int may = 14; int june = 8; double avg; avg = ( april + may + june ) / 3.0; System.out.println("Synsets Entered for April " + april); System.out.println("Synsets Entered for May " + may); System.out.println("Synsets Entered for June " + june); System.out.println("Average Synset Entered " + avg); } } nlp-ai@cse.iitb

Assignment int a_number=1; (range is 1 to 5 both including) Print the value in a_number in word with and without using equality (= =) operator. For example it should print “Four” if a_number contains 4. nlp-ai@cse.iitb

Solution class assign1 { public static void main(String args[]) { int a_number; a_number = 5; if(a_number == 1) System.out.println("One"); if(a_number == 2) System.out.println("Two"); if(a_number == 3) System.out.println("Three"); if(a_number == 4) System.out.println("Four"); if(a_number == 5) System.out.println("Five"); } } nlp-ai@cse.iitb

Arrays Definition: An array is a group/collection of variables of the same type that are referred to by a common name and an index Examples: Collection of numbers Collection of names Collection of suffixes nlp-ai@cse.iitb

Examples 10 23 863 8 229 Sholay Shaan Shakti ment tion ness ves Array of numbers: Array of names: Array of suffixes: 10 23 863 8 229 Sholay Shaan Shakti ment tion ness ves nlp-ai@cse.iitb

Analogy Array is like a pen box with fixed no. of slots of same size. nlp-ai@cse.iitb

End Thank you… nlp-ai@cse.iitb