Question

The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility) P A H N A P L S I I G Y I R And then read line by line: "PAHNAPLSIIGYIR" Write the code that will take a string and make this conversion given a number of rows: string convert(string s, int numRows); Example 1: Input: s = "PAYPALISHIRING", numRows = 3 Output: "PAHNAPLSIIGYIR" Example 2: Input: s = "PAYPALISHIRING", numRows = 4 Output: "PINALSIGYAHRPI" Explanation: P I N A L S I G Y A H R P I Example 3: Input: s = "A", numRows = 1 Output: "A" Constraints: 1 <= s.length <= 1000 s consists of English letters (lower-case and upper-case), ',' and '.'. 1 <= numRows <= 1000 solve in java

          The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)
P   A   H   N
A P L S I I G
Y   I   R
And then read line by line: "PAHNAPLSIIGYIR"
Write the code that will take a string and make this conversion given a number of rows:
string convert(string s, int numRows);
Example 1:
Input: s = "PAYPALISHIRING", numRows = 3
Output: "PAHNAPLSIIGYIR"
Example 2:
Input: s = "PAYPALISHIRING", numRows = 4
Output: "PINALSIGYAHRPI"
Explanation:
P     I    N
A   L S  I G
Y A   H R
P     I
Example 3:
Input: s = "A", numRows = 1
Output: "A"
Constraints:
1 <= s.length <= 1000
s consists of English letters (lower-case and upper-case), ',' and '.'.
1 <= numRows <= 1000
solve in java
        
Show more…

Added by Gregorio S.

Computer Science and Information Technology
Computer Science and Information Technology
Trishna Knowledge Systems 2018 Edition
AceChat toggle button
Close icon
Ace pointing down

Please give Ace some feedback

Your feedback will help us improve your experience

Thumb up icon Thumb down icon
Thanks for your feedback!
Profile picture
The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility) P A H N A P L S I I G Y I R And then read line by line: "PAHNAPLSIIGYIR" Write the code that will take a string and make this conversion given a number of rows: string convert(string s, int numRows); Example 1: Input: s = "PAYPALISHIRING", numRows = 3 Output: "PAHNAPLSIIGYIR" Example 2: Input: s = "PAYPALISHIRING", numRows = 4 Output: "PINALSIGYAHRPI" Explanation: P I N A L S I G Y A H R P I Example 3: Input: s = "A", numRows = 1 Output: "A" Constraints: 1 <= s.length <= 1000 s consists of English letters (lower-case and upper-case), ',' and '.'. 1 <= numRows <= 1000 solve in java
Close icon
Play audio
Feedback
Powered by NumerAI
Danielle Fairburn Ivan Kochetkov
Jennifer Stoner verified

Akash M and 57 other subject AP CS educators are ready to help you.

Ask a new question

*

Labs

-

Want to see this concept in action?

NEW

Explore this concept interactively to see how it behaves as you change inputs.

View Labs

*

Key Concepts

-
Key Concept
Premium Feature
Explore the core concept behind this problem.
Play button
Key Concept
Premium Feature
Explore the core concept behind this problem.
Your browser does not support the video tag.

*

Recommended Videos

-
i-came-to-this-question-and-i-need-a-java-solution-for-the-below-problem-the-chessboard-below-has-64-squares-8-rows-and-8-columns-each-row-is-labeled-from-1-to-8-and-each-column-is-labeled-f-99369

The chessboard below has 64 squares, 8 rows, and 8 columns. Each row is labeled from 1 to 8, and each column is labeled from a to h (lowercase). A square is located at the intersection of a row and of a column, like square 2C it's the intersection of the row 2 and column C. Positioning a pawn to a starting square, you need to find out where it will be the end square after moving it R times (rows) vertically to the top and C times (columns) horizontally to the right. If during the moves the pawn reaches the end of the board, it will start again from the opposite direction like in the examples below. INPUT string StartPosition number R number C OUTPUT string EndPosition EXAMPLE 1 Input StartPosition: 2b, R: 3, C: 2 Output 5d EXAMPLE 2 Input StartPosition: 5h, R: 11, C: 25 Output 8a public static String run(String startPosition, int R, int C) { }

