使用循环在java中打印图像/模式
写课堂练习。此类必须使用循环打印出以下内容 图画在main方法中编写代码。 第一张图片: / \\ /// \\\\ ///// \\\\\\ /////// / \\ /// \\\\ ///// \\\\\\ /////// 这是我目前掌握的代码:使用循环在java中打印图像/模式,java,eclipse,loops,Java,Eclipse,Loops,写课堂练习。此类必须使用循环打印出以下内容 图画在main方法中编写代码。 第一张图片: / \\ /// \\\\ ///// \\\\\\ /////// / \\ /// \\\\ ///// \\\\\\ /////// 这是我目前掌握的代码: for(int a=1; a<=7; a=a+2){ for(int i=1; i<=a; i++) System.out.print("/"); System.out.println(
for(int a=1; a<=7; a=a+2){
for(int i=1; i<=a; i++)
System.out.print("/");
System.out.println(" ");
for(int c=0; c<a; c=c+2)
System.out.print("\\\\");
System.out.println(" ");
}
for(inta=1;a试试这个:
for (int j=1 ; j<8 ; j++){
for(int k=0 ; k<j ; k++){
// checking if row number is Even/Odd to print '\' or '/'
System.out.print((j%2 == 0)? "\\" : "/");
}
System.out.println();
}
for(int j=1;j我假设您刚刚开始学习编程,下面是您的代码:
public class LoopPractice {
public static void main(String[] args) {
for(int counter = 0; counter<7; counter++){
for(int times=0;times<=counter;times++){
if(counter%2==0){
System.out.print("/");
}else{
System.out.print("\\");
}
}
System.out.println();
}
}
}
公共课堂实践{
公共静态void main(字符串[]args){
对于(int计数器=0;计数器