dimanche 27 décembre 2020

How to print 4 pattern in horizontal way? [closed]

Photo I'm new in learning programming and I just learned about looping.This is my code but it keep print vertically. How to make the output just like in the photo? I try to display the output in horizontal way I have tried \t but it did not came out as expected. I think I need to add something but I don't know what.

package question3;
import java.util.Scanner;
public class Question3 {
public static void main(String[] args) {
int i,j,num,k;  
Scanner sc=new Scanner(System.in);
System.out.println("Enter an integer number line");
int line=sc.nextInt();
System.out.println("Pattern I");
for(i=0; i<line; i++)
{
   num=1; 
   for(j=0; j<=i; j++) {
   System.out.print(num);
   num++; }
   System.out.println() }
   System.out.println("Pattern II");
   for(i=line; i>0; i--){
   num=1;
   for(j=0; j<i; j++)
   {
   System.out.print(num);
   num++;
    }
   System.out.println();
   }
  System.out.println("Pattern III");
  for(i=0; i<line; i++){
   for(k=line-1;k>i;k--) {
     System.out.print(" ");}
  num=i+1;
    for(j=0; j<=i; j++){
     System.out.print(num);
     num--;}
     System.out.println();}
   System.out.println("Pattern IV");
  for(i=line; i>0; i--){
 num=1;
  for(k=line;k>i;k--)
   {
  System.out.print(" ");
 }
  for(j=0; j<i; j++)
  {
  System.out.print(num);
   num++;
  }

   System.out.println();}}}  

Aucun commentaire:

Enregistrer un commentaire