Java Note 7 entry

Source: Internet
Author: User


1  in order to make the program's data more consistent with the development data, we added keyboard entry.
     Make the program more flexible.
    
     So, how do we implement keyboard data entry?
        a: Guide Package
             format:
                import java.util.Scanner;
             Location:
                  on class.
        b: Create a Keyboard entry object
             Format:
                scanner sc = new Scanner (system.in) ;
        c: Get Data from Objects     
              Format:
                int x = Sc.nextint ();

Import Java.util.Scanner; class Scannerdemo {    publicstaticvoid  main (string[] args) {        //  Create a keyboard entry data object        new  Scanner (system.in);                System.out.println ("Please enter a data:");         int x = sc.nextint ();                System.out.println ("The data you entered is:" +x);}    }
1 /*2 Practice:3 keyboard input Three data, get the maximum value of these three data4 keyboard input Two data to compare whether the two data is equal5 */6 ImportJava.util.Scanner;7 8 classScannerTest3 {9      Public Static voidMain (string[] args) {Ten         //keyboard input Three data, get the maximum value of these three data One      A         //Creating a Keyboard entry object -Scanner sc =NewScanner (system.in); -          theSystem.out.println ("Please enter the first data:"); -         intA =sc.nextint (); -          -System.out.println ("Please enter a second data:"); +         intb =sc.nextint (); -          +System.out.println ("Please enter a third data:"); A         intc =sc.nextint (); at          -         //get the maximum value in these three data -         inttemp = ((a > B)?a:b); -         intmax = (temp > c?)temp:c); -System.out.println ("Max:" +max); -System.out.println ("------------------"); in          -         //keyboard input of two data toSystem.out.println ("Please enter the first data:"); +         intx =sc.nextint (); -          theSystem.out.println ("Please enter a second data:"); *         inty =sc.nextint (); $         Panax Notoginseng         //Compare whether the two data are equal -         BooleanFlag = (x = =y); theSystem.out.println ("flag:" +flag); +     } A}

2

Java Note 7 entry

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.