Program to print a string in vertical in Java17 Mar 2025 | 4 min read Description: You have a string and you need to print its characters vertically, starting from left to right of the string. An array of characters can be referred to as a string. In this case, the program is built to print the letters vertically, beginning on the left side of the string and moving right. The string's characters are printed one per line. For instance, the string "ABC" has the three letters (or characters) "A," "B," and "C." This letter will now be printed in three distinct vertical lines as: The small-letter characters will be changed to upper case, and the upper case characters should then be printed. To print the characters in this manner, each character is first accessible using its respective index position (the index starts from 0). The text will be printed in upper case if it is in lower case, and after each character is printed, the cursor should be moved to the next line so that the following character can be printed once more. The string's final character will be reached by repeating this technique. AlgorithmExampleOutput: ![]() Time Complexity: This program has an O(n) time complexity, where n is the number of characters in the string. Space Complexity: This program has an O(n) space complexity, where n is the string's character count. Print a string in a vertical zigzag mannerThe job is to print the supplied string in a vertical zigzag pattern with respect to the given number of rows when given a string, S, of size N and a number of rows, R, as shown in the examples. Approach: The goal is to determine the distance between the major columns and a step value for the in-between columns in order to print the spaces until the string's final character is reached. To solve this issue, adhere to the methods listed below:
Below is the implementation of the above approach: Program code in JavaOutput: ![]() Time Complexity: O(R2*N) Auxiliary Space: O(1) |
Java Throwable.toString() Method
In Java, the java.lang.Throwable.toString() method is a built-in way to get a concise description of an exception or error. It is often used for logging or debugging when we want a quick summary of what went wrong in the program. Syntax: public String toString() It returns a short...
5 min read
How to Call a Method in Java
In Java, the method is a collection of statements that performs a specific task or operation. It is widely used because it provides reusability of code means that write once and use it many times. It also provides easy modification. Each method has its own name...
4 min read
User Thread Vs. Daemon Thread in Java
In the realm of Java programming, threads play a pivotal role in enabling concurrent execution of tasks. Threads are lightweight subprocesses that can run concurrently within a single process. Java offers two types of threads: user threads and daemon threads. Each type serves a distinct purpose...
6 min read
Difference Between Fork/Join Framework and ExecutorService in Java
In Java, the Fork/Join framework is majorly utilized for providing features and functionalities related to parallel processing and programming and this is carried out by dividing or breaking down an operation into smaller operations or instructions and they are processed with the help of available cores...
9 min read
Spliterator in java 8
It is similar to the other iterators available in Java to traverse the elements of the source(Collection, Generator function or IO channel). Spliterator is a base utility for Streams, especially parallel ones. In order to use Spliterator for collections, we create an object of Spliterator by calling...
9 min read
Advantages of JavaBeans
Using JavaBeans in the Java program allows us to encapsulate many objects into a single object called a bean. Java is an object-oriented programming language that makes the develop once, run and reuse the program everywhere most important. However, JavaBeans add reusability into the Java program by...
2 min read
How to Call Static Blocks in Java
? Static code blocks in Java are unique sections of code that are only run once, during the initialization of a class. They are typically used to execute one-time setup operations like initialising static variables or any other necessary setup. Static blocks are automatically executed by the...
3 min read
Finite Automata Algorithm for Pattern Searching
Pattern searching using Finite Automata is a string-matching technique that employs a finite state machine to locate occurrences of a pattern in a text. It preprocesses the pattern to create a transition table, enabling efficient text scanning using constant-time state transitions. This method guarantees deterministic and rapid...
6 min read
Difference Between Static and Non-Static Members in Java
Java, a widely used object-oriented programming language, offers a variety of features to help build robust and flexible applications. Two important concepts in Java of the object model have static and non-static members. Understanding the difference between static and non-static members is important for effective Java...
5 min read
Java Transaction API
In today's world, where data integrity and consistency are crucial, handling transactions becomes paramount in any software application. Transactions ensure that a set of database operations are executed as a single unit of work, either all succeeding or all failing, thereby maintaining the integrity of the...
5 min read
We request you to subscribe our newsletter for upcoming updates.

We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India

