Reference data Type Foundation in Java (Scanner. Random)

Source: Internet
Author: User


/*
Scanner use Step (Receive user keyboard input)
1. Import package Scanner class Java file class-util file class Import
2. Create an instance of scanner
Data type variable name =new data type ();
3. Using the Scanner function
Nextint () Receive numbers
Next () Receive string
*/
Import Java.util.Scanner;
public class scannerdome{
public static void Main (string[] args) {
Scanner sc=new Scanner (system.in);
System.out.print ("Please enter a number:");
int A=sc.nextint ();//number
System.out.println (a);

System.out.print ("Please enter a string:");
String B=sc.next ();//number
System.out.println (b+1);
}
}


Import java.util.random;//Importing Packages
public class randomdome{
public static void Main (string[] args) {
Create an instance
Random r = new Random ();
Using the Random method
int i = r.nextint (100);//Generate Shaping random number
System.out.println (i);//output random number
if (i%2==0) {
System.out.println (i+ "is even");
}else {System.out.println (i+ "is odd");}
Generate a floating-point random number
Double m = r.nextdouble ();//Generate floating-point random number
System.out.println (m);//output random number
}
}

Reference data Type Foundation in Java (Scanner. Random)

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.