前言:
题目集01题目较多,偏向于基本的java的一些代码、方法的用法
题目集02题目较少,考核重点为输入字符串,并对字符串做变换或判断及判断其中某个或多个字符
题目集03题目最少难度也最高,考察的知识是类之间的关系及相互调用,是面向对象程序设计的基础,创建的类繁多且复杂
(2)设计与分析:重点对题目的提交源码进行分析
SourceMonitor有关度量值知识信息摘抄
度量值
1. 总行数(Lines)
包括空行在内的代码行数。
2. 语句数(Statements)
语句是以分号结尾的。分支语句if,循环语句for、while,跳转语句goto都被计算在内。
3. 分支语句比例(Percent Branch Statements)
该值表示分支语句占语句数目的比例,这里的“分支语句”指的是使程序不顺序执行的语句,包括if、else、for、while、break、continue、goto、switch、case、default和return。需要注意的是,do不被计算在内,因为其对应的while已经计算了。另外,异常处理的catch也被作为一个分支计算。
4. 注释比例(Percent Lines with Comments)
该值指示注释行(包括/*……*/和//……形式的注释)占总行数的比例。一般公司会对每个文档的header或者footer部分进行特殊的声明注释,可以再工程属性中设置过滤,不计算在内。
5. 类个数(Classes)
包括class的个数。
6. 平均每个类方法数(Methods per Class)
平均每个类的方法数,即包括内联和非内联的,template函数在内的类方法数除以所有类的个数。
7. 函数个数(Functions)
所有函数的个数。
8. 平均每个函数包含的语句数目(Average Statements per Method)
总的函数语句数目除以函数数目得到该值。
9. 函数圈复杂度(Function Complexity)
圈复杂度指示一个函数可执行路径的数目,以下语句为圈复杂度的值贡献1:if/else/for/while语句,三元运算符语句,if/for/while判断条件中的"&&"或“||”,switch语句,后接break/goto/ return/throw/continue语句的case语句,catch/except语句等。对应有最大圈复杂度(Max Complexity)和平均圈复杂度(Avg Complexity)。
10. 函数深度(Block Depth)
函数深度指示函数中分支嵌套的层数。对应有最大深度(Max Depth)和平均深度(Avg Depth)。
题目集04
7-1 点线形系列1-计算两点之间的距离
输入连个点的坐标,计算两点之间的距离public static void main(String[] args) {
Point point1 = new Point();
Scanner sc = new Scanner(System.in);
int t=0;
String a = sc.nextLine();
for(int i=0;i<a.length();i++)
{
if(a.charAt(i)==' '){
t=1;
break;
}
}
if(t==0)
{
System.out.println("Wrong Format");
System.exit(0);
}
String[] string1 = a.split(" ");
for(int i=0;i<string1[0].length();i++)
{
if(a.charAt(i)==','){
t=0;
break;
}
}
if(t==1)
{
System.out.println("Wrong Format");
System.exit(0);
}
for(int i=0;i<string1[1].length();i++)
{
if(a.charAt(i)==','){
t=1;
break;
}
}
if(t==0)
{
System.out.println("Wrong Format");
System.exit(0);
}
String[] string2 = string1[0].split(",");
String[] string3 = string1[1].split(",");
if (isNumeric(string2[0]) == false || isNumeric(string2[1]) == false || isNumeric(string3[0]) == false || isNumeric(string3[1]) == false) {
System.out.println("Wrong Format");
System.exit(0);
}
if (string1.length > 2) {
System.out.println("wrong number of points");
System.exit(0);
}
Point point3 = new Point(Double.valueOf(string2[0]), Double.valueOf(string2[1]));
Point point4 = new Point(Double.valueOf(string3[0]), Double.valueOf(string3[1]));
System.out.println(point1.distance(point3, point4));
}
public static boolean isNumeric(String c) {
if (c.replace("-", "").matches("^[0-9]+$")) {
return true;
} else {
if (c.replace("-", "").matches("\\d+.\\d+")) {
return true;
} else {
if (c.replace("+", "").matches("^[0-9]+$")) {
return true;
}
else{
if (c.replace("+", "").matches("\\d+.\\d+")){
return true;
}
else
return false;
}
}
}
}
}
class Point {
private double x;
private double y;
public Point(double x,double y){
super();
this.x=x;
this.y=y;
}
public Point(){
super();
}
public double distance(Point p1, Point p2){
double distance=Math.sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y));
return distance;
}
}
用户输入一组选项和数据,进行与直线有关的计算。选项包括:
1:输入两点坐标,计算斜率,若线条垂直于X轴,输出"Slope does not exist"。
2:输入三个点坐标,输出第一个点与另外两点连线的垂直距离。
3:输入三个点坐标,判断三个点是否在一条线上,输出true或者false。
4:输入四个点坐标,判断前两个点所构成的直线与后两点构成的直线是否平行,输出true或者false.
5:输入四个点坐标,计算输出前两个点所构成的直线与后两点构成的直线的交点坐标,x、y坐标之间以英文分隔",",并输出交叉点是否在两条线段之内(不含四个端点)的判断结果(true/false),判断结果与坐标之间以一个英文空格分隔。若两条线平行,没有交叉点,则输出"is parallel lines,have no intersection point"。
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String a = sc.nextLine();
maohao(a);
String[] string1 = a.split(":");
if(string1.length>2||string1[0].length()!=1){
m();
}
else
{
if(Double.valueOf(string1[0])==1)
{
kongge(string1[1]);
String[] string2 = string1[1].split(" ");
if(string2.length!=2){
System.out.println("wrong number of points");
System.exit(0);
}
else
{
douhao(string2[0]);
douhao(string2[1]);
String[] string3 = string2[0].split(",");
String[] string4 = string2[1].split(",");
// ling(string3[0]); ling(string3[1]); ling(string4[0]); ling(string4[1]);
if(f(string3[0])&&f(string3[1])&&f(string4[0])&&f(string4[1]))
{
double q = Double.valueOf(string3[0]);
double w = Double.valueOf(string3[1]);
double e = Double.valueOf(string4[0]);
double r = Double.valueOf(string4[1]);
if(q==e&&w==r)
{
System.out.println("points coincide");
}
else if(q==e&&w!=r) {
System.out.println("Slope does not exist");
}
else {
System.out.println((w-r)/(q-e));
} }
else {
m(); } } }
else if(Double.valueOf(string1[0])==2) {
kongge(string1[1]);
String[] string2 = string1[1].split(" ");
if(string2.length!=3){
System.out.println("wrong number of points");
System.exit(0); }
else{
douhao(string2[0]);
douhao(string2[1]);
douhao(string2[2]);
String[] string3 = string2[0].split(",");
String[] string4 = string2[1].split(",");
String[] string5 = string2[2].split(",");
ling(string3[0]); ling(string3[1]); ling(string4[0]); ling(string4[1]); ling(string5[0]); ling(string5[1]);
if(f(string3[0])&&f(string3[1])&&f(string4[0])&&f(string4[1])&&f(string5[0])&&f(string5[1])) {
double q = Double.valueOf(string3[0]);
double w = Double.valueOf(string3[1]);
double e = Double.valueOf(string4[0]);
double r = Double.valueOf(string4[1]);
double t = Double.valueOf(string5[0]);
double y = Double.valueOf(string5[1]);
if(q==e&&w==r||q==t&&w==y||e==t&&r==y) {
System.out.println("points coincide");
}
else if(e==t) {
System.out.println(Math.abs(q-e));
}
else {
double k = (r-y)/(e-t);
System.out.println(Math.abs(k*q-w-k*e+r)/Math.sqrt(k*k+1));
}
}
else {
m(); } } }
else if(Double.valueOf(string1[0])==3){
kongge(string1[1]);
String[] string2 = string1[1].split(" ");
if(string2.length!=3){
System.out.println("wrong number of points");
System.exit(0);
}
else{
douhao(string2[0]);
douhao(string2[1]);
douhao(string2[2]);
String[] string3 = string2[0].split(",");
String[] string4 = string2[1].split(",");
String[] string5 = string2[2].split(",");
//ling(string3[0]); ling(string3[1]); ling(string4[0]); ling(string4[1]); ling(string5[0]); ling(string5[1]);
if(f(string3[0])&&f(string3[1])&&f(string4[0])&&f(string4[1])&&f(string5[0])&&f(string5[1])){
double q = Double.valueOf(string3[0]);
double w = Double.valueOf(string3[1]);
double e = Double.valueOf(string4[0]);
double r = Double.valueOf(string4[1]);
double t = Double.valueOf(string5[0]);
double y = Double.valueOf(string5[1]);
if(q==e&&w==r||q==t&&w==y||e==t&&r==y){
System.out.println("points coincide");
}
else if(e==t&&q==e) {
System.out.println("true");
}
else if(e==t&&t!=q||e==q&&q!=t||t==q&&q!=e) {
System.out.println("false");
}
else{
double k1 = (r-y)/(e-t);
double k2 = (w-r)/(q-e);
if(k1==k2){
System.out.println("true");
}
else
System.out.println("false");
} }
else {
m();
} } }
else if(Double.valueOf(string1[0])==4)
{
kongge(string1[1]);
String[] string2 = string1[1].split(" ");
if(string2.length!=4){
System.out.println("wrong number of points");
System.exit(0);
}
else {
douhao(string2[0]);
douhao(string2[1]);
douhao(string2[2]);
douhao(string2[3]);
String[] string3 = string2[0].split(",");
String[] string4 = string2[1].split(",");
String[] string5 = string2[2].split(",");
String[] string6 = string2[3].split(",");
// ling(string3[0]); ling(string3[1]);ling(string4[0]); ling(string4[1]); ling(string5[0]); ling(string5[1]); ling(string6[0]); ling(string6[1]);
if(f(string3[0])&&f(string3[1])&&f(string4[0])&&f(string4[1])&&f(string5[0])&&f(string5[1])&&f(string6[0])&&f(string6[1])) {
double q = Double.valueOf(string3[0]);
double w = Double.valueOf(string3[1]);
double e = Double.valueOf(string4[0]);
double r = Double.valueOf(string4[1]);
double t = Double.valueOf(string5[0]);
double y = Double.valueOf(string5[1]);
double u = Double.valueOf(string6[0]);
double i = Double.valueOf(string6[1]);
if(q==e&&w==r||q==t&&w==y||q==u&&w==i||e==t&&r==y||e==u&&r==i||t==u&&y==i) {
System.out.println("points coincide");
}
else if(q==e&&t==u) {
System.out.println("true");
}
else if(q==e&&t!=u||q!=e&&t==u) {
System.out.println("false");
}
else
{
double k1 = (w-r)/(q-e);
double k2 = (y-i)/(t-u);
if(k1==k2)
System.out.println("true");
else
System.out.println("false");
} }
else {
m();
} } }
else if(Double.valueOf(string1[0])==5) {
kongge(string1[1]);
String[] string2 = string1[1].split(" ");
if(string2.length!=4){
System.out.println("wrong number of points");
System.exit(0);
}
else {
douhao(string2[0]);
douhao(string2[1]);
douhao(string2[2]);
douhao(string2[3]);
String[] string3 = string2[0].split(",");
String[] string4 = string2[1].split(",");
String[] string5 = string2[2].split(",");
String[] string6 = string2[3].split(",");
// ling(string3[0]); ling(string3[1]); ling(string4[0]); ling(string4[1]); ling(string5[0]); ling(string5[1]); ling(string6[0]); ling(string6[1]);
if(f(string3[0])&&f(string3[1])&&f(string4[0])&&f(string4[1])&&f(string5[0])&&f(string5[1])&&f(string6[0])&&f(string6[1])) {
double q = Double.valueOf(string3[0]);
double w = Double.valueOf(string3[1]);
double e = Double.valueOf(string4[0]);
double r = Double.valueOf(string4[1]);
double t = Double.valueOf(string5[0]);
double y = Double.valueOf(string5[1]);
double u = Double.valueOf(string6[0]);
double i = Double.valueOf(string6[1]);
if(q==e&&w==r||q==t&&w==y||q==u&&w==i||e==t&&r==y||e==u&&r==i||t==u&&y==i) {
System.out.println("points coincide");
}
else if(q==e&&t==u)
System.out.println("is parallel lines,have no intersection point");
else if(q==e&&t!=u) {
double k=(y-i)/(t-u);
float o;
o=(float)(k*(q-t)+y);
System.out.print((float)(q)+","+(float)(o)+" ");
if(l(t,u,q))
System.out.print("true");
else
System.out.print("false"); }
else if(q!=e&&t==u) {
double k=(w-r)/(q-e);
float o;
o=(float)(k*(t-q)+w);
System.out.print((float)(t)+","+o+" ");
if(l(q,e,t))
System.out.print("true");
else
System.out.print("false");
}
else {
double k1 = (w-r)/(q-e);
double k2 = (y-i)/(t-u);
if(k1==k2)
System.out.println("is parallel lines,have no intersection point");
else {
float o = (float)((y-w-k2*t+k1*q)/(k1-k2));
float x = (float)(((o-w)/k1)+q);
System.out.print(x+","+o+" ");
if(l(q,e,x)||l(t,u,x))
System.out.print("true");
else
System.out.print("false");
} } }
else {
m();
} } }
else{
m();
} } }
public static boolean f(String c) {
if (c.replace("-", "").matches("^[0-9]+$") || c.replace("-", "").matches("\\d+.\\d+") || c.replace("+", "").matches("^[0-9]+$") || c.replace("+", "").matches("\\d+.\\d+")) {
return true;
} else {
return false;
}
}
public static void m() {
System.out.println("Wrong Format");
System.exit(0);
}
public static void kongge(String c){
int t=0;
for(int i=0;i<c.length();i++)
{
if(c.charAt(i)==' '){
t=1;
break;
} }
if(t==0)
m(); }
public static void douhao(String c)
{
int t=0;
for(int i=0;i<c.length();i++)
{
if(c.charAt(i)==','){
t=1;
break;
}
}
if(t==0)
m();
}
public static void maohao(String c) {
int t=0;
for(int i=0;i<c.length();i++) {
if(c.charAt(i)==':'){
t=1;
break;
} }
if(t==0)
m();}
public static void ling(String c){
for(int i=0;i<c.length();i++){
if(i==0) {if(c.charAt(i)=='0'&&c.charAt(i+1)>='0'&&c.charAt(i+1)<='9'){
m();
}
}
else if(c.charAt(i)=='0'&&(c.charAt(i-1)<'0'||c.charAt(i-1)>'9')&&c.charAt(i+1)>='0'&&c.charAt(i+1)<='9') {
m();
} }
}
public static boolean l(double x,double y,double z)
{
if(x>y)
{
if(z>y&&z<x)
return true;
else
return false;
}
else
if(z<y&&z>x)
return true;
else
return false;
}
}
用户输入一组选项和数据,进行与三角形有关的计算。选项包括:
1:输入三个点坐标,判断是否是等腰三角形、等边三角形,判断结果输出true/false,两个结果之间以一个英文空格符分隔。
2:输入三个点坐标,输出周长、面积、重心坐标,三个参数之间以一个英文空格分隔,坐标之间以英文","分隔。
3:输入三个点坐标,输出是钝角、直角还是锐角三角形,依次输出三个判断结果(true/false),以一个英文空格分隔,
4:输入五个点坐标,输出前两个点所在的直线与三个点所构成的三角形相交的交点数量,如果交点有两个,则按面积大小依次输出三角形被直线分割成两部分的面积。若直线与三角形一条线重合,输出"The point is on the edge of the triangle"
5:输入四个点坐标,输出第一个是否在后三个点所构成的三角形的内部(输出in the triangle/outof triangle)。
必须使用射线法,原理:由第一个点往任一方向做一射线,射线与三角形的边的交点(不含点本身)数量如果为1,则在三角形内部。如果交点有两个或0个,则在三角形之外。若点在三角形的某条边上,输出"on the triangle"
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String a = sc.nextLine();
maohao(a);
String[] string1 = a.split(":");
if(string1.length>2||string1[0].length()!=1){
m();
}
else
{
if(Double.valueOf(string1[0])==1)
{
kongge(string1[1]);
String[] string2 = string1[1].split(" ");
if(string2.length!=3){
System.out.println("wrong number of points");
System.exit(0);
}
else
{
douhao(string2[0]);
douhao(string2[1]);
douhao(string2[2]);
String[] string3 = string2[0].split(",");
String[] string4 = string2[1].split(",");
String[] string5 = string2[2].split(",");
if(f(string3[0])&&f(string3[1])&&f(string4[0])&&f(string4[1])&&f(string5[0])&&f(string5[1]))
{
double q = Double.valueOf(string3[0]);double w = Double.valueOf(string3[1]);
double e = Double.valueOf(string4[0]);double r = Double.valueOf(string4[1]);
double t = Double.valueOf(string5[0]);double y = Double.valueOf(string5[1]);
double k1=(w-r)/(q-e);
double k2=(w-y)/(q-t);
double b = Math.sqrt((q-e)*(q-e)+(w-r)*(w-r));double n = Math.sqrt((q-t)*(q-t)+(w-y)*(w-y));double m = Math.sqrt((e-t)*(e-t)+(r-y)*(r-y));
if(q==e&&w==r||q==t&&w==y||e==t&&r==y||q==e&&e==t||w==r&&w==y||k1==k2)
{
System.out.println("data error");
}
else if(b==n||b==m||n==m)
{
System.out.print("true ");
if(b==n&&b==m) System.out.println("true");
else System.out.println("false");
}
else {
System.out.println("false false");
}
}
else
{
m();
}
}
}
else if(Double.valueOf(string1[0])==2)
{
kongge(string1[1]);
String[] string2 = string1[1].split(" ");
if(string2.length!=3){
System.out.println("wrong number of points");
System.exit(0);
}
else
{
douhao(string2[0]);
douhao(string2[1]);
douhao(string2[2]);
String[] string3 = string2[0].split(",");
String[] string4 = string2[1].split(",");
String[] string5 = string2[2].split(",");
if(f(string3[0])&&f(string3[1])&&f(string4[0])&&f(string4[1])&&f(string5[0])&&f(string5[1]))
{
double q = Double.valueOf(string3[0]);double w = Double.valueOf(string3[1]);
double e = Double.valueOf(string4[0]);double r = Double.valueOf(string4[1]);
double t = Double.valueOf(string5[0]);double y = Double.valueOf(string5[1]);
double k1=(w-r)/(q-e);
double k2=(w-y)/(q-t);
double b = Math.sqrt((q-e)*(q-e)+(w-r)*(w-r));double n = Math.sqrt((q-t)*(q-t)+(w-y)*(w-y));double m = Math.sqrt((e-t)*(e-t)+(r-y)*(r-y));
if(q==e&&w==r||q==t&&w==y||e==t&&r==y||q==e&&e==t||w==r&&w==y||k1==k2)
{
System.out.println("data error");
}
else{double k = (r-y)/(e-t);
double d = Math.abs(k*q-w-k*e+r)/Math.sqrt(k*k+1);
System.out.print(round(add(b+n,m),6));System.out.print(" ");System.out.print(round(mul(d/2,m),6));
System.out.print(" ");System.out.print(round(add(q/3+e/3,t/3),6));System.out.print(",");System.out.print(round(add(w/3+y/3,r/3),6)); }
}
else
{
m();
}
} }
else if(Double.valueOf(string1[0])==3){
kongge(string1[1]);
String[] string2 = string1[1].split(" ");
if(string2.length!=3){
System.out.println("wrong number of points");
System.exit(0);
}
else{
douhao(string2[0]);
douhao(string2[1]);
douhao(string2[2]);
String[] string3 = string2[0].split(",");
String[] string4 = string2[1].split(",");
String[] string5 = string2[2].split(",");
if(f(string3[0])&&f(string3[1])&&f(string4[0])&&f(string4[1])&&f(string5[0])&&f(string5[1]))
{
double q = Double.valueOf(string3[0]);double w = Double.valueOf(string3[1]);
double e = Double.valueOf(string4[0]);double r = Double.valueOf(string4[1]);
double t = Double.valueOf(string5[0]);double y = Double.valueOf(string5[1]);
double k1=(w-r)/(q-e);
double k2=(w-y)/(q-t);
double b = Math.sqrt((q-e)*(q-e)+(w-r)*(w-r));double n = Math.sqrt((q-t)*(q-t)+(w-y)*(w-y));double m = Math.sqrt((e-t)*(e-t)+(r-y)*(r-y));
if(q==e&&w==r||q==t&&w==y||e==t&&r==y||q==e&&e==t||w==r&&w==y||k1==k2) {
System.out.println("data error");
System.exit(0);
}
if(Math.abs(b*b-n*n-m*m)<(1e-10)||Math.abs(n*n-m*m-b*b)<(1e-10)||Math.abs(m*m-n*n-b*b)<(1e-10))
{System.out.println("false true false");System.exit(0);}
if(b*b-n*n-m*m>0||n*n-m*m-b*b>0||m*m-n*n-b*b>0)
{ System.out.println("true false false");System.exit(0);}
if(b*b-n*n-m*m<0&&n*n-m*m-b*b<0&&m*m-n*n-b*b<0) {System.out.println("false false true");System.exit(0);}
}
else
{
m();
}
}
}
else if(Double.valueOf(string1[0])==4)
{
kongge(string1[1]);
String[] string2 = string1[1].split(" ");
if(string2.length!=5){
System.out.println("wrong number of points");
System.exit(0);
}
else {
douhao(string2[0]);
douhao(string2[1]);
douhao(string2[2]);
douhao(string2[3]);douhao(string2[4]);
String[] string3 = string2[0].split(",");
String[] string4 = string2[1].split(",");
String[] string5 = string2[2].split(",");
String[] string6 = string2[3].split(",");
String[] string7 = string2[4].split(",");
if(f(string3[0])&&f(string3[1])&&f(string4[0])&&f(string4[1])&&f(string5[0])&&f(string5[1])&&f(string6[0])&&f(string6[1])&&f(string7[0])&&f(string7[1])) {
double q = Double.valueOf(string3[0]);double w = Double.valueOf(string3[1]);
double e = Double.valueOf(string4[0]);double r = Double.valueOf(string4[1]);
double t = Double.valueOf(string5[0]);double y = Double.valueOf(string5[1]);
double u = Double.valueOf(string6[0]);double i = Double.valueOf(string6[1]);
double d = Double.valueOf(string7[0]);double s = Double.valueOf(string7[1]);
double k1=(y-i)/(t-u); double k2=(y-s)/(t-d);
if(t==u&&y==i||t==d&&y==s||u==d&&i==s||t==u&&u==d||y==i&&y==s||k1==k2) {
System.out.println("data error");
}else if(q==e&&w==r){
System.out.println("points coincide");
}else if(xian(q,w,t,y,u,i)&&xian(e,r,t,y,u,i)||xian(q,w,t,y,d,s)&&xian(e,r,t,y,d,s)||xian(q,w,d,s,u,i)&&xian(e,r,d,s,u,u)) {
System.out.println("The point is on the edge of the triangle");
}
else{
System.out.println("0");
}
}
else
{
m();
} } }
else if(Double.valueOf(string1[0])==5)
{
kongge(string1[1]);
String[] string2 = string1[1].split(" ");
if(string2.length!=4){
System.out.println("wrong number of points");
System.exit(0);
}
else
{
douhao(string2[0]);
douhao(string2[1]);
douhao(string2[2]);
douhao(string2[3]);
String[] string3 = string2[0].split(",");
String[] string4 = string2[1].split(",");
String[] string5 = string2[2].split(",");
String[] string6 = string2[3].split(",");
if(f(string3[0])&&f(string3[1])&&f(string4[0])&&f(string4[1])&&f(string5[0])&&f(string5[1])&&f(string6[0])&&f(string6[1]))
{
double q = Double.valueOf(string3[0]);double w = Double.valueOf(string3[1]);
double e = Double.valueOf(string4[0]);double r = Double.valueOf(string4[1]);
double t = Double.valueOf(string5[0]);double y = Double.valueOf(string5[1]);
double u = Double.valueOf(string6[0]);double i = Double.valueOf(string6[1]);
int count=0;
double k4=(r-y)/(e-t); double k5=(r-i)/(e-u);
if(e==t&&r==y||e==u&&r==i||t==u&&y==i||e==t&&e==u||r==y&&r==i||k4==k5) {
System.out.println("data error");
}
else if(xian(q,w,e,r,t,y)&&l(t,e,q)||xian(q,w,e,r,u,i)&&l(e,u,q)||xian(q,w,t,y,u,i)&&l(t,u,q))
System.out.println("The point is on the edge of the triangle");
else if(r==y) { double k2=(r-i)/(e-u);double k=k2*(q-t)+y; double k3=(y-i)/(t-u);double l=k3*(q-u)+i;
if(l(r,i,k)&&k>w) count++;
if(l(y,i,l)&&l>w) count++;
if(count==1) System.out.println("in the triangle");
else System.out.println("outof the triangle");
}
else if(r==i){ double k1=(r-y)/(e-t);double j=k1*(q-e)+r; double k3=(y-i)/(t-u);double l=k3*(q-u)+i;
if(l(r,y,j)&&j>w) count++;if(l(y,i,l)&&l>w) count++;
if(count==1) System.out.println("in the triangle");
else System.out.println("outof the triangle");
}
else if(y==i){double k1=(r-y)/(e-t);double j=k1*(q-e)+r; double k2=(r-i)/(e-u);double k=k2*(q-t)+y;
if(l(r,y,j)&&j>w) count++; if(l(r,i,k)&&k>w) count++;
if(count==1) System.out.println("in the triangle");
else System.out.println("outof the triangle");
}
else {
double k1=(r-y)/(e-t);double j=k1*(q-e)+r;
double k2=(r-i)/(e-u);double k=k2*(q-t)+y;
double k3=(y-i)/(t-u);double l=k3*(q-u)+i;
if(l(r,y,j)&&j>w) count++;
if(l(r,i,k)&&k>w) count++;
if(l(y,i,l)&&l>w) count++;
if(count==1) System.out.println("in the triangle");
else System.out.println("outof the triangle");
}
}
else
{
m();
}
}
}
else{
m();
}
}
}
public static double add(double d1, double d2) {
BigDecimal b1 = new BigDecimal(Double.toString(d1));
BigDecimal b2 = new BigDecimal(Double.toString(d2));
return b1.add(b2).doubleValue();
}
public static double mul(double d1, double d2) {
BigDecimal b1 = new BigDecimal(Double.toString(d1));
BigDecimal b2 = new BigDecimal(Double.toString(d2));
return b1.multiply(b2).doubleValue();
}
校验键盘输入的 QQ 号是否合格,判定合格的条件如下:
import java.util.Scanner;
class Main {
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
String a;
a=input.next();
if(a.length()>=5&&a.length()<=15)
{
String regex = "[1-9][0-9]{4,14}";
if(a.matches(regex))
{
System.out.print("你输入的QQ号验证成功");
}
else
System.out.print("你输入的QQ号验证失败");
}
else
System.out.print("你输入的QQ号验证失败");
}
}
import java.util.Scanner;
class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String str = sc.nextLine();
char[]chars = str.toCharArray();
Arrays.sort(chars);
System.out.println(new String(chars));
}
}
接受给定的字符串,判断该字符串是否属于验证码。验证码是由四位数字或者字母(包含大小写)组成的字符串。
class Main {
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
String a;
a=input.next();
String regex = "[0-9]|[a-z]|[A-Z]{4}";
if(a.matches(regex))
{
System.out.print(a+"属于验证码");
}
else
System.out.print(a+"不属于验证码");
}
}
对软件学院2020级同学学号进行校验,学号共八位,规则如下:
要求如下:
class Main {
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
String a;
a=input.next();
String regex = "2020(1[1-7])|(7[1-3])|(8[1,2])(0[1-9])|([1-3][0-9])|(40)";
if(a.matches(regex))
{
System.out.print("正确");
}
else
System.out.print("错误");
}
}
每一行输入一次业务操作,可以输入多行,最终以字符#终止。具体每种业务操作输入格式如下:
卡号 密码 ATM机编号 金额
(由一个或多个空格分隔),卡号
class Main {
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
String a;
yonghu y1 = new yonghu(10000);
yonghu y2 = new yonghu(10000);
yonghu y3 = new yonghu(10000);
yonghu y4 = new yonghu(10000);
yonghu y5 = new yonghu(10000);
yonghu y6 = new yonghu(10000);
yonghu y7 = new yonghu(10000);
yonghu y8 = new yonghu(10000);
a=input.nextLine();
while(!Objects.equals(a, "#")){
String[] b = a.split("\\s+");
if(b.length==4)
{
if(Objects.equals(b[0], "6217000010041315709") || Objects.equals(b[0], "6217000010041315715") )
{
String regex="0[1-6]";
if(b[2].matches(regex)){
if(Objects.equals(b[1], "88888888"))
{
if(b[2].equals("05") || b[2].equals("06")){
System.out.println("Sorry,cross-bank withdrawal is not supported.");
}
else
{
double s= Double.parseDouble(b[3]);
if(s>=0)
{ if(s<=y1.getA()) {
y1.qv(s);
System.out.println("杨过在中国建设银行的" + b[2] + "号ATM机上取款¥" + String.format("%.2f", s));
System.out.println("当前余额为¥" + String.format("%.2f", y1.getA()));
}
else
System.out.println("Sorry,your account balance is insufficient.");
}
else
{
y1.cun(Math.abs(s));
System.out.println("杨过在中国建设银行的"+b[2]+"号ATM机上存款¥"+String.format("%.2f", Math.abs(s)));
System.out.println("当前余额为¥"+String.format("%.2f", y1.getA()));
}
}
}
else
System.out.println("Sorry,your password is wrong.");
}
else
System.out.println("Sorry,the ATM's id is wrong.");
}
else if(Objects.equals(b[0], "6217000010041315718"))
{
String regex="0[1-6]";
if(b[2].matches(regex)){
if(Objects.equals(b[1], "88888888"))
{
if(b[2].equals("05") || b[2].equals("06")){
System.out.println("Sorry,cross-bank withdrawal is not supported.");
}
else
{
double s= Double.parseDouble(b[3]);
if(s>=0)
{ if(s<=y5.getA()) {
y5.qv(s);
System.out.println("杨过在中国建设银行的" + b[2] + "号ATM机上取款¥" + String.format("%.2f", s));
System.out.println("当前余额为¥" + String.format("%.2f", y5.getA()));
}
else
System.out.println("Sorry,your account balance is insufficient.");
}
else
{
y5.cun(Math.abs(s));
System.out.println("杨过在中国建设银行的"+b[2]+"号ATM机上存款¥"+String.format("%.2f", Math.abs(s)));
System.out.println("当前余额为¥"+String.format("%.2f", y5.getA()));
}
}
}
else
System.out.println("Sorry,your password is wrong.");
}
else
System.out.println("Sorry,the ATM's id is wrong.");
}
else if(Objects.equals(b[0], "66217000010051320007"))
{
String regex="0[1-6]";
if(b[2].matches(regex)){
if(Objects.equals(b[1], "88888888"))
{
if(b[2].equals("05") || b[2].equals("06")){
System.out.println("Sorry,cross-bank withdrawal is not supported.");
}
else
{
double s= Double.parseDouble(b[3]);
if(s>=0)
{ if(s<=y2.getA()) {
y2.qv(s);
System.out.println("郭靖在中国建设银行的" + b[2] + "号ATM机上取款¥" + String.format("%.2f", s));
System.out.println("当前余额为¥" + String.format("%.2f", y2.getA()));
}
else
System.out.println("Sorry,your account balance is insufficient.");
}
else
{
y2.cun(Math.abs(s));
System.out.println("郭靖在中国建设银行的"+b[2]+"号ATM机上存款¥"+String.format("%.2f", Math.abs(s)));
System.out.println("当前余额为¥"+String.format("%.2f", y2.getA()));
}
}
}
else
System.out.println("Sorry,your password is wrong.");
}
else
System.out.println("Sorry,the ATM's id is wrong.");
}
else if(Objects.equals(b[0], "6222081502001312389") )
{
String regex="0[1-6]";
if(b[2].matches(regex)){
if(Objects.equals(b[1], "88888888"))
{
if(b[2].equals("01") || b[2].equals("02")||b[2].equals("03") || b[2].equals("04")){
System.out.println("Sorry,cross-bank withdrawal is not supported.");
}
else
{
double s= Double.parseDouble(b[3]);
if(s>=0)
{ if(s<=y3.getA()) {
y3.qv(s);
System.out.println("张无忌在中国工商银行的" + b[2] + "号ATM机上取款¥" + String.format("%.2f", s));
System.out.println("当前余额为¥" + String.format("%.2f", y3.getA()));
}
else
System.out.println("Sorry,your account balance is insufficient.");
}
else
{
y3.cun(Math.abs(s));
System.out.println("张无忌在中国工商银行的"+b[2]+"号ATM机上存款¥"+String.format("%.2f", Math.abs(s)));
System.out.println("当前余额为¥"+String.format("%.2f", y3.getA()));
}
}
}
else
System.out.println("Sorry,your password is wrong.");
}
else
System.out.println("Sorry,the ATM's id is wrong.");
}
else if(Objects.equals(b[0], "6222081502001312390"))
{
String regex="0[1-6]";
if(b[2].matches(regex)){
if(Objects.equals(b[1], "88888888"))
{
if(b[2].equals("01") || b[2].equals("02")||b[2].equals("03") || b[2].equals("04")){
System.out.println("Sorry,cross-bank withdrawal is not supported.");
}
else
{
double s= Double.parseDouble(b[3]);
if(s>=0)
{ if(s<=y6.getA()) {
y6.qv(s);
System.out.println("张无忌在中国工商银行的" + b[2] + "号ATM机上取款¥" + String.format("%.2f", s));
System.out.println("当前余额为¥" + String.format("%.2f", y6.getA()));
}
else
System.out.println("Sorry,your account balance is insufficient.");
}
else
{
y6.cun(Math.abs(s));
System.out.println("张无忌在中国工商银行的"+b[2]+"号ATM机上存款¥"+String.format("%.2f", Math.abs(s)));
System.out.println("当前余额为¥"+String.format("%.2f", y6.getA()));
}
}
}
else
System.out.println("Sorry,your password is wrong.");
}
else
System.out.println("Sorry,the ATM's id is wrong.");
}
else if(Objects.equals(b[0], "6222081502001312399") || Objects.equals(b[0], "6222081502001312400"))
{
String regex="0[1-6]";
if(b[2].matches(regex)){
if(Objects.equals(b[1], "88888888"))
{
if(b[2].equals("01") || b[2].equals("02")||b[2].equals("03") || b[2].equals("04")){
System.out.println("Sorry,cross-bank withdrawal is not supported.");
}
else
{
double s= Double.parseDouble(b[3]);
if(s>=0)
{ if(s<=y7.getA()) {
y7.qv(s);
System.out.println("张无忌在中国工商银行的" + b[2] + "号ATM机上取款¥" + String.format("%.2f", s));
System.out.println("当前余额为¥" + String.format("%.2f", y7.getA()));
}
else
System.out.println("Sorry,your account balance is insufficient.");
}
else
{
y7.cun(Math.abs(s));
System.out.println("张无忌在中国工商银行的"+b[2]+"号ATM机上存款¥"+String.format("%.2f", Math.abs(s)));
System.out.println("当前余额为¥"+String.format("%.2f", y7.getA()));
}
}
}
else
System.out.println("Sorry,your password is wrong.");
}
else
System.out.println("Sorry,the ATM's id is wrong.");
}
else if(Objects.equals(b[0], "6222081502051320785") )
{
String regex="0[1-6]";
if(b[2].matches(regex)){
if(Objects.equals(b[1], "88888888"))
{
if(b[2].equals("01") || b[2].equals("02")||b[2].equals("03") || b[2].equals("04")){
System.out.println("Sorry,cross-bank withdrawal is not supported.");
}
else
{
double s= Double.parseDouble(b[3]);
if(s>=0)
{ if(s<=y4.getA()) {
y4.qv(s);
System.out.println("韦小宝在中国工商银行的" + b[2] + "号ATM机上取款¥" + String.format("%.2f", s));
System.out.println("当前余额为¥" + String.format("%.2f", y4.getA()));
}
else
System.out.println("Sorry,your account balance is insufficient.");
}
else
{
y4.cun(Math.abs(s));
System.out.println("韦小宝在中国工商银行的"+b[2]+"号ATM机上存款¥"+String.format("%.2f", Math.abs(s)));
System.out.println("当前余额为¥"+String.format("%.2f", y4.getA()));
}
}
}
else
System.out.println("Sorry,your password is wrong.");
}
else
System.out.println("Sorry,the ATM's id is wrong.");
}
else if(Objects.equals(b[0], "6222081502051320786"))
{
String regex="0[1-6]";
if(b[2].matches(regex)){
if(Objects.equals(b[1], "88888888"))
{
if(b[2].equals("01") || b[2].equals("02")||b[2].equals("03") || b[2].equals("04")){
System.out.println("Sorry,cross-bank withdrawal is not supported.");
}
else
{
double s= Double.parseDouble(b[3]);
if(s>=0)
{ if(s<=y8.getA()) {
y8.qv(s);
System.out.println("韦小宝在中国工商银行的" + b[2] + "号ATM机上取款¥" + String.format("%.2f", s));
System.out.println("当前余额为¥" + String.format("%.2f", y8.getA()));
}
else
System.out.println("Sorry,your account balance is insufficient.");
}
else
{
y8.cun(Math.abs(s));
System.out.println("韦小宝在中国工商银行的"+b[2]+"号ATM机上存款¥"+String.format("%.2f", Math.abs(s)));
System.out.println("当前余额为¥"+String.format("%.2f", y8.getA()));
}
}
}
else
System.out.println("Sorry,your password is wrong.");
}
else
System.out.println("Sorry,the ATM's id is wrong.");
}
else
System.out.println("Sorry,this card does not exist.");
}
else if(b.length==1)
{
if(Objects.equals(b[0], "6217000010041315709") || Objects.equals(b[0], "6217000010041315715") )
{
System.out.println("¥"+String.format("%.2f", y1.getA()));
}
else if(Objects.equals(b[0], "6217000010041315718"))
System.out.println("¥"+String.format("%.2f", y5.getA()));
else if(Objects.equals(b[0], "66217000010051320007"))
{
System.out.println("¥"+String.format("%.2f", y2.getA()));
}
else if(Objects.equals(b[0], "6222081502001312389") )
{
System.out.println("¥"+String.format("%.2f", y3.getA()));
}
else if( Objects.equals(b[0], "6222081502001312390"))
System.out.println("¥"+String.format("%.2f", y6.getA()));
else if(Objects.equals(b[0], "6222081502001312399") || Objects.equals(b[0], "6222081502001312400"))
System.out.println("¥"+String.format("%.2f", y7.getA()));
else if(Objects.equals(b[0], "6222081502051320785") )
{
System.out.println("¥"+String.format("%.2f", y4.getA()));
}
else if( Objects.equals(b[0], "6222081502051320786"))
System.out.println("¥"+String.format("%.2f", y8.getA()));
else
System.out.println("Sorry,this card does not exist.");
}
a=input.nextLine();
}
}
}
class yonghu {
double a;
public yonghu(double a){
this.a=a;
}
public double getA(){
return a;
}
public double cun(double b){
a=a+b;
return getA();
}
public double qv(double b){
a=a-b;
return getA();
}
}
题目集06
请编写程序,实现如下功能:读入关于蛟龙号载人潜水器探测数据的多行字符串,从给定的信息找出数字字符,输出每行的数字之和。
提示 若输入为“2012年2月”,则该行的输出为:2014。若干个连续的数字字符作为一个整体,以十进制形式相加。
class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String a;
a = input.nextLine();
while (!Objects.equals(a, "end")) {
String reg = "\\d*[^\\D*]";
Matcher m = Pattern.compile(reg).matcher(a);
double b = 0;
while (m.find()) {
String r = m.group(0);
b += Double.parseDouble(r);
}
System.out.println(String.format("%.0f", b));
a = input.nextLine();
}
}
}
用户输入一组选项和数据,进行与四边形有关的计算。
以下四边形顶点的坐标要求按顺序依次输入,连续输入的两个顶点是相邻顶点,第一个和最后一个输入的顶点相邻。
选项包括:
1:输入四个点坐标,判断是否是四边形、平行四边形,判断结果输出true/false,结果之间以一个英文空格符分隔。
2:输入四个点坐标,判断是否是菱形、矩形、正方形,判断结果输出true/false,结果之间以一个英文空格符分隔。 若四个点坐标无法构成四边形,输出"not a quadrilateral"
3:输入四个点坐标,判断是凹四边形(false)还是凸四边形(true),输出四边形周长、面积,结果之间以一个英文空格符分隔。 若四个点坐标无法构成四边形,输出"not a quadrilateral"
4:输入六个点坐标,前两个点构成一条直线,后四个点构成一个四边形或三角形,输出直线与四边形(也可能是三角形)相交的交点数量。如果交点有两个,再按面积从小到大输出四边形(或三角形)被直线分割成两部分的面积(不换行)。若直线与四边形或三角形的一条边线重合,输出"The line is coincide with one of the lines"。若后四个点不符合四边形或三角形的输入,输出"not a quadrilateral or triangle"。
后四个点构成三角形的情况:假设三角形一条边上两个端点分别是x、y,边线中间有一点z,另一顶点s:
1)符合要求的输入:顶点重复或者z与xy都相邻,如x x y s、x z y s、x y x s、s x y y。此时去除冗余点,保留一个x、一个y。
2) 不符合要求的输入:z 不与xy都相邻,如z x y s、x z s y、x s z y
5:输入五个点坐标,输出第一个是否在后四个点所构成的四边形(限定为凸四边形,不考虑凹四边形)或三角形(判定方法见选项4)的内部(若是四边形输出in the quadrilateral/outof the quadrilateral,若是三角形输出in the triangle/outof the triangle)。如果点在多边形的某条边上,输出"on the triangle或者on the quadrilateral"。若后四个点不符合四边形或三角形,输出"not a quadrilateral or triangle"。
import java.text.DecimalFormat;
import java.util.Scanner;
class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String a = sc.nextLine();
if(!Test(a))
m();
String[] string1 = a.split(":");
if(Double.valueOf(string1[0])==1)
{
String[] string2 = string1[1].split(" ");
if(string2.length!=4){
System.out.println("wrong number of points");
System.exit(0);
}
else
{
String[] string3 = string2[0].split(",");
String[] string4 = string2[1].split(",");
String[] string5 = string2[2].split(",");
String[] string6 = string2[3].split(",");
double q = Double.valueOf(string3[0]);double w = Double.valueOf(string3[1]);
double e = Double.valueOf(string4[0]);double r = Double.valueOf(string4[1]);
double t = Double.valueOf(string5[0]);double y = Double.valueOf(string5[1]);
double u = Double.valueOf(string6[0]);double i = Double.valueOf(string6[1]);
if(q==e&&w==r||q==t&&w==y||q==u&&w==i||e==t&&r==y||e==u&&r==i||t==u&&y==i)
{
System.out.println("points coincide");
}
else if(q==e&&q==t||q==t&&q==u||e==t&&e==u||q==e&&q==u||(w-r)/(q-e)==(w-y)/(q-t)||(w-y)/(q-t)==(w-i)/(q-u)||(r-y)/(e-t)==(r-i)/(e-u)||(w-r)/(q-e)==(w-i)/(q-u)) {
System.out.println("false false");
}
else {
if((w-r)/(q-e)==(y-i)/(t-u)&&(w-i)/(q-u)==(r-y)/(e-t)||q==e&&t==u&&(w-i)/(q-u)==(r-y)/(e-t)||q==u&&e==t&&(w-r)/(q-e)==(y-i)/(t-u))
System.out.println("true true");
else
System.out.println("true false");
}
} }
else if(Double.valueOf(string1[0])==2) {
String[] string2 = string1[1].split(" ");
if(string2.length!=4){
System.out.println("wrong number of points");
System.exit(0); }
else{
String[] string3 = string2[0].split(",");
String[] string4 = string2[1].split(",");
String[] string5 = string2[2].split(",");
String[] string6 = string2[3].split(",");
double q = Double.valueOf(string3[0]);double w = Double.valueOf(string3[1]);
double e = Double.valueOf(string4[0]);double r = Double.valueOf(string4[1]);
double t = Double.valueOf(string5[0]);double y = Double.valueOf(string5[1]);
double u = Double.valueOf(string6[0]);double i = Double.valueOf(string6[1]);
double l1=Math.sqrt((q-t)*(q-t)+(w-y)*(w-y));
double l2=Math.sqrt((e-u)*(e-u)+(r-i)*(r-i));
if(q==e&&w==r||q==t&&w==y||q==u&&w==i||e==t&&r==y||e==u&&r==i||t==u&&y==i||q==e&&q==t||q==t&&q==u||e==t&&e==u||q==e&&q==u||(w-r)/(q-e)==(w-y)/(q-t)||(w-y)/(q-t)==(w-i)/(q-u)||(r-y)/(e-t)==(r-i)/(e-u)||(w-r)/(q-e)==(w-i)/(q-u)) {
System.out.println("not a quadrilateral");
}
else if(l1==l2){
if(((w-y)/(q-t))*((r-i)/(e-u))==-1||q==t&&r==i||w==y&&e==u)
{
System.out.println("true true true");
}
else
System.out.println("false true false");
}
else if(((w-y)/(q-t))*((r-i)/(e-u))==-1||q==t&&r==i||w==y&&e==u)
System.out.println("true false false");
else
System.out.println("false false false");
} }
else if(Double.valueOf(string1[0])==3){
String[] string2 = string1[1].split(" ");
if(string2.length!=4){
System.out.println("wrong number of points");
System.exit(0);
}
else{
String[] string3 = string2[0].split(",");
String[] string4 = string2[1].split(",");
String[] string5 = string2[2].split(",");
String[] string6 = string2[3].split(",");
double q = Float.parseFloat(string3[0]);double w = Float.parseFloat(string3[1]);
double e = Float.parseFloat(string4[0]);double r = Float.parseFloat(string4[1]);
double t = Float.parseFloat(string5[0]);double y = Float.parseFloat(string5[1]);
double u = Float.parseFloat(string6[0]);double i = Float.parseFloat(string6[1]);
double t1 = (u-q)*(r-w)-(i-w)*(e-q);
double t2 = (q-e)*(y-r)-(w-r)*(t-e);
double t3 = (e-t)*(i-y)-(r-y)*(u-t);
double t4 = (t-u)*(w-i)-(y-i)*(q-u);
double l1=Math.sqrt((q-e)*(q-e)+(w-r)*(w-r));
double l2=Math.sqrt((e-t)*(e-t)+(r-y)*(r-y));
double l3=Math.sqrt((t-u)*(t-u)+(y-i)*(y-i));
double l4=Math.sqrt((q-u)*(q-u)+(w-i)*(w-i));
double l5=Math.sqrt((q-t)*(q-t)+(w-y)*(w-y));
double m=(l1+l2+l5)/2;
double s1=Math.sqrt(m*(m-l1)*(m-l2)*(m-l5));
double n=(l3+l4+l5)/2;
double s2=Math.sqrt(n*(n-l3)*(n-l4)*(n-l5));
double l= (l1+l2+l3+l4);
double s= (s1+s2);
if(q==e&&w==r||q==t&&w==y||q==u&&w==i||e==t&&r==y||e==u&&r==i||t==u&&y==i||q==e&&q==t||q==t&&q==u||e==t&&e==u||q==e&&q==u||(w-r)/(q-e)==(w-y)/(q-t)||(w-y)/(q-t)==(w-i)/(q-u)||(r-y)/(e-t)==(r-i)/(e-u)||(w-r)/(q-e)==(w-i)/(q-u)) {
System.out.println("not a quadrilateral");
}
else if(t1*t2*t3*t4<0)
System.out.println("false "+new DecimalFormat("#.0##").format(l)+" "+new DecimalFormat("#.0##").format(s));
else
System.out.println("true "+new DecimalFormat("#.0##").format(l)+" "+new DecimalFormat("#.0##").format(s));
} }
else if(Double.valueOf(string1[0])==4)
{
String[] string2 = string1[1].split(" ");
if(string2.length!=6){
System.out.println("wrong number of points");
System.exit(0);
}
else {
String[] string3 = string2[0].split(",");
String[] string4 = string2[1].split(",");
String[] string5 = string2[2].split(",");
String[] string6 = string2[3].split(",");
String[] string7 = string2[4].split(",");
String[] string8 = string2[5].split(",");
double o = Double.valueOf(string3[0]);double p = Double.valueOf(string3[1]);
double g = Double.valueOf(string4[0]);double h = Double.valueOf(string4[1]);
double q = Double.valueOf(string5[0]);double w = Double.valueOf(string5[1]);
double e = Double.valueOf(string6[0]);double r = Double.valueOf(string6[1]);
double t = Double.valueOf(string7[0]);double y = Double.valueOf(string7[1]);
double u = Double.valueOf(string8[0]);double i = Double.valueOf(string8[1]);
if(o==g&&p==h)
System.out.println("points coincide");
else if(q==e&&w==r&&q==t&&w==y||q==e&&w==r&&q==u&&w==i||q==t&&w==y&&q==u&&w==i||e==t&&r==y&&e==u&&r==i||q==e&&q==t&&q==u||(w-r)/(q-e)==(w-y)/(q-t)&&(w-r)/(q-e)==(w-i)/(q-u))
System.out.println("not a quadrilateral or triangle");
else
System.out.println("The line is coincide with one of the lines");
} }
else if(Double.valueOf(string1[0])==5) {
String[] string2 = string1[1].split(" ");
if(string2.length!=5){
System.out.println("wrong number of points");
System.exit(0);
}
else {
String[] string3 = string2[0].split(",");
String[] string4 = string2[1].split(",");
String[] string5 = string2[2].split(",");
String[] string6 = string2[3].split(",");
String[] string7 = string2[4].split(",");
// ling(string3[0]); ling(string3[1]); ling(string4[0]); ling(string4[1]); ling(string5[0]); ling(string5[1]); ling(string6[0]); ling(string6[1]);
double x = Double.valueOf(string3[0]);double o = Double.valueOf(string3[1]);
double q = Double.valueOf(string4[0]);double w = Double.valueOf(string4[1]);
double e = Double.valueOf(string5[0]);double r = Double.valueOf(string5[1]);
double t = Double.valueOf(string6[0]);double y = Double.valueOf(string6[1]);
double u = Double.valueOf(string7[0]);double i = Double.valueOf(string7[1]);
if(q==e&&w==r&&q==t&&w==y||q==e&&w==r&&q==u&&w==i||q==t&&w==y&&q==u&&w==i||e==t&&r==y&&e==u&&r==i||q==e&&q==t&&q==u||(w-r)/(q-e)==(w-y)/(q-t)&&(w-r)/(q-e)==(w-i)/(q-u)){
System.out.println("not a quadrilateral or triangle");
}
else{
if(q==e&&w==r||q==t&&w==y||q==u&&w==i||e==t&&r==y||e==u&&r==i||t==u&&y==i||(w-r)/(q-e)==(w-y)/(q-t)||(w-y)/(q-t)==(w-i)/(q-u)||(r-y)/(e-t)==(r-i)/(e-u)||(w-r)/(q-e)==(w-i)/(q-u))
System.out.println("in the triangle");
else
System.out.println("in the quadrilateral");
}
} }
else{
m();
} }
public static void m() {
System.out.println("Wrong Format");
System.exit(0);
}
public static boolean Test(String line){
String Str=("[1-5]\\:[\\+|-]?([0]|([1-9]((\\d)?)+))(\\.\\d+)?\\,([+\\-]?([0]|([1-9]((\\d)?)+)))(\\.\\d+)?(\\s([+\\-]?([0]|([1-9]((\\d)?)+)))(\\.\\d+)?\\,([+\\-]?([0]|([1-9]((\\d)?)+)))(\\.\\d+)?)+");
return line.matches(Str);
}
public static boolean l(double x,double y,double z)
{
if(x>y)
{
if(z>y&&z<x)
return true;
else
return false;
}
else
if(z<y&&z>x)
return true;
else
return false;
}
}
编写一个银行业务类BankBusiness,具有以下属性和方法:
(1)公有、静态的属性:银行名称bankName,初始值为“中国银行”。
(2)私有属性:账户名name、密码password、账户余额balance。
(3)银行对用户到来的欢迎(welcome)动作(静态、公有方法),显示“中国银行欢迎您的到来!”,其中“中国银行”自动使用bankName的值。
(4)银行对用户离开的提醒(welcomeNext)动作(静态、公有方法),显示“请收好您的证件和物品,欢迎您下次光临!”
(5)带参数的构造方法,完成开户操作。需要账户名name、密码password信息,同时让账户余额为0。
(6)用户的存款(deposit)操作(公有方法,需要密码和交易额信息),密码不对时无法存款且提示“您的密码错误!”;密码正确、完成用户存款操作后,要提示用户的账户余额,例如“您的余额有1000.0元。”。
(7)用户的取款(withdraw)操作(公有方法,需要密码和交易额信息)。密码不对时无法取款且提示“您的密码错误!”;密码正确但余额不足时提示“您的余额不足!”;密码正确且余额充足时扣除交易额并提示用户的账户余额,例如“请取走钞票,您的余额还有500.0元。”。
编写一个测试类Main,在main方法中,先后执行以下操作:
(1)调用BankBusiness类的welcome()方法。
(2)接收键盘输入的用户名、密码信息作为参数,调用BankBusiness类带参数的构造方法,从而创建一个BankBusiness类的对象account。
(3)调用account的存款方法,输入正确的密码,存入若干元。密码及存款金额从键盘输入。
(4)调用account的取款方法,输入错误的密码,试图取款若干元。密码及取款金额从键盘输入。
(5)调用account的取款方法,输入正确的密码,试图取款若干元(取款金额大于余额)。密码及取款金额从键盘输入。
(6)调用account的取款方法,输入正确的密码,试图取款若干元(取款金额小于余额)。密码及取款金额从键盘输入。
class Main {
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
String a=input.next();
String b=input.next();
BankBusiness account=new BankBusiness(a,b);
account.welcome();
String c=input.next();
double d=input.nextDouble();
account.cun(c,d);
String q=input.next();
double w=input.nextDouble();
account.qv(q,w);
String e=input.next();
double r=input.nextDouble();
account.qv(e,r);
String t=input.next();
double y=input.nextDouble();
account.qv(t,y);
account.welcomeNext();
}
}
class BankBusiness {
String a;
String b;
double m=0;
BankBusiness(String a,String b){
this.a=a;
this.b=b;
}
public void welcome(){
String Bankname="中国银行";
System.out.println(Bankname+"欢迎您的到来!");
}
public void cun(String c,double d){
if(Objects.equals(c, b)){
this.m+=d;
System.out.println("您的余额有"+m+"元。");
}
else{
System.out.println("您的密码错误!");
}
}
public void qv(String c,double d){
if(Objects.equals(c, b)){
if(d<=this.m){
this.m-=d;
System.out.println("请取走钞票,您的余额还有"+m+"元。");
}
else
System.out.println("您的余额不足!");
}
else{
System.out.println("您的密码错误!");
}
}
public void welcomeNext(){
System.out.print("请收好您的证件和物品,欢迎您下次光临!");
}
}