1 / 49

השתלמות מדעי המחשב בשפות חדשות 7/02/07

השתלמות מדעי המחשב בשפות חדשות 7/02/07. טיפוסים, המרה, פעולות קלט/פלט, אופרטורים, התאמת סביבות העבודה לצרכי ההוראה. טיפוסים פרימיטיביים. ~ 10 19. כמה מילישניות יש בחודש?. 86400000. System.out.println(1000*60*60*24); System.out.println(1000*60*60*24*7);

allayna
Download Presentation

השתלמות מדעי המחשב בשפות חדשות 7/02/07

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. השתלמות מדעי המחשב בשפות חדשות7/02/07 טיפוסים, המרה, פעולות קלט/פלט, אופרטורים, התאמת סביבות העבודה לצרכי ההוראה ד''ר יבגני קנל

  2. טיפוסים פרימיטיביים ~1019 ד''ר יבגני קנל

  3. כמה מילישניות יש בחודש? 86400000 System.out.println(1000*60*60*24); System.out.println(1000*60*60*24*7); System.out.println(1000*60*60*24*30); 604800000 -1702967296 ד''ר יבגני קנל

  4. הצהרה על משתנים • int a; • int a,b; • int a=10, b; • int a=10, b=2*a; • int a=IO.readInt(“ enter the number”); אפשר להצהיר על משתנה בכל רגע ד''ר יבגני קנל

  5. אין ברירת מחדל! public static void main(String args[]){ int a; System.out.println("Hello, Java's world"); System.out.println(a); } Error: variable a might not have been initialized ד''ר יבגני קנל

  6. אפשר להצהיר על משתנה רק פעם אחת בתוך בלוק public static void main(String args[]){ System.out.println("Hello, Java's world"); int a=10; System.out.println(a); int a=100; System.out.println(a); } public static void main(String args[]){ int a=10; if (a>10){ int b=5; System.out.println(a+b); } else { int b=100; System.out.println(b); } } Error: a is already defined in main(java.lang.String[]) ד''ר יבגני קנל

  7. לכל משתנה חייב להיות ערך! public static void main(String args[]){ System.out.println("Hello, Java's world"); int a=10; int b; if(a>0)System.out.println(a); else System.out.println(b); } Error: variable b might not have been initialized ד''ר יבגני קנל

  8. למה שווה X ? 0; -2147483648; int x=… int y=-x; If(x==y)System.out.println(“Yes”); else System.out.println(“No”); ערך מינימאלי ל- int // Error: integer number too large: 2147483648 int x= 2147483648; int y=-x; If(x==y)System.out.println(“Yes”); else System.out.println(“No”); ד''ר יבגני קנל

  9. אופרטורים מתמטיים שפועלים על ערכים שלמים ד''ר יבגני קנל

  10. ד''ר יבגני קנל

  11. אופרטורים אונריים ד''ר יבגני קנל

  12. הבדל בין num++ ו- ++num int num; num=10; System.out.println(num); System.out.println(num++); System.out.println(num); num =10; System.out.println(num); System.out.println(++num); System.out.println(num); 10 10 11 10 11 11 ד''ר יבגני קנל

  13. אופרטורים מקוצרים ד''ר יבגני קנל

  14. פעולות עם תווים char ch='a', ch1=98; System.out.println(ch); System.out.println(ch+1); System.out.println(ch++); System.out.println("ch="+ch); System.out.println('c'+'='+ch); System.out.println(ch1); System.out.println(ch1+1); System.out.println(ch1++); System.out.println("ch1="+ch1); System.out.println('c'+'='+ch1); a 98 a ch=b 258 b 99 b ch1=c 259 ד''ר יבגני קנל

  15. פעולות עם תווים } char ch='a'; ch=ch+1; System.out.println(ch); } char ch='a'; ch=(char)(ch+1); System.out.println(ch); Error: possible loss of precision found : int required: char ד''ר יבגני קנל

  16. טיפוסים פרימיטיביים ד''ר יבגני קנל

  17. חילוק ל-0. מה יהיה? double xD=1.0; double zD=0.0; int x=1; int z=0; System.out.println(xD/zD); System.out.println(-xD/z); System.out.println(x/zD); System.out.println(z/zD); System.out.println(x/z); Infinity -Infinity Infinity NaN ArithmeticException: / by zero at Test1.main(Test1.java:11) atun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) ד''ר יבגני קנל

  18. אופרטורים / ו-% • ליוסי יש 13 ש''ח. כמה סוכריות ב-3 ש''ח הוא יכול לקנות וכמה עודף יישאר לו? int candy= 13 / 3; int change= 13 % 3; 4 1 • ליוסי יש 3.5 ש''ח. כמה סוכריות ב-1.5 ש''ח הוא יכול לקנות וכמה עודף יישאר לו? int candy= (int)(3.5 / 1.5); double change= 3.5 % 1.5; 2 0.5 ד''ר יבגני קנל

  19. אופרטורים / ו-% • למספרים שלמים: num1%num2=num1-(num1/num2)*num2 התוצאה היא שלמה • למספרים ממשיים: num1%num2=num1-((int)(num1/num2)*num2) התוצאה היא ממשית ד''ר יבגני קנל

  20. המרה ((casting ערך של משתנה ‘a’ ערך של משתנה 97.0 ערך של משתנה 97 ד''ר יבגני קנל

  21. טעות נפוצה אצל תלמידים: השמת החלוקה השלמה במשתנה ממשי – התוצאה החלק השבור הוא 0. חישוב ממוצע ציונים: 100, 80, 95 double avg; avg=(100+80+95)/3; System.out.println(avg); avg=(double)(100+80+95)/3; System.out.println(avg); 91.0 91.66666666666667 כדי לקבל חלוקה ממשית – חובה לשים (double) לפני החלוקה ד''ר יבגני קנל

  22. פעולות קלט/פלט • פלט/ קלט סטנדרטי שימוש בכלים של Java, "מומלץ" על ידי פיקוח • מחלקה IO מומלץ על ידי צוותי פיתוח של מכון ויצמן, האוניברסיטה הפתוחה, והאוניברסיטה העברית,. • מחלקה In מומלץ על ידי צוות פיתוח של אוניברסיטת תל-אביב ד''ר יבגני קנל

  23. פעולות פלט • System.out.println(5); • System.out.println(“num”); • int num=5;System.out.println(num); • System.out.println(“num=“+num); • int num1=5, num2=6;System.out.println(num1+num2);System.out.println(“sum:“+num1+num2);System.out.println(“nums: ”+num1+” “+num2); ד''ר יבגני קנל

  24. הדפסת מספר ממשי עם דיוק ספרות רצוי. (הפיכתו למחרוזת) //שימוש בקלט פלט תקני    double num = ...   System.out.format("The number is %6.2f ", num); //או הפיכה למחרוזת    double num = ...   String s = String.format("The number is %6.2f ", num);   System.out.println(s); //import java.text.*; צריך שימוש בפקודה DecimalFormat df = new DecimalFormat("####0.00"); System.out.println("The number is " + df.format(number)); ד''ר יבגני קנל

  25. שימוש בקלט/פלט סטנדרטי • הוראות פלט: System.out.println( )או System.out.print( ) • הוראות קלט: הקלט הסטנדרטי יעשה ע"י המחלקה Scanner הנמצאת בספריה הסטנדרטית (java.util) • לפני כותרת המחלקה יש לרשום את המשפט: import java.util.*; • בתוך גוף המחלקה יש לכתוב את המשפט: Scanner input = new Scanner(System.in); • בתוך גוף המחלקה יש לרשום את פעולת הקלט לפי הטיפוסים הבסיסיים השונים: ד''ר יבגני קנל

  26. שימוש בקלט/פלט סטנדרטי אין קלט מסוים לתווים!char c=input.next().charAt(0); ד''ר יבגני קנל

  27. המורים חייבים ללמד קלט ב- Javaעל פי סטנדרט זה. דוגמא: התוכנית הבאה מחשבת את הממוצע של ערכי הקלט: import java.util.Scanner; class Average { public static void main(String[] args) { double sum = 0; int count = 0; Scanner input = new Scanner(System.in); while (input.hasNext()) { sum = sum + input.nextDouble(); count++; } System.out.println(“The average is “ + sum/count); } } - boolean hasNext()האם יש עוד token בקלט? ד''ר יבגני קנל

  28. שימוש בקלט/פלט של מחלקה In(אוניברסיטת תל-אביב) הוראות הפלט System.out.println(); System.out.print(); ד''ר יבגני קנל

  29. שימוש בקלט/פלט של מחלקה IO(מכון ויצמן- מוטי בן ארי) הוראות הפלט: IO.write(); IO.writeln(); IO.print(); IO.println() ד''ר יבגני קנל

  30. פלט עם דיוק רצוי ב-IO • double num = ... IO.println(String.format("The num is %6.2f ", num)); • double num1 = ..., num2=…; IO.println( String.format("num1 is %6.2f num2 is %6.2f ", num1,num2) ); ד''ר יבגני קנל

  31. סביבות העבודה • DrJava ספר רשמי של משרד החינוך "יסודות מדעי המחשב1-2 בשפת JAVA" אוניברסיטת תל-אביב • BlueJ "יסודות מדעי המחשב 1-2 בשפת JAVA" "מבט לחלונות" "עיצוב תוכנה מבוסס עצמים" האוניברסיטה העברית • JCreator ד''ר יבגני קנל

  32. ד''ר יבגני קנל

  33. DrJava ד''ר יבגני קנל

  34. ד''ר יבגני קנל

  35. www.drjava.org אתר של DrJava ד''ר יבגני קנל

  36. http://www.tau.ac.il/~csedu/yesodotoop/yesodot_dj_ins.html אתר של קבוצת מדעי המחשב –אוניברסיטת תל-אביב ד''ר יבגני קנל

  37. BlueJ ד''ר יבגני קנל

  38. ד''ר יבגני קנל

  39. http://www.bluej.orgאתר BlueJ ד''ר יבגני קנל

  40. Tools Preferences הוספת מחלקות שרות ד''ר יבגני קנל

  41. JCreator ד''ר יבגני קנל

  42. ד''ר יבגני קנל

  43. JCreator Compile Execute ד''ר יבגני קנל

  44. ד''ר יבגני קנל

  45. ד''ר יבגני קנל

  46. www.jcreator.comאתר של JCreator ד''ר יבגני קנל

  47. הוספת מחלקות שרות ד''ר יבגני קנל

  48. ד''ר יבגני קנל

  49. תבניות –Templates • Program Files -> • Xinox Software-> • JCreatorV4LE -> • FileTemplates -> • Java Classes • templates.xml ד''ר יבגני קנל

More Related