Akash M.

given-string-userstring1-on-one-line-and-string-userstring2-on-a-second-lineassign-maxlength-with-the-length-of-the-longer-string-ex-if-the-input-is-garden-animals-then-the-output-is-7-2-3-p-85877

Willis J.

suppose-you-are-to-design-a-program-that-prompts-the-user-to-enter-a-string-and-displays-the-number-of-vowels-consonantsand-spacesassume-letters-aeiouor-aeiou-as-the-vowelscheck-the-two-samp-69265

Suppose you are to design a program that prompts the user to enter a String and displays the number of vowels, consonants, and spaces. Assume letters A, E, I, O, U or a, e, i, o, u as the vowels. Check the two sample runs and carefully read the instructions below. Two Sample Run: Enter a String: I Love CPS*1231 LoL!!! "The number of vowels is 4" "The number of consonants is 7" "The number of spaces is 3" Enter a String: 123 456 789 0 "The number of vowels is 0" "The number of consonants is 0" "The number of spaces is 3" Instructions: • Prompt the user to input a String (the String may contain spaces). • Based on the inputted String, check each character using a Loop to count the total number of vowels, consonants, and spaces. • Print the total number of vowels, consonants, and spaces. The count displayed must account for all the vowels and consonants in the String regardless of case-sensitivity (upper or lower case). • Print double quotes in the beginning and end of the output as shown in the Sample Run. • Hint: o charAt(index) and length() method from the String class, toUpperCase(ch) (or toLowerCase(ch)), isLetter(ch) method from the Character class might be helpful. o Check whether the character is a space. (ch == ' ') o Check whether the character is C or P or S. (ch == 'C' || ch == 'P' || ch == 'S') o Check whether the character is between A to Z. (ch >= 'A' && ch <= 'Z') • Copy&Paste your code and screenshot your console output for the same 2 Sample Runs shown above.

Akash M.


*

Recommended Textbooks

-
Computer Science and Information Technology

Computer Science and Information Technology

Trishna Knowledge Systems 2018 Edition
achievement 1,702 solutions
Introduction to Programming Using Python

Introduction to Programming Using Python

Y. Daniel Liang 1st Edition
achievement 1,481 solutions
Computer Science - An Overview

Computer Science - An Overview

Glenn Brookshear, Dennis Brylow 12th Edition
achievement 1,020 solutions

*

Transcript

-
00:01 Here from the given question we have the java solution for the given problem that is java public static class just bold on public static string run string start position comma in r comma in scene browse bracket open in start row is equal to integer dot verse int in bracket start position dot sub string zero comma one so we call an character start column which equals to start position dot character at one semicolon int and raw is equals to start row plus r minus one percentile of eight plus one semicolon character and column is equals to character start column minus a plus c percentile a plus main semicolon return plus end raw plus end column semicolon bracket close public static wide main string brackets close arg bracket open for example string result is equals to run to be comma three two semicolon system out print in example one column result semicolon and output should be 5d the example to string result to is equals to run 5h comma 11 25 semicolon system doubt out print in example two plus result in semicolon and close the brackets here this program defines a chessboard pro class with a written method that makes the starting position the number of rows of a r and number of columns to most see the main method demonstrate the use of function in the provided example...
Need help? Use Ace
Ace is your personal tutor. It breaks down any question with clear steps so you can learn.
Start Using Ace
Ace is your personal tutor for learning
Step-by-step explanations
Instant summaries
Summarize YouTube videos
Understand textbook images or PDFs
Study tools like quizzes and flashcards
Listen to your notes as a podcast
Continue solving this problem
Create a free account to:
  • View full step-by-step solution
  • Ask follow-up questions with Ace AI
  • Save progress and study later
Continue Free
Numerade

Get step-by-step video solution
from top educators

Continue with Clever
or



By creating an account, you agree to the Terms of Service and Privacy Policy
Already have an account? Log In

A free answer
just for you

Watch the video solution with this free unlock.

Numerade

Log in to watch this video
...and 100,000,000 more!


EMAIL

PASSWORD

OR
Continue with Clever