菜鸟柳基础经典案例--金字塔形输出打印
来源:互联网 发布:全球主权财富基金 知乎 编辑:程序博客网 时间:2024/06/05 10:47
/需求:根据用户指定的数字–金字塔层数,输出他想要的1–正金字塔,2–倒金字塔模型/
package 经典算法案例;
import java.util.Scanner;
public class JinZiTa {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println(“请输入金字塔层数”);
int count = sc.nextInt();
System.out.println(“请输入编号选择金字塔形状1–金字塔,2–倒金字塔:”);
int model = sc.nextInt();
switch (model) {
case 1:
function_1(count);
break;
case 2:
function_2(count);
break;
default:
System.out.println(“你个傻逼看不懂中国字么,只能输入1和2”);
break;
}
sc.close();
}
// 金字塔public static void function_1(int count) { for (int i = 0; i < count; i++) { for (int space = 0; space < (count - i - 1); space++) { System.out.print(" "); } for (int star = count - i; star < (count + i + 1); star++) { System.out.print("☆"); } System.out.println(); }}public static void function_2(int count) { for (int i = 0; i < count; i++) { for (int space = 0; space < i; space++) { System.out.print(" "); } for (int star = i; star < (count * 2 - i - 1); star++) { System.out.print("☆"); } System.out.println(); }}
}
0 0
- 菜鸟柳基础经典案例--金字塔形输出打印
- 打印金字塔
- 金字塔打印
- 打印金字塔
- 打印*金字塔
- 打印: 金字塔
- 打印金字塔
- 打印金字塔
- 打印金字塔
- 杨辉三角的金字塔数字打印输出
- 使用C程序打印输出等腰三角形(或者是金字塔)
- 输出金字塔
- 输出金字塔:*,***,*****,*******,*********
- 输出金字塔
- 小M开发_java零基础(字母金字塔案例)
- C++打印数字金字塔
- 打印金字塔代码
- 打印出金字塔形状
- 菜鸟柳(二维数组练习)--根据用户输入的数字输出如下格式:等长、数字从1递增1的螺旋二维数组的
- 函数spl_autoload_register()用法
- Android onTouch事件解析
- Eclipse快捷键
- Memcache的使用和协议分析详解
- 菜鸟柳基础经典案例--金字塔形输出打印
- 4.15初上 Linux
- IO:字节流截取音乐
- GIT的安装和使用简介
- Eclipse创建新的server
- 用PHP实现一个关于德州扑克算法的程序(三):顺子
- KMP
- 摆动排序
- KMP