1 המרכז להוראת המדעים © האוניברסיטה העברית בירושלים עוברים לג ' אווה.

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.
STRING AN EXAMPLE OF REFERENCE DATA TYPE. 2 Primitive Data Types  The eight Java primitive data types are:  byte  short  int  long  float  double.
Fundamental Programming Structures in Java: Control Flow, Arrays and Vectors.
האוניברסיטה העברית בירושלים
5/17/ Programming Constructs... There are several types of programming constructs in JAVA. - If-else construct or ternary operator - while - do-while.
INSTRUCTOR: SHIH-SHINH HUANG Windows Programming Using Java Chapter4: Control Statements Part I.
CS 106 Introduction to Computer Science I 02 / 18 / 2008 Instructor: Michael Eckmann.
Shlomo Hershkop1 Introduction to java Class 1 Fall 2003 Shlomo Hershkop.
Additional control structures. The if-else statement The if-else statement chooses which of two statements to execute The if-else statement has the form:
Chapter 4 - Control Structures: Part 1 Outline 4.4Control Structures 4.5The if Selection Structure 4.6The if/else Selection Structure 4.7The while Repetition.
(c) 2003 E.S.Boese1 Conditionals Chapter 10 - Student.
מבוא למדעי המחשב תרגול 4 שעת קבלה : יום שני 11:00-12:00 דוא " ל :
Lecture 3 Java Basics Lecture3.ppt.
BASIC JAVA. Hello World n // Hello world program public class MyFirstJavaProgram { public static void main(String args[]) { char c = 'H'; String s =
Switch Statement switch (month) { case 9: case 4: case 6: case 11: days = 30; break; case 2: days = 28; if (year % 4 == 0) days = 29; break; default: days.
© המרכז להוראת המדעים האוניברסיטה העברית בירושלים 1 הפניות.
מבוא למדעי המחשב תרגול 3 שעת קבלה : יום שני 11:00-12:00 דוא " ל :
Last time on Clang משתנה: "פתק" המשמש את המחשב לשמירת מידע. לכל משתנה יש שם וטיפוס כללים לשמות משתנים –חייבים להכיל רק אותיות, מספרים ו '_' –חייבים להתחיל.
11 Introduction to Programming in C - Fall 2010 – Erez Sharvit, Amir Menczel 1 Introduction to Programming in C תרגול
Introduction to Programming G51PRG University of Nottingham Revision 2 Essam Eliwa.
SYDE223 Tutorial 3: Introduction to Java Annie En-Shiun Lee January 19, 2010.
Lecture 10 Instructor: Craig Duckett. Assignment 2 Revision TONIGHT DUE TONIGHT Wednesday, August 5 th Assignment 3 NEXT DUE NEXT Monday, August 10 th.
JAVA PROGRAMMING PART II.
Agenda Review User input Scanner Strong type checking Other flow-control structures switch break & continue Strings Arrays 2.
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
Control Structures if else do while continue break switch case return for.
Basic Java Programming CSCI 392 Week Two. Stuff that is the same as C++ for loops and while loops for (int i=0; i
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
Chapter 3:Decision Structures.  3.1 The if Statement  3.2 The if-else Statement  3.3 The if-else-if Statement  3.4 Nested if Statements  3.5 Logical.
Lecture 3 Decisions (Conditionals). One of the essential features of computer programs is their ability to make decisions. Like a train that changes tracks.
An Introduction to Java – Part 1 Dylan Boltz. What is Java?  An object-oriented programming language  Developed and released by Sun in 1995  Designed.
5. Conditionals & Loops Based on Java Software Development, 5 th Ed. By Lewis &Loftus.
1 Programming Java Java Basics. 2 Java Program Java Application Program Application Program written in general programming language Applet Program running.
Introduction to Programming Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology Spring 2011.
OOP (pre) Basic Programming. Writing to Screen print will display the string to the screen, the following print statement will be appended to the previous.
Mixing integer and floating point numbers in an arithmetic operation.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
Chapter 6. else-if & switch Copyright © 2012 Pearson Education, Inc.
1-Dec-15 Additional control structures. 2 The if-else statement The if-else statement chooses which of two statements to execute The if-else statement.
Decisions. Three Forms of Decision Making in Java if statements (test a boolean expression) switch statements (test an integer expression) conditional.
Important Java terminology The information we manage in a Java program is either represented as primitive data or as objects. ● Primitive data (נתונים.
More loops while and do-while. Recall the for loop in general for (initialization; boolean_expression; update) { }
1 המרכז להוראת המדעים © האוניברסיטה העברית בירושלים פולימורפיזם מתקדם ממשקים בג ' אווה 1.
A Introduction to Computing II Lecture 1: Java Review Fall Session 2000.
Java Scanner Class Keyboard Class. User Interaction So far when we created a program there was no human interaction Our programs just simply showed one.
Chapter 2: Fundamental Programming Structures in Java Adapted from MIT AITI Slides Control Structures.
©2016 Pearson Education, Inc. Upper Saddle River, NJ. All Rights Reserved. CSC 110 – INTRO TO COMPUTING - PROGRAMMING Switch Statement.
Session 2 Operators, Decisions and Loops. Objectives Operators Casting data Decision marking structures Loops break, continue, return.
1 Lecture # 2. * Introducing Programming with an Example * Identifiers, Variables, and Constants * Primitive Data Types * Byte, short, int, long, float,
Introduction to Programming G50PRO University of Nottingham Unit 6 : Control Flow Statements 2 Paul Tennent
C syntax (simplified) BNF. Program ::= [ ] Directives ::= [ ] ::= | |… ::=#include > ::=#define.
Chapter 7 Control Structures. Java has very flexible three looping mechanisms. You can use one of the following three loops:  while Loop  do...while.
Object Oriented Programming Lecture 2: BallWorld.
Topics introduced today (these topics would be covered in more detail in later classes) – Primitive Data types Variables Methods “for” loop “if-else” statement.
האוניברסיטה העברית בירושלים
Information and Computer Sciences University of Hawaii, Manoa
Chapter 4: Control Structures I
Unit-1 Introduction to Java
Control Structures.
Introduction to programming in java
Chapter 5: Control Structures II
An Introduction to Java – Part I
Introduction to Programming in Java
null, true, and false are also reserved.
An Introduction to Java – Part I, language basics
פולימורפיזם מתקדם ממשקים בC# עריכה ועיצוב: קרן הרדי
Java Programming Review 1
Control Structure.
Control Statements:.
Presentation transcript:

1 המרכז להוראת המדעים © האוניברסיטה העברית בירושלים עוברים לג ' אווה

2 המרכז להוראת המדעים © האוניברסיטה העברית בירושלים מה נלמד היום ? 1. תחביר 2. מוסכמות 3. טיפוסי נתונים בסיסיים (primitive data types) 4. המרה בין טיפוסי משתנים (casting) 5. תנאים ולולאות (if, for, while, etc.)

3 המרכז להוראת המדעים © האוניברסיטה העברית בירושלים נראה מוכר ? /** This program prints a question */ public class HowDoYouDrinkYourJava{ public static void main (String[] args){ //prints a question System.out.println(“How do you drink your java?”); }//end of main }//end of class

4 המרכז להוראת המדעים © האוניברסיטה העברית בירושלים לג ' אווה כללים משלה נקודה פסיק ; - מסיים פקודה סוגריים מסולסלים : פותחים } וסוגרים { - מגדירים בלוק איזון סוגריים : public class HowDoYouDrinkYourJava{ … }

5 המרכז להוראת המדעים © האוניברסיטה העברית בירושלים הבנת הנקרא – קונבנציות ( מוסכמות ) הזחה (indentation) חלוקה במקומות לוגיים ונוחים לקריאה : /* This program prints a question */ public class HowDoYouDrinkYourJava{ public static void main (String[] args){ //prints a question System.out.println(“How do you drink your java?”); }//end of main }//end of class

6 המרכז להוראת המדעים © האוניברסיטה העברית בירושלים אפשר היה גם ככה, אבל... /* This program prints a question */ public class HowDoYouDrinkYourJava{public static void main (String[] args){System.out.println(“How do you drink your java?”);}//end of main }//end of class

7 המרכז להוראת המדעים © האוניברסיטה העברית בירושלים מה המשמעות של ה -X הזה ? שמות בעלי משמעות : שמות מחלקות : public class QuotesRelatedToEinstein{ … שמות משתנים : int numberOfQuotes = 5; מילים שמורות - באותיות קטנות (lower case).

8 המרכז להוראת המדעים © האוניברסיטה העברית בירושלים מה התכוונתי שהתוכנית הזו תעשה ? הערות (comments): בשורה // או בקטע /* …*/ /*This class prints quotes related to Albert Einstein*/ public class QuotesRelatedToEinstein{ //number of quotes the program prints int numberOfQuotes = 5; … }

9 המרכז להוראת המדעים © האוניברסיטה העברית בירושלים טיפוס בסיסי מספרים : byte, short, int, long, float, double טיפוס לוגי : boolean תווים : char char theFirstLetterOfTheAlphaBet = ’a’;

10 המרכז להוראת המדעים © האוניברסיטה העברית בירושלים איך הופכים int ל - double המרה בין טיפוסי משתנים – Casting שום דבר לא ילך לאיבוד – ג ' אווה תדאג להמרה אוטומטית double price = 14;

11 המרכז להוראת המדעים © האוניברסיטה העברית בירושלים איך הופכים double ל - int המרה בין טיפוסי משתנים – Casting משהו פה עלול ללכת לאיבוד ! int price = 0.8; בטיחות ! int price = (int)(0.8);

12 המרכז להוראת המדעים © האוניברסיטה העברית בירושלים כללי אצבע 1. נקודה - פסיק בסוף כל פקודה. 2. לשמור על איזון סוגריים. 3. הקפדה על אינדנטציה. קוד מוזח נכון, מחולק באופן לוגי ומסודר. 4. שמות ברורים ובעלי משמעות. 5. שם מחלקה - מתחיל באות גדולה. 6. שם משתנה - מתחיל באות קטנה וכל מילה נוספת בשם מתחילה באות גדולה. 7. מילים שמורות נכתבות באותיות קטנות. 6. המרה : הרחבת הנתון – אוטומטי, צמצום הנתון - יש להיזהר !

13 המרכז להוראת המדעים © האוניברסיטה העברית בירושלים איך יראה הפלט ? /** This program prints the student’s name and grades */ public class StudentsNameAndGrade{ public static void main (String[] args){ //Prints the student’s first name System.out.print(“The student’s name is: Albert Einstein” +”\n”); double gradeInPhysics = 88.75; System.out.println(“Grade in Physics:” + gradeInPhysics ); int newGradeInPhysics = (int)gradeInPhysics; System.out.println(“New Grade in Physics:”+ newGradeInPhysics ); }//end of main }//end of class

14 המרכז להוראת המדעים © האוניברסיטה העברית בירושלים הציונים של אינשטיין The student’s name is: Albert Einstein Grade in Physics: New Grade in Physics: 88

15 המרכז להוראת המדעים © האוניברסיטה העברית בירושלים תנאים ולולאות (if-else, while, for)

16 המרכז להוראת המדעים © האוניברסיטה העברית בירושלים if-else מבנה כללי : if (condition){ statement1; statement2; … } else { statement3; statement4; … }

17 המרכז להוראת המדעים © האוניברסיטה העברית בירושלים = אינו שווה ל - == == משמש להשוואה בין ביטויים = משמש להצבה במשתנים if(i=j) if(i==j) לא יעבור את שלב ההידור

18 המרכז להוראת המדעים © האוניברסיטה העברית בירושלים Are you a Javaholic? int javaCups; // get value from user if (javaCups <= 5) { System.out.println(“You are not a Javaholic"); } else{ if ( javaCups > 5 && javaCups <= 9 ){ System.out.println(“Careful!"); } else{ System.out.println ("You are a Javaholic! See a doctor" ); }

19 המרכז להוראת המדעים © האוניברסיטה העברית בירושלים switch מבנה כללי : switch (expression){ case A : do something; break; case B : do something; break; default: do something; break; }

20 המרכז להוראת המדעים © האוניברסיטה העברית בירושלים Can we write javaholic using switch?

21 המרכז להוראת המדעים © האוניברסיטה העברית בירושלים Are you a javaholic – switch version switch (javaCups){ case 0: case 1: case 2: case 3: case 4: case 5: System.out.println(“You are not a Javaholic ”); break; …

22 המרכז להוראת המדעים © האוניברסיטה העברית בירושלים switch version (cont.) case 6: case 7: case 8: case 9: System.out.println(“Careful!”); break; default: System.out.println(“You are a Javaholic! See a doctor”); }// end of switch

23 המרכז להוראת המדעים © האוניברסיטה העברית בירושלים while מבנה כללי : while (boolean condition){ statement1; statement2; … }

24 המרכז להוראת המדעים © האוניברסיטה העברית בירושלים do-while מבנה כללי : do{ statement1; statement2; … }while(boolean condition);

25 המרכז להוראת המדעים © האוניברסיטה העברית בירושלים for loop מבנה כללי : for ( initialization; condition; update) { statement1; … statement7; } כל עוד התנאי מתקיים - הפעולות בבלוק יתבצעו.

26 המרכז להוראת המדעים © האוניברסיטה העברית בירושלים Let’s count to 10 for( int i = 1; i > 11 ; i++ ) { System.out.println(“count:” + i ); } …

27 המרכז להוראת המדעים © האוניברסיטה העברית בירושלים כללי אצבע 2 1. לסימן + יש שני שימושים : שרשור וחיבור. 2.= להצבה ו == להשוואה. 3.switch אחד עדיף על אלף if-else. 4. לא לשכוח break בפקודת switch. 5. היזהרו מלולאות אינסופיות.