Print Upward Arrow Mark Symbol Number Pattern
In the previous article, we have discussed Java Program to Print Downward Arrow Mark Symbol Star Pattern
In this article we are going to see how to print the upward arrow mark symbol number pattern.
- Java Code to Print Upward Arrow Mark Symbol
- C Code to Print Upward Arrow Mark Symbol
- C++ Code to Print Upward Arrow Mark Symbol
Example-1 When size value= 5 3 234 1 3 5 3 3
Example-2
When size value= 7
4
345
2 4 6
1 4 7
4
4
4
Now, let’s see the actual program to print it.
If you are new to Java and want to learn the java coding skills too fast. Try practicing the core java programs with the help of the Java basic programs list available.
Approach:
- Enter size of the pattern and store it in an integer variable
size. - Take one outer for loop to iterate the rows.
- Take one inner for loops, to iterate the columns.
- After each iteration print a newline.
Java Code to Print Upward Arrow Mark Symbol
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
int size, r, c;
//Taking size as input from user
System.out.print("Size : ");
Scanner scan = new Scanner(System.in);
size = scan.nextInt();
//Taking middle row of the pattern
int mid = size / 2 + 1;
//Outer Loop
for (r = 1; r <= size; r++)
{
//Inner loop
for (c = 1; c <= size; c++)
{
if (c == size / 2 + 1 || c == mid || c == size - mid + 1)
System.out.print(c);
else
System.out.print(" ");
}
//Prints a newline
System.out.println();
//Incrementing the mid value
mid++;
}
}
}
Output:
Size : 7
4
345
2 4 6
1 4 7
4
4
4
C Code to Print Upward Arrow Mark Symbol
#include <stdio.h>
int main()
{
int size, r, c;
//Taking size as input from user
printf("Size : ");
scanf("%d", &size);
//Taking middle of the pattern
int mid = size / 2 + 1;
//Outer Loop
for (r = 1; r <= size; r++)
{
//Inner loop
for (c = 1; c <= size; c++)
{
if (c == size / 2 + 1 || c == mid || c == size - mid + 1)
printf("%d",c);
else
printf(" ");
}
//Prints a newline
printf("\n");
//incrementing the mid value
mid++;
}
return 0;
}
Output:
Size : 7
4
345
2 4 6
1 4 7
4
4
4
C++ Code to Print Upward Arrow Mark Symbol
#include <iostream>
using namespace std;
int main(int argc, char const *argv[])
{
int size, r, c;
//Taking size as input from user
cout << "Size : ";
cin >> size;
//Taking middle of the pattern
int mid = size / 2 + 1;
//Outer Loop
for (r = 1; r <= size; r++)
{
//Inner loop
for (c = 1; c <= size; c++)
{
if (c == size / 2 + 1 || c == mid || c == size - mid + 1)
cout << c;
else
cout << " ";
}
//Prints a newline
cout << endl;
//Incrementing the mid value
mid++;
}
return 0;
}
Output:
Size : 7
4
345
2 4 6
1 4 7
4
4
4
Are you seeking professional help for coding in the Java programming language? The tutorial of Java Programming Examples for beginners and experts will strongly improve your coding skills then you can program for any logic in Java.
Related Java Number Pattern Programs: