Danh mục

Java Programming for absolute beginner- P4

Số trang: 20      Loại file: pdf      Dung lượng: 528.85 KB      Lượt xem: 15      Lượt tải: 0    
Jamona

Hỗ trợ phí lưu trữ khi tải xuống: 17,000 VND Tải xuống file đầy đủ (20 trang) 0

Báo xấu

Xem trước 2 trang đầu tiên của tài liệu này:

Thông tin tài liệu:

Java Programming for absolute beginner- P4:Hello and welcome to Java Programming for the Absolute Beginner. You probablyalready have a good understanding of how to use your computer.These days it’s hard to find someone who doesn’t, given the importanceof computers in today’s world. Learning to control your computer intimatelyis what will separate you from the pack! By reading this book, you learnhow to accomplish just that through the magic of programming.
Nội dung trích xuất từ tài liệu:
Java Programming for absolute beginner- P4 JavaProgAbsBeg-02.qxd 2/25/03 8:13 AM Page 38 38 //The value of b will be 1. //The addition happens first because of the parentheses Java Programming for the Absolute Beginner //Next the division and then the subtraction. int b = 10 - (4 + 14) / 2; System.out.println(“10 - (4 + 14) / 2 = “ + b); //The value of c will be -1 int c = 10 - (4 + 14 / 2); System.out.println(“10 - (4 + 14 / 2) = “ + c); } } FIGURE 2.5 This demonstrates how parentheses affect operator precedence. Getting Simple User Input Thus far, the programs you have written have been one-sided in that they per- form specific tasks and do not accept any user input. Every time you run these programs the output is exactly the same, making them all but useless in the eyes of a user after the first few times they are run. How can you make procedures more dynamic? By adding the functionality to accept and use user input. Any- time the user runs the application, he or she can enter different input, causing the program to have the capability to have different output each time it is run. Because programmers write programs in the real world to be useful to users, this almost always means that the programs provide some interface that accepts user input. The program then processes that input and spits out the result. Accepting command-line input is a simple way to allow users to interact with your pro- grams. In this section, you will learn how to accept and incorporate user input into your Java programs. What follows is a listing of the HelloUser application: TEAM LinG - Live, Informative, Non-cost and Genuine!Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. JavaProgAbsBeg-02.qxd 2/25/03 8:13 AM Page 39 39 /* * HelloUser Chapter 2 * Demonstrates simple I/O */ import java.io.*; public class HelloUser { Variables, Data Types, and Simple I/O public static void main(String args[]) { String name; BufferedReader reader; reader = new BufferedReader(new InputStreamReader(System.in)); System.out.print(“ What is your name? “); try { name = reader.readLine(); ...

Tài liệu được xem nhiều: