how to print these patterns
Answers
go to microsoft word let it be which ever year (the software) write down the following number patterns on the basis or as per your wish and then press ctrl+p or tap on the print option goahead PRINT IS READY !!!
Answer:
In JAVA:-
class pattern
{
public static void main()
{
int i,j;
for (i=1;i <=9;i+=2)
{
for (j=i;j <=9;j+=2)
System.out.print(j);
System.out.println ();
}
}
}
In PYTHON:-
for i in range (1,10,2):
for j in range(i,10,2):
print (j,end="")
print ()
NOW IT'S TIME FOR EXPLANATION
SEE IN THE FIRST THERE IS 13579 AND THE VALUE DEDUCTS FROM LEFT THEREFORE THE VALUE SHIFTS TOWARDS THE LEFT.
HERE YOU HAVE TO MAKE TWO LOOPS. THE OUTER RUNNING FROM 1 TO 9 AND THE INNER RUNNING FROM THE VALUE WHERE THE OUTER LOOP 'I' IS TO 9.
HENCE WHEN 'I' IS AT FIRST 1 THE INNER LOOP RUNS FROM 1 TO 9 WITH AN INTERVAL OF 2. THEREFORE PRINTING ALL THE ODD NUMBERS FROM 1 TO 9.
LIKE THIS 'I' ITERATES AND WHEN THE OUTER LOOP IS AT LAST 9 THE INNER LOOP RUN FROM 9 TO ITS UPPER LIMIT ALSO 9.
HENCE PRINTING ONLY 9 THOUGH THE INTERVAL IS OF 2.
I HOPE THIS HELPS YOU TO KNOW HOW A LOOP IS ITERATING
HOW IS IT PRINTING THE PATTERN??
ANSWER: WHEN 'J' IS UNDER ITERATION IT IS ONLY PRINTING THE NUMBERS IN A LINE.
WHEN THE SYSTEM COMES OUT OF THE INNER LOOP THE SYSTEM GOES TO THE NEXT LINE AND PRINTS THE OTHER VALUES UNDER THE NEXT ITERATION OF THE 'J' LOOP.
System.out.println ();
System.out.println ();is used to send the cursor into the next line while printing.
SAME FOR print () IN PYTHON.
LEARN MORE ABOUT RANGE FUNCTION IN PYTHON BY SEARCHING IT ON GOOGLE.
DON'T FORGET TO MARK ME THE BRAINLIEST
BYE