Create a single NOTEPAD or PDF file that restates the problem in your own words,
ID: 3585861 • Letter: C
Question
Create a single NOTEPAD or PDF file that restates the problem in your own words, specifies what input is needed for whomever is using the process, what output is expected, the step by step process (algorithm) to get the output from the input, and test data (input for which you know the expected output for each of the 3 problems given below. (Include all this information in one file) You should not write any code. Make sure the problem statement is in your own words and is descriptive enough so someone not reading the problem you were given will understand what is being done. Do not write any code.
Write a process that will ask the user to enter a number then output a pattern consisting of user’s number of # in the first row, the user’s number -1 # in the second row, the user’s number -2 # in the third row, etc. until the last row contains 1 #. For example if the user entered 8, the pattern would be
########
#######
######
#####
####
###
##
#
Explanation / Answer
printing pattern:
algorithm:
input:take number of rows as input from user.this input is used for fixing size of rows to print
declare variable:val,this is used for printing number of columns.defaultly it takes or copys the value of rows into it..
(solution is based on nested loop)
loop:
starts from 1 to rows:
this loop is used for rows
it starts from row 1 to row number given by user input which is in row variable
loop2:(nested loop)
this loop prints value to console
from 1 to val;supose val =8;
at first row it prints 8 times value:
next we decrement val variable value by 1.
so,this val value decrements each time
supose let us asume val=8
at row 1,val=8
at row 2,val=7
at row 3,val=6
so......till at row 8 val=1;
the solution for this problm is fully depend on loops concept..
outer loop is for looping rows
inner loop is for printing column value on console.
and one varaible called val is decremented for every row..each time
base on this val value ..console prints done.
example program to show just output:
import java.util.Scanner;
public class Pattern {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
System.out.println("enter number of rows to print pattern:");
int rows=sc.nextInt();
int val=rows;
for(int i=1;i<=rows;i++){
for(int j=1;j<=val;j++){
System.out.print("#");
}
val--;
System.out.println();
}
}
}
output:
enter number of rows to print pattern:
11
###########
##########
#########
########
#######
######
#####
####
###
##
#
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.