🔒 Closed How to print diagonal string

Status
Not open for further replies.

Penpenqt69

Journeyman
Code:
    public static void main(String[] args) {
       int x = 0,y = 0;
       Scanner enter = new Scanner(System.in);
        System.out.println("String: ");   
        String alpha;
      
         alpha = enter.nextLine();         
                 for (x = 1; x <alpha.length(); x++)
        {
            for (y = 1; y <= x; y++)
            {
                if(x>=2 && y<=x-1){
                    System.out.print("@");
                }
                else
                System.out.print(alpha.charAt(x)+" ");
            }
            System.out.println();
        }         
    }
}




Paano po ito ayusin? dapat po mag uumpisa sya sa "P" pero nag uumpisa sya sa "a" dapat po yung out put is ganito: "
p
@a
@@n
@@@g
@@@@a
@@@@@s
@@@@@@i
@@@@@@@n
@@@@@@@@a
@@@@@@@@@n"


pero ang lumalabas ganito: "
a
@n
@@g
@@@a
@@@@s
@@@@@i
@@@@@@n
@@@@@@@a
@@@@@@@@n "

please help me po Thankyou!!
 
Aahh nvm sir. nakuha ko na yung output na gusto ko. kelangan ko lang pala palitan yung sa IF statement: if(x>=2 && y<=x-1) to if(x>=1 && y<=x-1)
THANK YOU SIR! :>
 
Status
Not open for further replies.

About this Thread

  • 4
    Replies
  • 345
    Views
  • 2
    Participants
Last reply from:
Flavored

Trending Topics

Online now

Members online
999
Guests online
1,866
Total visitors
2,865

Forum statistics

Threads
2,290,749
Posts
29,066,463
Members
1,211,518
Latest member
jemelanie
Back
Top