我的面向对象

洗牌算法

package hello;

import java.util.Random;
import java.util.Scanner;

class xipai {
	String k[] = { "红桃A", "红桃2", "红桃3", "红桃4", "红桃5", "红桃6", "红桃7", "红桃8", "红桃9", "红桃10", "红桃J", "红桃Q", "红桃K; \n黑桃A",
			"黑桃2", "黑桃3", "黑桃4", "黑桃5", "黑桃6", "黑桃7", "黑桃8", "黑桃9", "黑桃10", "黑桃J", "黑桃Q", "黑桃K; \n梅花A", "梅花2", "梅花3",
			"梅花4", "梅花5", "梅花6", "梅花7", "梅花8", "梅花9", "梅花10", "梅花J", "梅花Q", "梅花K; \n方片A", "方片2", "方片3", "方片4", "方片5",
			"方片6", "方片7", "方片8", "方片9", "方片10", "方片J", "方片Q", "方片K", "大王", "小王" };

	void xipi() {
		for (int i = 0; i < 1000; i++) {
			Random r = new Random();
			int x = r.nextInt(51);
			int y = r.nextInt(51);
			String w;
			w = k[x];
			k[x] = k[y];
			k[y] = w;
		}
		for(int i=0;i<k.length;i++)
			System.out.print(k[i] + ' ');
	}

}

public class hello {
	public static void main(String[] args) {
		xipai x = new xipai();
		x.xipi();
	}
}
package hello;

import java.util.Random;
import java.util.Scanner;

class MathUtil {


	
  void showme  () {int n=0;
		Random random = new Random();
		int rand = 0;// 存储随机数
		int x = random.nextInt(10);
		int y = random.nextInt(10);
		int[][] arrays = new int[x][y];// 声明二维数组
// 给数组赋值
		for (int i = 0; i <x; i++) {
			for (int j = 0; j < y; j++) {
				rand = random.nextInt(10);// 在0-10内随机生成一个正整数
				arrays[i][j] = rand;
			}
		}
		

		for (int i = 0; i < x; i++) {
			for (int j = 0; j < y; j++) {
				n+=arrays[i][j];
				System.out.print(' '+arrays[i][j]);	
				
			}
        	System.out.println();
		}
	System.out.print(n);
	}
	
	
	
}

public class hello {
	public static void main(String[] args) {
MathUtil m=new MathUtil();

m.showme();
	}
}

在这里插入图片描述``

package hello;

import java.util.regex.*;

class zhengze {
	String c = "int x,y11,z=1+2*xL+0x5L+姓名+a姓名;";
	String x = "王五 010-65151234 手机 13812345678 张三 手机号 13177118811,买了138671456件商品,李四 电话 0791-88120410 有1566789件商品";
	String d="2001.1.1 2112334.2334.21";
	void cfen() {

		String[] r = c.split(" |\\+|\\*|\\-|\\%|,|;|=");

		for (String item : r) {
			System.out.print(item + ' ');
		}

	}

	void cshi() {
		Pattern p = Pattern.compile("[a-zA-Z_](\\w)*");
		Matcher k = p.matcher(c);
		if (k.find())
			System.out.println("yes");
		else {
			System.out.println("no");
		}
	}

	void shaoma() {

		Pattern p = Pattern.compile("(13[0-9]|14[579]|15[0-35-9]|17[0-35-8]|18[0-9]){1}\\d{8}");
		Matcher k = p.matcher(x);
		while (k.find()) {
			System.out.println("手机号码: " + k.group());

		}
	}

	void dhaoma() {
		Pattern a = Pattern.compile("0\\d{2,3}[-]?\\d{7,8}|0\\d{2,3}\\s?\\d{7,8}");
		Matcher z = a.matcher(x);
		while (z.find()) {
			System.out.println("电话号码: " + z.group());

		}
	}

void day()
{Pattern a = Pattern.compile("\\d{1,4}\\.\\d{1,2}\\.\\d{1,2}");
Matcher z = a.matcher(d);
while (z.find()) {
	System.out.println("合法日子: " + z.group());
	}
}
}
public class hello {
	public static void main(String[] args) {
		zhengze z = new zhengze();
		z.cfen();
		z.cshi();
		z.shaoma();
		z.dhaoma();
		z.day();
	}
}

