What's new

Closed How to print diagonal string

Status
Not open for further replies.

Penpenqt69

Addict
Joined
Jul 31, 2018
Posts
36
Reaction
3
Points
83
Age
24
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.

Similar threads

Back
Top