freepeople性欧美熟妇, 色戒完整版无删减158分钟hd, 无码精品国产vα在线观看DVD, 丰满少妇伦精品无码专区在线观看,艾栗栗与纹身男宾馆3p50分钟,国产AV片在线观看,黑人与美女高潮,18岁女RAPPERDISSSUBS,国产手机在机看影片

正文內容

[工學]anintroductiontojavaapplication(編輯修改稿)

2025-02-17 13:03 本頁面
 

【文章內容簡介】 : )。 / / p r o m p t 21 n u m b e r 2 = i n p u t . n e x t I n t ( ) 。 / / r e a d s e c o n d n u m b e r f r o m u s e r 22 23 s u m = n u m b e r 1 + n u m b e r 2 。 / / a d d n u m b e r s 24 25 S y s t e m . o u t . p r i n t f ( S u m i s % d \ n , s u m ) 。 / / d i s p l a y s u m 26 27 } / / e n d m e t h o d m a i n 28 29 } / / e n d c l a s s A d d i t i o n E n t e r f i r s t i n t e g e r : 45 E n t e r s e c o n d i n t e g e r : 72 S u m i s 1 1 7 Read an integer from the user and assign it to number2. Calculate the sum of the variables number1 and number2, assign result to sum. Display the sum using formatted output. Two integers entered by the user. What we learn from this program? ? How should we input by keyboard? Import 。 import Scanner from java package: Question ? is the function of the import’s statement? ? we locate this statement? ? 3. For Line 11,What is and what is a Scanner? ? 4. How to create a Scanner object? ? Line1315, why declare the same type of variables in different lines? Question ? to identify a variable name? ? package are the class System in and why not import this class? ? to obtain a number from keyboard? ? is the function of statement? Another Java Application: Adding Integers (Cont.) ? import declarations ? Used by piler to identify and locate classes used in Java programs ? Tells piler to load class Scanner from package ? Begins public class Addition ? Recall that file name must be 3 import 。 // program uses class Scanner 5 public class Addition 6 { Another Java Application: Adding Integers (Cont.) ? Variable Declaration Statement ? Variables ? Location in memory that stores a value ? Declare with name and type before use ?Input is of type Scanner ? Enables a program to read data for use ? Variable name: any valid identifier ? Declarations end with semicolons 。 ? Initialize variable in its declaration ? Equal sign ? Standard input object ? 10 // create Scanner to obtain input from mand window 11 Scanner input = new Scanner( )。 Another Java Application: Adding Integers (Cont.) ? Declare variable number1, number2 and sum of type int ? int holds integer values (whole numbers): ., 0, 4, 97 ? Types float and double can hold decimal numbers ? Type char can hold a single character: ., x, $, \n, 7 ? int, float, double and char are primitive types ? Can add ments to describe purpose of variables ? Can declare multiple variables of the same type in one declaration ? Use maseparated list 13 int number1。 // first number to add 14 int number2。 // second number to add 15 int sum。 // second number to add int number1, // first number to add number2, // second number to add sum。 // second number to add Another Java Application: Adding Integers (Cont.) ? Message called a prompt directs user to perform an action ? Package ? Result of call to nextInt given to number1 using assignment operator = ?Assignment statement ?= binary operator takes two operands ? Expression on right evaluated and assigned to variable on left ?Read as: number1 gets the value of () 17 ( Enter first integer: )。 // prompt 18 number1 = ()。 // read first number from user Another Java Application: Adding Integers (Cont.) ? Similar to previous statement ? Prompts the user to input the second integer ? Similar to previous statement ? Assign variable number2 to second integer input ? Assignment statement ? Calculates sum of number1 and number2 (right hand side) ? Uses assignment operator = to assign result to variable sum ? Read as: sum gets the value of number1 + number2 ? number1 and number2 are operands 20 ( Enter second integer: )。 // prompt 21 number2 = ()。 // read second number from user 23 sum = number1 + number2。 // add numbers Another Java Application: Adding Integers (Cont.) ? Use to display results ? Format specifier %d ?Placeholder for an int value ? Calculations can also be performed inside printf ? Parentheses around the expression number1 + number2 are not required 25 ( Sum is %d\n: , sum )。 // display sum ( Sum is %d\n: , ( number1 + number2 ) )。 What we learn from this program? ? How should we input by keyboard? Import 。 Scanner input = new Scanner()。 Create an object of scanner to accept the input from user What we learn from this program? ? How should we input by keyboard? Import 。 Scanner input = new Scanner()。 int number = ()。 Use method nextInt of class Scanner to accept the a integer from keyboard variable Declaration ? Int number1; ? Int number2; data type Variable name Memory Concepts ? Variables ? Every variable has a name, a type, a size and a value ?Name corresponds to location in memory ? When new value is placed into a variable, replaces (and destroys) previous value ? Reading variables from memory does not change them Fig. | Memory location showing the name and value of variable number1. Fig. | Memory locations after storing values for number1 and number2. Fig. | Memory locations after calculating and storing the sum of number1 and number2. Arithmetic ? Arithmetic calculations used in most programs ? Usage ?* for multiplication ?/ for division ?% for remainder ?+, ? Integer division truncates remainder 7 / 5 evaluates to 1 ? Remainder operator % returns the remainder 7 % 5 evaluates to 2 Fig. |
點擊復制文檔內容
教學課件相關推薦
文庫吧 www.dybbs8.com
備案圖片鄂ICP備17016276號-1