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)