Java applet 1 (2015-8-2)

Source: Internet
Author: User

1, from the keyboard input the side length of the square, to find the circumference and area of the square

Import Java.util.Scanner;

public class Test1 {

public static void Main (String []args) {

int c=0;

int s=0;

Scanner scan=new Scanner (system.in);

System.out.print ("side length of the square L:");

int L=scan.nextint ();

C=4*l;

S=l*l;

System.out.println ("The circumference of the square is:" +c+ "; the area of the square is:" +s);

}

}

2, from the keyboard input rectangular length, width, to find the circumference and area of the rectangle

Import Java.util.Scanner;

public class Test2 {

public static void Main (String []args) {

int c=0;

int s=0;

Scanner scan=new Scanner (system.in);

System.out.print ("Oblong long L:");

int L=scan.nextint ();

Scan.nextline ();

System.out.print ("Rectangular width w:");

int W=scan.nextint ();

c=2* (L+W);

S=l*w;

System.out.println ("The circumference of the rectangle is:" +c+ "; the area of the rectangle is:" +s);

}

}

3, enter 5 numbers from the keyboard, calculate the number of 5 and the product.

Import Java.util.Scanner;

public class Test3 {

public static void Main (String []args) {

Scanner scan=new Scanner (system.in);

System.out.print ("Please enter five number:");

Double a=scan.nextdouble ();

Double b=scan.nextdouble ();

Double c=scan.nextdouble ();

Double d=scan.nextdouble ();

Double e=scan.nextdouble ();

Double sum=a+b+c+d+e;

Double product=a*b*c*d*e;

System.out.println ("The sum of five data is:" +sum+ "\ n Five data of the product is:" +product);

}

}

4. Enter 3 numbers from the keyboard, an int type data, a double type, a float type data, and a sum of 3 numbers.

Import Java.util.Scanner;

public class Test {

public static void Main (String []args) {

Scanner scan=new Scanner (system.in);

System.out.print ("Integer Data:");

int A=scan.nextint ();

Scan.nextline ();

System.out.print ("Double-precision data:");

Double b=scan.nextdouble ();

Scan.nextline ();

System.out.print ("Floating-point data:");

float c=scan.nextfloat ();

Scan.nextline ();

System.out.println ("The sum of the three data is:" + (A+b+c));

}

}

5. Enter 3 numbers from the keyboard, an int type data, a double type, a float type data, and a sum of 3 numbers. (Note: The type to sum is of type int) (The conversion of the data type is used here)

Import Java.util.Scanner;

public class Test5 {

public static void Main (String []args) {

Scanner scan=new Scanner (system.in);

System.out.print ("Integer Data:");

int A=scan.nextint ();

Scan.nextline ();

System.out.print ("Double-precision data:");

Double b=scan.nextdouble ();

Scan.nextline ();

System.out.print ("Floating-point data:");

float c=scan.nextfloat ();

Scan.nextline ();

int sum= (int) (A+B+C);

System.out.println ("The sum of the three data is:" +sum);

}

}

Java applet 1 (2015-8-2)

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.