在这里插入图片描述

package hello;

import java.lang.Math;
import java.util.Scanner;

class Triangle {
	private double a, b, c;

	void debian() {
		Scanner s = new Scanner(System.in);
		a = s.nextDouble();
		c = b = a;
	}

	void deyao() {
		Scanner s = new Scanner(System.in);
		a = s.nextDouble();
		b = s.nextDouble();
if(2*b<a)c=a;
else c=b;
	}

	void putri() {
		Scanner s = new Scanner(System.in);
		a = s.nextDouble();
		b = s.nextDouble();
		c = s.nextDouble();
	}

	double geta() {
		return a;
	}

	double getb() {
		return b;
	}

	double getc() {
		return c;
	}
	
	void show()
	{System.out.println("普通三角形:a="+a+"b="+b+"c="+c);
		
	}
	
}

class zhijiao extends Triangle {
	double a, b, c;

	public zhijiao() {
		System.out.print("请输入:");
	}

	void towzhi() {

		this.deyao();

		a = this.geta();
		b = this.getb();
		c = Math.sqrt(a * a + b * b);
		if (a + b <= c || b + c <= a || a + c <= b) {
			a = 3;
			b = 4;
			c = 5;
		}

	}

	void thzhi() {
		this.putri();
		a = this.geta();
		b = this.getb();
		c = this.getc();
		if (a * a + b * b != c * c || b * b + c * c != a * a || a * a + c * c != b * b) {
			a = 3;
			b = 4;
			c = 5;

		}

	}
	void show()
	{System.out.println("直角三角形:a="+a+"b="+b+"c="+c);
		
	}

}

public class hello {
	public static void main(String[] args) {
		Triangle t1=new Triangle();
		zhijiao z1=new zhijiao();
		t1.debian();
		t1.show();
		t1.deyao();
		t1.show();
		t1.putri();
		t1.show();
		z1.towzhi();
		z1.show();
	}
}

package hello;

import java.lang.Math;
import java.util.Scanner;

class Triangle {
	private double a, b, c;
	private static final int total = 5;
	private static int count = 0;

	private Triangle(double x) {
		a = x;
		b = x;
		c = x;
		count++;
	}

	private Triangle(double x, double y) {
		a = x;
		b = x;
		c = y;
		count++;
	}

	private Triangle(double x, double y, double z) {
		a = x;
		b = y;
		c = z;
		count++;
	}

	private static boolean limit(double x, double y, double z) {
		return (x > 0 && y > 0 && z > 0 && x + y > z && x + z > y && y + z > x && count < total);
	}

	public static Triangle creat(double x) {
		if (limit(x, x, x)) {

			return new Triangle(x);
		} else {
			return null;
		}
	}

	public static Triangle creat(double x, double y) {
		if (limit(x, x, y)) {

			return new Triangle(x, y);
		}

		else if (limit(x, y, y)) {
			return new Triangle(y, x);

		} else {
			return null;
		}
	}

	public static Triangle creat(double x, double y, double z) {
		if (limit(x, y, z)) {

			return new Triangle(x, y, z);
		}
		return null;
	}
}
public  class hello {
	public static void main(String[] args) {
		Triangle[] t=new Triangle[10];
        t[0]=Triangle.creat(0);
        t[1]=Triangle.creat(1);
        t[2]=Triangle.creat(1,2);
        t[3]=Triangle.creat(-1,2,3);
        t[4]=Triangle.creat(2,2,3);
        t[5]=Triangle.creat(2,2,3);
        t[6]=Triangle.creat(2,2,3);
        for(Triangle x:t){
            System.out.println(x);
        }
	}
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值