الكلية الجامعية للعلوم التطبيقية

Slides:



Advertisements
Similar presentations
STRING AN EXAMPLE OF REFERENCE DATA TYPE. 2 Primitive Data Types  The eight Java primitive data types are:  byte  short  int  long  float  double.
Advertisements

Computer Programming Lab(7).
Chapter 2 Elementary Programming
Liang, Introduction to Java Programming, Sixth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 2 1 Chapter 2 Primitive.
Primitive Data Types and Operations. Introducing Programming with an Example public class ComputeArea { /** Main method */ public static void main(String[]
Evan Korth Scanner class Evan Korth NYU. Evan Korth Java 1.5 (5.0)’s Scanner class Prior to Java 1.5 getting input from the console involved multiple.
Java Intro. Strings “This is a string.” –Enclosed in double quotes “This is “ + “another “ + “string” –+ concatenates strings “This is “ “ string”
Chapter 2: Java Fundamentals Input and Output statements.
Java Overview CS2336: Computer Science II1. First Program public class HelloWorld { public static void main(String args[]) { System.out.println("Hello.
Expressions, Data Conversion, and Input
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 2 Elementary Programming.
Simple Programs from Chapter 2 Putting the Building Blocks All Together (corresponds with Chapter 2)
Chapter 2: Basic Elements of Java J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
1 Chapter 2 Elementary Programming. 2 Objectives  To write Java programs to perform simple calculations  To obtain input from the console using the.
Java Fundamentals 3 Input and Output statements. Standard Output Window Using System.out, we can output multiple lines of text to the standard output.
Chapter 2 Elementary Programming
Math class services (functions) Primitive vs reference data types Scanner class Math class services (functions) Primitive vs reference data types Scanner.
Windows Programming, C.-S. Shieh, KUAS EC, Chapter 3 Operators and Expressions.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 2 Basic Elements of Java.
Can we talk?. In Hello World we already saw how to do Standard Output. You simply use the command line System.out.println(“text”); There are different.
Using Java Class Library
Primitive variables Android Club types of variables: Primitive single value (starts with uppercase letter) Complex multiple value (starts with.
FUNDAMENTALS 2 CHAPTER 2. OPERATORS  Operators are special symbols used for:  mathematical functions  assignment statements  logical comparisons 
Important Java terminology The information we manage in a Java program is either represented as primitive data or as objects. ● Primitive data (נתונים.
CSC 1051 – Algorithms and Data Structures I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
CompSci Classwork today  Back to bouncing balls  Create a new BouncingSmiley using inheritence  Create an Arraylist of bouncing balls and smileys.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
A: A: double “4” A: “34” 4.
Java – Variables and Constants By: Dan Lunney. Declaring Variables All variables must be declared before they can be used A declaration takes the form:
Chapter 2 Console Input and Output Copyright © 2010 Pearson Addison-Wesley. All rights reserved.
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.
Objectives  File I/O: using Scanner with File  Inserting into Partially Filled Array  Deleting from Partially Filled Array  Static methods and variables.
© 2007 Lawrenceville Press Slide 1 Chapter 4 Review Assignment Statement An assignment statement gives a value to a variable. Assignment can take several.
Java Programming: From Problem Analysis to Program Design, Second Edition 1 Lecture 1 Objectives  Become familiar with the basic components of a Java.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Elementary Programming.
1 1 Chapter 2 Elementary Programming. 2 2 Motivations In the preceding chapter, you learned how to create, compile, and run a Java program. Starting from.
JAVA 1.COMPARISON: JAVA AND C++ 2.KEYBOARD INPUT 3.OUTPUT 4.CONVERSION FROM STRING 5.OPERATORS AND EXPRESSIONS 6.DIALOG BOX – USER PROMPT January
Copyright 2008 by Pearson Education Building Java Programs Chapter 3 Lecture 3-3: Interactive Programs w/ Scanner reading: self-check: #16-19.
Fundamentals 2 1. Programs and Data Most programs require the temporary storage of data. The data to be processed is stored in a temporary storage in.
CPSC 233 Tutorial January 21 st /22 nd, Linux Commands.
Introduction to programming in java Lecture 16 Random.
Chapter 2: Basic Elements of Java
String Comparison, Scanner
CSC1401 Input and Output (and we’ll do a bit more on class creation)
Unit 2 Elementary Programming
Elementary Programming
Chapter 2 Elementary Programming
Data Conversion & Scanner Class
Chapter 3 Java Input/Output.
Chapter 2 Elementary Programming
Java Programming: From Problem Analysis to Program Design, 4e
Chapter 2 Elementary Programming
Starting JavaProgramming
مساق: خوارزميات ومبادئ البرمجة الفصل الدراسي الثاني 2016/2015
Introduction to Classes and Methods
Chapter 2: Basic Elements of Java
A+ Computer Science INPUT.
Java so far Week 7.
Fundamentals 2.
Unit 1: Intro Lesson 3: Input.
Chapter 3 Input/Output.
Chapter 2 Elementary Programming
Chapter 2: Java Fundamentals
A+ Computer Science INPUT.
CS2011 Introduction to Programming I Elementary Programming
Object Oriented Programming
មជ្ឈមណ្ឌលកូរ៉េ សហ្វវែរ អេច អ ឌី
Java: Variables, Input and Arrays
Math class services (functions)
Presentation transcript:

الكلية الجامعية للعلوم التطبيقية لغة برمجة حديثة (1) COMP 2301 د. سناء وفا الصايغ الفصل الأول 2010- 2011 جمل الادخال والعمليات الحسابية

المحتويات User Inputs جمل الادخال والعمليات الحسابية الإدخال بواسطة المستخدم (Input By Users) أنواع العمليات (Operations ) عمليات الإسناد ( Assignment Operations) الزيادة والنقصان (Increment & Decrement) العمليات الحسابية (Arithmetic Operations)  Page 2

الإدخال بواسطة المستخدم Input By users)) User Inputs جمل الادخال والعمليات الحسابية الإدخال بواسطة المستخدم Input By users)) هناك العديد من الطرق التي تطرحها لغة جافا والتي تمكن المستخدم من إدخال قيم المتغيرات بنفسه نحتاج كثير إلى أن نجعل المستخدم هو الذي يقوم بإدخال قيمة المتغير، بدلا من إعطاء المتغير قيمة ابتدائية ثابتة في داخل البرنامج، فكيف نستطيع عمل ذلك؟؟!! الجواب: من خلال استخدام الدوال الجاهزة في جافا والتي تقوم بانتظار إدخال قيم من لوحة المفاتيح سوف نستخدم الصنف Class المسمى Scanner.  Page 3 3

صنف الإدخال Class Scanner User Inputs جمل الادخال والعمليات الحسابية صنف الإدخال Class Scanner يحتوي هذا الـصنف Class على العديد من الدوال التي تتيح للمستخدم إدخال أنواع مختلفة من البيانات بواسطة لوحة المفاتيح، من أمثلة هذه الدوال: next() تتيح للمستخدم إدخال أي شيء وتخزينه كجملة String. nextInt() تتيح للمستخدم إدخال فيمة عددية صحيحة. nextFloat() تتيح لمستخدم إدخال عدد عشري. nextDouble() تتيح للمستخدم إدخال قيمة عشرية من نوع Double. nextLong() تتيح للمستخدم إدخال قسمة عددية صحيحة من نوع Long nextBoolean() تتيح للمستخدم إدخال قيمة منطقية من نوع Boolean  Page 4 4

How to Use Scanner? User Inputs جمل الادخال والعمليات الحسابية لكي نستطيع استخدام هذا الصنف Class نتبع الخطوات التالية: نقوم بتعريف متغير بأي اسم من نوع Scanner كالتالي: Scanner sc = new Scanner(System.in(; نفوم بتعريف أي متغير من أي نوع واستخدام المتغير الذي عرفناه سابقا من أجل إدخال قيمة المتغير الجديد ، مثل: int x=sc.nextInt(); float x=sc.nextFloat(); String x=sc.next ();  Page 5 5

تمرين 1: User Inputs جمل الادخال والعمليات الحسابية اكتب برنامج يقوم بحساب معدل 4 علامات ، بحيث يقوم المستخدم نفسه بإدخال هذه العلامات:  Page 6 6

تمرين 2: User Inputs جمل الادخال والعمليات الحسابية اكتب برنامج يطلب منك إدخال اسمك رباعيا ثم يقوم بعد ذلك بطباعة جملة ترحيبية لك باسمك:  Page 7 7

أنواع العمليات Operations Types)) جمل الادخال والعمليات الحسابية أنواع العمليات Operations Types)) هناك العديد من العمليات في لغات البرمجة والتي تتيح للمبرمج تحقيق الهدف من البرنامج. أولا العمليات الإسنادية (Assignment Operations): تستخدم هذه العمليات لإسناد قيمة معينة لمتغير ما بعد تعريف هذا المتغير. أمثلة: X =1 radius =1.0 ch = ‘A’  Page 8 8

عمليات الإسناد (Assignment Operations) Operations Types جمل الادخال والعمليات الحسابية عمليات الإسناد (Assignment Operations) ملاحظات مهمة: لا تسند قيمة من نوع يختلف عن نوع المتغير كأن تسند قيمة صحيحة لمتغير من نوع char مثلا اسم المتغير دائما يكون على يسار الإشارة وقيمة المتغير تكون على يمين الإشارة، أي أن الصيغة التالية تعتبر خطأ ( 1 = X). يمكن كتابة عمليات الإسناد بصورة مختصرة كما هو موضح بالجدول التالي:  Page 9 9

عمليات الإسناد (Assignment Operations) Operations Types جمل الادخال والعمليات الحسابية عمليات الإسناد (Assignment Operations)  Page 10 10

عامل الزيادة والنقصان (Increment & Decrement) Operations Types جمل الادخال والعمليات الحسابية عامل الزيادة والنقصان (Increment & Decrement) تمدنا لغة جافا بعامل الزيادة ++ وعامل النقصان –– وذلك من أجل زيادة قيمة متغير أ, إنقاص قميته بمقدار واحد باستخدام جملة واحدة مختصرة كالتالي: a++ بدلا من a = a+1 أ, بدلا من a+=1 a--بدلا من a = a-1 أو بدلا من a- =1  Page 11 11

أنواع العمليات Operations Types)) جمل الادخال والعمليات الحسابية أنواع العمليات Operations Types)) ثانيا: العمليات الحسابية (Arithmetic Operations): معظم برامج الحاسوب تقوم بعمليات حسابية ، والشكل التالي يوضح بعض هذه العمليات:  Page 12 12

أولويات العمليات الحسابية: Operations Types جمل الادخال والعمليات الحسابية أولويات العمليات الحسابية: تستخدم الأقواس في الجافا تماما كما نستخدمها في الجبر العادي لتحديد أولويات التنفيذ. أولويات التنفيذ: يتم احتساب ما بداخل الأقواس أولا إذا وجدت الأقواس. إذا كان هناك العديد من الأقواس المتداخلة يتم تنفيذ الأقواس الداخلية فالخارجية ثم الخارجية. يأتي بعد ذلك في الأولوية الضرب والقسمة والباقي ( * ، / ، %) ويكون التنفيذ من اليسار إلى اليمين. يأتي بعد ذلك الجمع والطرح وهما في نفس الترتيب والأولوية.  Page 13 13