Jump to content

How to make Java Strings Diagonal

BronyPie

Hey everyone,

Would everyone know how to change the output of this from making it diagonal from left to right to right to left?

Thanks

Screenshot (41).png

Link to comment
Share on other sites

Link to post
Share on other sites

When you use println() instead of print(), it automatically adds a new line at the end of whatever you're printing (the ln in println is short for 'line', essentially meaning this function prints a discrete line of text). This is why you are seeing that diagonal text. Try experimenting around that and see what you get.

 

EDIT: I apologize if I misunderstood your questions, do you want it to be on different lines but have the lines go out and back in? like:

T
	H
		I
			S
            	
					I
						S
                    
				A
            
		T
	E
S

 

Gaming build:

CPU: i7-7700k (5.0ghz, 1.312v)

GPU(s): Asus Strix 1080ti OC (~2063mhz)

Memory: 32GB (4x8) DDR4 G.Skill TridentZ RGB 3000mhz

Motherboard: Asus Prime z270-AR

PSU: Seasonic Prime Titanium 850W

Cooler: Custom water loop (420mm rad + 360mm rad)

Case: Be quiet! Dark base pro 900 (silver)
Primary storage: Samsung 960 evo m.2 SSD (500gb)

Secondary storage: Samsung 850 evo SSD (250gb)

 

Server build:

OS: Ubuntu server 16.04 LTS (though will probably upgrade to 17.04 for better ryzen support)

CPU: Ryzen R7 1700x

Memory: Ballistix Sport LT 16GB

Motherboard: Asrock B350 m4 pro

PSU: Corsair CX550M

Cooler: Cooler master hyper 212 evo

Storage: 2TB WD Red x1, 128gb OCZ SSD for OS

Case: HAF 932 adv

 

Link to comment
Share on other sites

Link to post
Share on other sites

 

Yes, I want it like

                             T

                    E

           S

T

Link to comment
Share on other sites

Link to post
Share on other sites

4 minutes ago, BronyPie said:

I'm trying to figure out how to print out the other way

can you be clear on what you mean by "the other way"? can you show us an example of what you want the output to look like?

Gaming build:

CPU: i7-7700k (5.0ghz, 1.312v)

GPU(s): Asus Strix 1080ti OC (~2063mhz)

Memory: 32GB (4x8) DDR4 G.Skill TridentZ RGB 3000mhz

Motherboard: Asus Prime z270-AR

PSU: Seasonic Prime Titanium 850W

Cooler: Custom water loop (420mm rad + 360mm rad)

Case: Be quiet! Dark base pro 900 (silver)
Primary storage: Samsung 960 evo m.2 SSD (500gb)

Secondary storage: Samsung 850 evo SSD (250gb)

 

Server build:

OS: Ubuntu server 16.04 LTS (though will probably upgrade to 17.04 for better ryzen support)

CPU: Ryzen R7 1700x

Memory: Ballistix Sport LT 16GB

Motherboard: Asrock B350 m4 pro

PSU: Corsair CX550M

Cooler: Cooler master hyper 212 evo

Storage: 2TB WD Red x1, 128gb OCZ SSD for OS

Case: HAF 932 adv

 

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, reniat said:

can you be clear on what you mean by "the other way"? can you show us an example of what you want the output to look like?

I want it like : 

                 T

           E

      S

T

Link to comment
Share on other sites

Link to post
Share on other sites

42 minutes ago, BronyPie said:

I want it like : 

                 T

           E

      S

T

You'll have to calculate how many tabs your top line will need before you start printing, and then each character will get 1 less tab until your last which will have 0. In other words, you'll have to go through your entire text before you start printing, so 2 loops (edit: for some reason I was thinking this was broken up into tokens that had to be counted, so you still only need 1 loop).

Gaming build:

CPU: i7-7700k (5.0ghz, 1.312v)

GPU(s): Asus Strix 1080ti OC (~2063mhz)

Memory: 32GB (4x8) DDR4 G.Skill TridentZ RGB 3000mhz

Motherboard: Asus Prime z270-AR

PSU: Seasonic Prime Titanium 850W

Cooler: Custom water loop (420mm rad + 360mm rad)

Case: Be quiet! Dark base pro 900 (silver)
Primary storage: Samsung 960 evo m.2 SSD (500gb)

Secondary storage: Samsung 850 evo SSD (250gb)

 

Server build:

OS: Ubuntu server 16.04 LTS (though will probably upgrade to 17.04 for better ryzen support)

CPU: Ryzen R7 1700x

Memory: Ballistix Sport LT 16GB

Motherboard: Asrock B350 m4 pro

PSU: Corsair CX550M

Cooler: Cooler master hyper 212 evo

Storage: 2TB WD Red x1, 128gb OCZ SSD for OS

Case: HAF 932 adv

 

Link to comment
Share on other sites

Link to post
Share on other sites

Just now, reniat said:

You'll have to calculate how many tabs your top line will need before you start printing, and then each character will get 1 less tab until your last which will have 0

Okay, so I need it of the string length in which the user inputs it in. Where would I put that in?

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, BronyPie said:

Okay, so I need it of the string length in which the user inputs it in. Where would I put that in?

Simplify the problem and then think it through. let's just start with "You". That's 3 characters. How many tabs would be before the Y once you write it out the way it should look?

Gaming build:

CPU: i7-7700k (5.0ghz, 1.312v)

GPU(s): Asus Strix 1080ti OC (~2063mhz)

Memory: 32GB (4x8) DDR4 G.Skill TridentZ RGB 3000mhz

Motherboard: Asus Prime z270-AR

PSU: Seasonic Prime Titanium 850W

Cooler: Custom water loop (420mm rad + 360mm rad)

Case: Be quiet! Dark base pro 900 (silver)
Primary storage: Samsung 960 evo m.2 SSD (500gb)

Secondary storage: Samsung 850 evo SSD (250gb)

 

Server build:

OS: Ubuntu server 16.04 LTS (though will probably upgrade to 17.04 for better ryzen support)

CPU: Ryzen R7 1700x

Memory: Ballistix Sport LT 16GB

Motherboard: Asrock B350 m4 pro

PSU: Corsair CX550M

Cooler: Cooler master hyper 212 evo

Storage: 2TB WD Red x1, 128gb OCZ SSD for OS

Case: HAF 932 adv

 

Link to comment
Share on other sites

Link to post
Share on other sites

 I need 3 Tabs for the "y", then two for the "o", then one for the "u"

Link to comment
Share on other sites

Link to post
Share on other sites

You simply need to invert the count of j. Rather than starting from 0 and increment to h.length() - 1 [inclusive]. You need to start from h.length()-1, decrement integer j and use the integer i as an inset.

int i = 0;
while (i < h.length())
{
  int j = h.length() - 1 - i;
  while (j > 0)
  {
    System.out.print("\t");
    j--;
  }
  System.out.println(h.charAt(i));
  i++;
}
Link to comment
Share on other sites

Link to post
Share on other sites

4 minutes ago, mshaugh said:

You simply need to invert the count of j. Rather than starting from 0 and increment to h.length() - 1 [inclusive]. You need to start from h.length()-1, decrement integer j and use the integer i as an inset.


int i = 0;
while (i < h.length())
{
  int j = h.length() - 1 - i;
  while (j > 0)
  {
    System.out.print("\t");
    j--;
  }
  System.out.println(h.charAt(i));
  i++;
}

Thank you so much! I understand it now

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×