高博实训第三天作业
来源:互联网 发布:sql文件 执行 oracle 编辑:程序博客网 时间:2024/06/03 13:15
public class PrintRect {
public static void main(String[] args) {
PrintOutRectangle();
System.out.println();
FilledRectangle();
}
/**
* 打印空心矩形
*/
public static void PrintOutRectangle() {
for (int i = 1; i <= 5; i++) {
if (i == 1 || i == 5) {
System.out.println("**********");
} else {
System.out.println("* *");
}
}
}
/**
* 打印实心矩形
*/
public static void FilledRectangle() {
for (int i = 1; i <= 5; i++) {
System.out.println("##########");
}
}
}
2.package com.geminno.homework3;
/**
*
* @author Song
*
*/
public class PrintFilledTriangle {
public static void main(String[] args) {
//实心上三角形(左)
FilledUpperLeftTriangle();
//实心上三角形(右)
FilledUpperRightTriangle();
//实心下三角形(左)
FilledLowerLeftTriangle();
//实心下三角形(右)
FilledLowerRightTriangle();
}
/**
* 打印实心上三角(左)
*/
public static void FilledUpperLeftTriangle() {
for (int i = 1; i <= 10; i++) {
for (int j = i; j <= 10; j++) {
System.out.print("#");
}
System.out.println();
}
}
/**
* 打印实心上三角(右)
*/
public static void FilledUpperRightTriangle() {
for(int i=1;i<=10;i++){
for(int j=1;j<i;j++){
System.out.print(" ");
}
for(int k=10;k>=i;k--){
System.out.print("#");
}
System.out.println();
}
}
/**
* 打印实心下三角(左)
*/
public static void FilledLowerLeftTriangle() {
for(int i=1;i<=10;i++){
for(int j=1;j<=i;j++){
System.out.print("#");
}
System.out.println();
}
}
/**
* 打印实心下三角(右)
*/
public static void FilledLowerRightTriangle() {
for(int i=1;i<=10;i++){
for(int j=i;j<10;j++){
System.out.print(" ");
}
for(int k=1;k<=i;k++){
System.out.print("#");
}
System.out.println();
}
}
}
3.package com.geminno.homework3;
public class PrintHollowTriangle {
public static void main(String[] args) {
//打印空心上三角形
HollowLeftUpperTrianle();
//打印空心左上三角形
HollowRightUpperTrianle();
// 打印空心左下三角形
HollowLeftLowerTrianle();
// 打印空心左下三角形
HollowRightLowerTrianle();
}
/**
* 打印空心左上三角形
*/
public static void HollowLeftUpperTrianle(){
for (int i=1;i<=10;i++){
for(int j=1;j<=10;j++) {
if(i==1||j==1||j==(10-i+1)) {
System.out.print("#");
}else{
System.out.print(" ");
}
}
System.out.println();
}
}
/**
* 打印空心右上三角形
*/
public static void HollowRightUpperTrianle(){
for (int i=1;i<=10;i++){
for(int j=1;j<=10;j++) {
if(i==1||j==10||j==i) {
System.out.print("#");
}else{
System.out.print(" ");
}
}
System.out.println();
}
}
/**
* 打印空心左下三角形
*/
public static void HollowLeftLowerTrianle(){
for (int i=1;i<=10;i++){
for(int j=1;j<=i;j++) {
if(i==10||j==1||j==i) {
System.out.print("#");
}else{
System.out.print(" ");
}
}
System.out.println();
}
}
/**
* 打印空心右下三角形
*/
public static void HollowRightLowerTrianle(){
for (int i=1;i<=10;i++){
for(int j=1;j<=10;j++) {
if(i==10||j==10||j==10-i+1) {
System.out.print("#");
}else{
System.out.print(" ");
}
}
System.out.println();
}
}
}
4.package com.geminno.homework3;
/**
*
* @author Song
*
*/
public class PrintRhombus {
public static void main(String[] args) {
//打印空心菱形
PrintHollowRhombus();
//打印实心菱形
// PrintFilledRhombus();
}
/**
* 打印空心菱形
*/
public static void PrintHollowRhombus(){
for (int i=1;i<=11;i++) { //上半部分
for (int j=i;j<11;j++) {
System.out.print(" ");
}
for (int k=1;k<=2*i-1;k++) {
if(k==1||k==2*i-1){
System.out.print("#");
}
else{
System.out.print(" ");
}
}
System.out.println();
}
for (int i=10;i>=1;i--) { //下半部分
for (int j=1;j<=11-i;j++) {
System.out.print(" ");
}
for (int k=2*i-1;k>0;k--) {
if(k==1||k==2*i-1){
System.out.print("#");
}else{
System.out.print(" ");
}
}
System.out.println();
}
}
/**
* 打印实心菱形
*/
public static void PrintFilledRhombus(){
for (int i=1;i<=11;i++) { //上半部分
for (int j=i;j<11;j++) {
System.out.print(" ");
}
for (int k=1;k<=2*i-1;k++) {
System.out.print("#");
}
System.out.println();
}
for (int i=10;i>=1;i--) { //下半部分
for (int j=1;j<=11-i;j++) {
System.out.print(" ");
}
for (int k=2*i-1;k>0;k--) {
System.out.print("#");
}
System.out.println();
}
}
}
5.package com.geminno.homework3;
/**
* 1!+2!+3!+.....+10!
* @author Song
*
*/
public class Factorial {
public static void main(String[] args) {
long sum=0;
for(int i=1;i<=10;i++){
sum=sum+FunFactorial(i);
}
System.out.println(sum);
}
public static long FunFactorial(int m){
if(m==0||m==1){
return 1;
}else{
return FunFactorial(m-1)*m;
}
}
}
6.package com.geminno.homework3;
/**
*
* @author Song
*
*/
public class LCMOrGCD {
public static void main(String[] args) {
System.out.println("最小公倍数数是:"+LCM(3,5));
System.out.println("最大公约数是:"+GCD(3,5));
}
//最小公倍数
public static int LCM(int m,int n){
int k=m*n/GCD(m,n);
return k;
}
//最大公约数
public static int GCD(int m,int n){
while(m%n!=0){
int temp=n%m;
n=m;
m=temp;
}
return n;
}
}
- 高博实训第三天作业
- Ruby第三天作业
- Prolog第三天作业
- Scala第三天作业
- 训练营第三天作业
- Python第三天课后作业
- 码神第三天学习(加作业)
- Java Language:-第三天-2-Java作业-12/10/2014
- c++ 学习之路 第三天 作业理解
- 程序设计方法学作业—三天打渔两天晒网程序设计
- 三天
- 作业
- 作业
- 作业
- 作业
- 作业
- 作业
- 作业
- USACO-Section2.1 Healthy Holsteins [搜索][枚举]
- 最后剩下的一张骨牌的编号
- Failed to start firewalld.service: Unit firewalld.service is masked
- 论文格式中的几个要点
- 如何使用自己不了解的计算机语言去实现自己想要的功能呢?
- 高博实训第三天作业
- anaconda安装tensorflow
- centos7之zabbix入门(一)
- 1030. Travel Plan (30)
- 喷水装置(一)
- USACO-Section1.4 Mother's Milk
- Android Binder机制
- [编程珠玑]-第二章:二分及标识
- MVP 模式在Android中的应用