Using for-loops, develop an algorithm that RETURNS A STRING
formatted as a staircase using the character ‘x’ (lower case). The
staircase should have the following properties:
N steps going up from left to right
The top step should have one ‘x’, the second step from the top have
two ‘x’s, the third step from the top should have three ‘x’s, … ,
the bottom step should have N ‘x’s.
Generally, the nth step from the top should have n ‘x’s
Example output for N = 10:
_________x↩
________xx↩
_______xxx↩
______xxxx↩
_____xxxxx↩
____xxxxxx↩
___xxxxxxx↩
__xxxxxxxx↩
_xxxxxxxxx↩
xxxxxxxxxx↩
Note: the underscores (“_”) should be spaces (“ “) and the arrows (“↩”) should be replaced with carriage returns. I’ve included them here to draw attention to the fact that there should be spaces preceding the step. Your output has to exactly match the specifications to be considered correct. The method should look like this:
public String printPattern(int n) {
}
Code:
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is
public. */
class Test
{
public static String printPattern(int n){
String result="";
int temp=n-1;
while(temp>0){
for(int
i=0;i<temp;i++){
result=result+"
";
}
for(int
i=temp;i<n;i++){
result=result+"Z";
}
result=result+" ";
temp--;
}
return result;
}
public static void main(String[] args)
{
String
result=printPattern(10);
System.out.println(result);
}
}
output:
Hit thumps up, if you like the
solution.
thanks
Using for-loops, develop an algorithm that RETURNS A STRING formatted as a staircase using the character...
2) Write a function stringManip that takes in a character string and returns a character string following these rules: a) any vowel (a, e, i, o, u) is replaced by the character '&' b) any numeric character has 1 added to it (if it was 9, it becomes O instead) (str2num() is useful here) c) all lowercase characters become uppercase d) replace the final character with '!' e) append the length of the string before this step to the end...
In Java Only can use class String length charAt class StringBuilder length charAt append toString class Character any method Create the following methods nthWord takes an int and a String as input and returns a String: The input int represents a number n that is assumed to be positive, and the output string contains every nth word of the input string, starting with the first word, separated by a single space. {\em For this method, a word is defined to...
Write a program that uses a recursive function to determine whether a string is a character-unit palindrome. Moreover, the options for doing case sensitive comparisons and not ignoring spaces are indicated with flags. For example "A nut for a jar of tuna" is a palindrome if spaces are ignored and not otherwise. "Step on no pets" is a palindrome whether spaces are ignored or not, but is not a palindrome if it is case sensitive. Background Palindromes are character sequences...
Using loops with the String and Character classes. You can also use the StringBuilder class to concatenate all the error messages. Floating point literals can be expressed as digits with one decimal point or using scientific notation. 1 The only valid characters are digits (0 through 9) At most one decimal point. At most one occurrence of the letter 'E' At most two positive or negative signs. examples of valid expressions: 3.14159 -2.54 2.453E3 I 66.3E-5 Write a class definition...
In Java All methods listed below must be public and static. If your code is using a loop to modify or create a string, you need to use the StringBuilder class from the API. Keep the loops simple but also efficient. Remember that you want each loop to do only one "task" while also avoiding unnecessary traversals of the data. No additional methods are needed. However, you may write additional private helper methods, but you still need to have efficient...
JAVA MASTERMIND The computer will randomly select a four-character mastercode. Each character represents the first letter of a color from the valid color set. Our valid color choices will be: (R)ed, (G)reen, (B)lue and (Y)ellow. Any four-character combination from the valid color set could become the mastercode. For example, a valid mastercode might be: RGBB or YYYR. The game begins with the computer randomly selecting a mastercode. The user is then given up to 6 tries to guess the mastercode....
PA #1: Word Counter Tabulating basic document statistics is an interesting exercise that leverages your knowledge of strings, files, loops, and arrays. In this homework, you must write a C++ program that asks the user for an input and output file. For each line in the input file, write a modified line containing a line number to the output file. Additionally, calculate the number of paragraphs, lines, words, and characters. Write the summary information to the bottom of the output...
This looks long but it is easy just having some trouble please help out thank you. Find and fix all syntax and semantic errors which prevent the program from compiling. Find and fix all logical errors which cause the program to crash and/or produce unexpected results. In addition to making sure the code compiles, we have one final method which we need to complete. There is a method in the code, printAll, which is responsible for printing out the entirety...
12.8 GPA reports using files Prompt the user by "Enter name of input file: " for the name of an input file and open that file for reading. The two input files for the tests are already at the zyBooks site.They each have a list of student names with the course they have taken, of the form Jacobs, Anthony ECS10 4 B- ECS20 4 C+ ANS17 3 A ANS49H 2 D Wilson, Elaine ECS10 4 B+ ECS20 4 C+ ANS17...
12.8 GPA reports using files This program is to compute and write to a file the GPA for student scores read from an input file. As in Lab 7.5, the point values of the grades are 4 for A, 3 for B, 2 for C, 1 for D, and 0 for F. Except for the grade A, where + has no effect, a + after the letter increases the point value by 0.3, and except for F, where a -...