Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
Lecture Fundamentals of computing 1 - Lecture 3 introduce the console Input and Output. This chapter presents the following content: Console output, using imported class, scanner class, common pitfalls. Inviting you refer. | Lecture Title: Console Input and Output Fundamentals of Computing 1 Agenda Console output Using imported class Scanner class Common pitfalls ask them, how might the computer store "hi" using binary digits? (some kind of mapping; ASCII) System.out.println for console output System.out is an object that is part of the Java language println is a method invoked by the System.out object that can be used for console output The data to be output is given as an argument in parentheses A plus sign is used to connect more than one item Every invocation of println ends a line of output System.out.println("The answer is " + 42); Console Input What if we want to let the users choose any values they want to use ? We can prompt the user by console (keyboard) input Console Input Import instruction Create Scanner object Read a first integer and assign it to variable a Read a second integer and assign it to variable b Agenda Console output Using imported class Scanner class Common pitfalls ask them, how might the computer store "hi" using binary digits? (some kind of mapping; ASCII) Importing Packages and Classes Libraries in Java are called packages A package is a collection of classes that is stored in a manner that makes it easily accessible to any program In order to use a class that belongs to a package, the class must be brought into a program using an import statement Classes found in the package java.lang are imported automatically into every Java program import java.text.NumberFormat; // import theNumberFormat class only import java.text.*; //import all the classes in package java.text Using * Agenda Console output Using imported class Scanner class Common pitfalls ask them, how might the computer store "hi" using binary digits? (some kind of mapping; ASCII) Console Input Using the Scanner Class Starting with version 5.0, Java includes a class for doing simple keyboard input named the Scanner class In order to use the Scanner class, a program must include the . | Lecture Title: Console Input and Output Fundamentals of Computing 1 Agenda Console output Using imported class Scanner class Common pitfalls ask them, how might the computer store "hi" using binary digits? (some kind of mapping; ASCII) System.out.println for console output System.out is an object that is part of the Java language println is a method invoked by the System.out object that can be used for console output The data to be output is given as an argument in parentheses A plus sign is used to connect more than one item Every invocation of println ends a line of output System.out.println("The answer is " + 42); Console Input What if we want to let the users choose any values they want to use ? We can prompt the user by console (keyboard) input Console Input Import instruction Create Scanner object Read a first integer and assign it to variable a Read a second integer and assign it to variable b Agenda Console output Using imported class Scanner class Common pitfalls ask