① java列印圖形
雙層for循環就夠了 我剛開始寫循環的時候用*花寫過自己的名字,主要看你的會不會圖形拆分
println(「* * **** * * ** 」)
println(「* * * * * * * 」)
println(「**** **** * * * * 」)
println(「* * * * * * * 」)
println(「* * **** **** ***** ** 」)
最簡單的辦法
② java 編寫程序列印下面的圖案
publicclass${
publicstaticvoidmain(String[]args){
intsize=5;
for(inti=0;i<size;i++){
//空格
for(intj=0;j<size-i-1;j++){
System.out.print("");
}
//星號
for(intj=0;j<=i;j++){
System.out.print("*");
}
System.out.println();
}
}
}
③ 這個圖案用Java怎麼列印出來
可以的。
④ 用Java編寫列印下列圖形的程序
假設只要列印第一行的*號,那麼肯定是一個循環搞定;而如果要列印一個矩形,那麼肯定是兩層循環,外層循環控制行數,內層循環控制列數,現在問題的關鍵是,從第二行開始,每行都比前一行少兩列*號,所以第二層循環的上限是動態的,而且跟行數有關,假設當前是第i行(i從0開始),那麼第i行就會有7-2*i個星號,也就是內層循環的上限。此時輸出的應該是直角三角形,接下來再考慮將直角三角形改成等邊的,此時只需要在每一行的前面輸出一定的空格就可以了,如果上面我說的你看懂了,空格應該能自己加出來了。
⑤ Java編程:編寫程序列印下列圖案
class For
{
public static void main(String[] args)
{
for(int i=4;i>0;i--)
{
//左邊空格
for(int j=1;j<=7-i;j++)
System.out.print(" ");
//空格後面的*
for(int s=1;s<=i*2-1;s++)
System.out.print("*");
//回車
System.out.println();
}
for(int i=2;i<=4;i++)
{
for(int j=1;j<=7-i;j++)
System.out.print(" ");
for(int s=1;s<=i*2-1;s++)
System.out.print("*");
System.out.println();
}
}
}
第二種方法 不過 這個空格沒弄 你可以自己加上
class For
{
public static void main(String[] args)
{
for(int x=7;x>0;x--)
{
if(x%2==1)
{
for(int y=0;y<x;y++)
{
System.out.print("*");
}
System.out.println();
}
}
for(int x=3;x<9;x++)
{
if(x%2==1)
{
for(int y=0;y<x;y++)
{
System.out.print("*");
}
System.out.println();
}
}
⑥ java列印星星圖案的
public class Test4 {
public static void main(String[] args) {
for(int i=1;i<=9;i++){
if(i<=5){
for(int j=1;j<=i*2-1;j++){
System.out.print("*");
}
}
if(i>5&&i<=9){
for(int j=9;j>=(i-5)*2+1;j--)
System.out.print("*");
}
System.out .println();
}
}
}
⑦ 用JAVA程序列印如下圖案
用個for循環就是了
public class test
{
public static void main(String [] args){
for(int i=1;i<=5;i++){
for(int j=1;j<=i;j++)
System.out.print(j);
for(int j=i-1;j>0;j--)
System.out.print(j);
System.out.println();
}
}
}
測試過了 可用
⑧ java for循環 輸出以下圖案並列印出 急!在線等!
Problem Description
通過使用雙重for循環語句,列印下列圖形:
nput
Output
Example Input
Example Output
*
***
*****
*******
*****
***
*
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner reader=new Scanner(System.in);
int i,j,k;
for(i=1;i<=4;i++)
{
for(k=1;k<=4-i;k++)
{
System.out.printf(" ");
}
for(j=1;j<=2*i-1;j++)
{
System.out.printf("*");
}
System.out.println();
}
for(i=3;i>=1;i--)
{
for(k=1;k<=4-i;k++)
{
System.out.printf(" ");
}
for(j=1;j<=2*i-1;j++)
{
System.out.printf("*");
}
System.out.println();
}
}
}
⑨ java編程列印如下圖案
public class Test2 {
public static void main(String[] args) {
int n = 7;
int space = 0;
int star = n;
while(space < n / 2){
print(" ", space++);
print("*", star);
System.out.println();
star = star - 2;
}
while(space >= 0){
print(" ", space--);
print("*", star);
System.out.println();
star += 2;
}
}
private static void print(String string, int space) {
for(int i = 1; i <= space; i++){
System.out.print(string);
}
}
}
----------testing
*******
*****
***
*
***
*****
*******
⑩ 用java列印出這樣的圖案
public static void main(String[] args) {
int n = 5;//循環次數
for (int i = 1; i <= n; i++) {
for (int j = 0; j < i; j++) {
System.out.print("*");
for (int k = 0; k < i; k++) {
System.out.print(".");
}
}
System.out.println();
}
}