package com.tgb.test;
public class SpringTest
{
/**
* 正三角
*
* @param a
*/
public static void zsj(int a)
{
int m = 2 * a;
for (int i = 0; i < a; i++) {
for (int j = 0; j < m - 1; j++) {
int x = (m - 2 * i + 1) / 2 - 1;
int y = (m - 2 * i + 1) / 2 + 2 * i;
if (j >= x & j < y) {
System.out.print(" * ");
}
else {
System.out.print(" - ");
}
}
System.out.println();
}
};
/**
* 倒三角
*
* @param a
*/
public static void dsj(int a)
{
int m = 2 * a - 1;
for (int i = 0; i < a; i++) {
for (int j = 0; j < m; j++) {
int y = m - i;
if (j > i - 1 & j < y) {
System.out.print(" * ");
}
else {
System.out.print(" ");
}
}
System.out.println();
}
};
/**
* 乘法表
*
*/
public static void cfb()
{
for (int i = 1; i < 10; i++) {
for (int j = 1; j < i + 1; j++) {
System.out.print(j + "*" + i + "=" + i * j + " ");
}
System.out.println();
}
}
/**
* 递归算阶乘
*
* @param b
* @return
*/
public static int jc(int b)
{
if (b == 1) {
return 1;
}
else {
return b * jc(b - 1);
}
}
/**
* 累加
*
* @param b
* @return
*/
public static int jf(int b)
{
if (b == 0) {
return 0;
}
else {
return b + jf(b - 1);
}
}
/**
* 升序排列
*
* @param a
* @return
*/
public static int[] px(int[] a)
{
for (int i = 0; i < a.length - 1; i++) {
if (a[i] > a[i + 1]) {
a[i] = a[i + 1] + a[i];
a[i + 1] = a[i] - a[i + 1];
a[i] = a[i] - a[i + 1];
}
}
return a;
}
/**
* 查找算法
*
* @param a
* @return
*/
public static String cz(int a)
{
String str = "没有找到";
int[] b = { 1, 2, 3, 4, 5, 6, 7 };
int min = 0;
int max = b.length - 1;
int mid = (min + max) / 2;
for (; 0 <= mid && mid <= b.length - 1;) {
if (b[mid] < a) {
min = mid;
}
else if (b[mid] > a) {
max = mid;
}
else {
str = "已找到";
break;
}
mid = (min + max) / 2;
}
return str;
}
public static void main(String[] args)
{
dsj(5);
zsj(5);
cfb();
System.out.println(jf(3));
int[] b = { 1, 2, 3, 5, 7, 8 };
int[] c = px(b);
for (int j = 0; j < c.length - 1; j++) {
System.out.println(c[j]);
}
System.out.println(cz(3));
}
}
java的简单数据方面运用
最新推荐文章于 2022-08-30 11:31:20 发布