请问各位前辈们这个程序怎么做? 很简单的,就是搞不懂
就是输出这个阵型
*
* *
* * *
* * * *
当然我知道是for循环 具体怎么循环 请大家告诉我具体的代码吧,辛苦了
注意这不是左对齐。。。。
for循环的java程序
答案:6 悬赏:0 手机版
解决时间 2021-03-09 12:11
- 提问者网友:锁深秋
- 2021-03-08 21:59
最佳答案
- 五星知识达人网友:低血压的长颈鹿
- 2021-03-08 23:00
你想要啥样的形状的,自己挑一个,都是回答问题写的。都可以执行。
public class Pyramid {
public static void main(String[] args) {
// TODO Auto-generated method stub
show(9);
mm(9);
sjx(9);
sjx2(9);
sjx3(9);
doubleSjx(9);
}
public static void doubleSjx(int n){
for(int i=0; i<(n+1)/2; i++){
for(int j=0; j System.out.print(" ");
}
for(int j=n-2*i; j>0;j--){
System.out.print("*");
}
System.out.println();
}
int i2 = 1;
for(int i=(n+1)/2; i
for(int j=n-1-i; j>0;j--){
System.out.print(" ");
}
for(int j=0; j<2*i2+1;j++){
System.out.print("*");
}
System.out.println();
i2++;
}
}
public static void sjx(int n){
for(int i=0; i
for(int j=0; j
System.out.print(" ");
}
for(int j=n; j>i; j--){
System.out.print("*");
}
System.out.println();
}
}
public static void sjx2(int n){
for(int i=0; i
for(int j=n-1; j>i;j--){
System.out.print(" ");
}
for(int j=0; j<=i; j++){
System.out.print("*");
}
System.out.println();
}
}
public static void sjx3(int n){
for(int i=0; i
for(int j=0; j
System.out.print(" ");
j+=2;
}
for(int j=n; j>i;j--){
System.out.print("*");
}
System.out.println();
i+=2;
}
}
public static void show(int n) {
for (int i = 1; i <= n; i++) {
for (int j = 0; j < Math.abs(i - n); j++) {
System.out.print(" ");
}
for (int j = i; j >= 1; j--) {
System.out.print(j);
}
for (int j = 2; j <= i; j++) {
System.out.print(j);
}
System.out.println();
}
}
public static void show2(int n){
int[][] result = new int[n][2*n-1];
for(int i=0; i
for(int j=0; j
result[i][j] = 0;
}
}
}
public static void mm(int x) {
for (int nHight = 1; nHight <= x; nHight++) {
for (int i = nHight - x; i < nHight; i++)
print(i);
for (int i = nHight; i > 0; i--)
print(i);
System.out.println("");
}
}
public static void print(int i) {
if (i < 1)
System.out.print(" ");
else
System.out.print(i);
}
}
public class Pyramid {
public static void main(String[] args) {
// TODO Auto-generated method stub
show(9);
mm(9);
sjx(9);
sjx2(9);
sjx3(9);
doubleSjx(9);
}
public static void doubleSjx(int n){
for(int i=0; i<(n+1)/2; i++){
for(int j=0; j System.out.print(" ");
}
for(int j=n-2*i; j>0;j--){
System.out.print("*");
}
System.out.println();
}
int i2 = 1;
for(int i=(n+1)/2; i
System.out.print(" ");
}
for(int j=0; j<2*i2+1;j++){
System.out.print("*");
}
System.out.println();
i2++;
}
}
public static void sjx(int n){
for(int i=0; i
}
for(int j=n; j>i; j--){
System.out.print("*");
}
System.out.println();
}
}
public static void sjx2(int n){
for(int i=0; i
System.out.print(" ");
}
for(int j=0; j<=i; j++){
System.out.print("*");
}
System.out.println();
}
}
public static void sjx3(int n){
for(int i=0; i
j+=2;
}
for(int j=n; j>i;j--){
System.out.print("*");
}
System.out.println();
i+=2;
}
}
public static void show(int n) {
for (int i = 1; i <= n; i++) {
for (int j = 0; j < Math.abs(i - n); j++) {
System.out.print(" ");
}
for (int j = i; j >= 1; j--) {
System.out.print(j);
}
for (int j = 2; j <= i; j++) {
System.out.print(j);
}
System.out.println();
}
}
public static void show2(int n){
int[][] result = new int[n][2*n-1];
for(int i=0; i
}
}
}
public static void mm(int x) {
for (int nHight = 1; nHight <= x; nHight++) {
for (int i = nHight - x; i < nHight; i++)
print(i);
for (int i = nHight; i > 0; i--)
print(i);
System.out.println("");
}
}
public static void print(int i) {
if (i < 1)
System.out.print(" ");
else
System.out.print(i);
}
}
全部回答
- 1楼网友:酒者煙囻
- 2021-03-09 02:35
public class Test {
public static void main(String[] args) {
for(int i=0;i<5;i++){
for(int j=0;j
- 2楼网友:神鬼未生
- 2021-03-09 02:19
public class TextS{
public static void main(String args[]){
int i = 1;
for(i=1; i < 30; i++ ){
for(int h = 30 ; h > i ; h--){
System.out.print(" ");
}
for(int k = 0 ; k < i ; k++){
System.out.print("* ");
}
System.out.println(" ");
}
}
}
- 3楼网友:第四晚心情
- 2021-03-09 02:07
public static void main(string[] args)
{
int i = 0;
//加一个 scanner 让程序可以识别input。
scanner sc = new scanner(system.in);
do{
system.out.println("please enter a word(case sensitive).");
string letter1 = sc.next();
system.out.println("please enter another word(case sensitive).");
string letter2 = sc.next();
if(letter1.compareto(letter2) == 0)
{
system.out.println("they are same");
}
else
{
system.out.println("they are different");
}
system.out.println("please enter 0 to continue the compare.");
i = sc.nextint();
}while(i==0);
sc.close();
}
- 4楼网友:想偏头吻你
- 2021-03-09 01:24
public class Test {
public static void main(String[] args) {
// TODO Auto-generated method stub
for(int i=0;i<5;i++){
for(int j=0;j
- 5楼网友:想偏头吻你
- 2021-03-09 00:40
刚好有一个以前编好的,送给你了!
import java.io.*;
public class Test1
{
public static void main(String[] args)throws IOException
{
BufferedReader buf=new BufferedReader(new InputStreamReader(System.in));
String str;
System.out.println("请输入要打印的层数:");
str=buf.readLine();
int lay=Integer.parseInt(str);
for (int i=1;i<=lay;i++)
{
for (int k=1;k<=lay-i;k++)
{
System.out.print(" ");//输出一个空格
}
for (int j=1;j<=(i-1)*2+1;j++)
{
System.out.print("*");
}
System.out.println();
}
}
}
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