To print a right-facing arrow using the input 01, first create a class for the arrow and set the space value properly with '%6d' before showing the arrow.
Further Explanation:
The following code prints the arrowhead and body:
Import java.util.Scanner;
//Define the method.
public class RightfacingArrow
{
//Define the main method.
public static void main(String[] args)
{
//Create an instance of Scanner.
Scanner object = new Scanner(System.in);
//Declare the variables.
int baseChar;
int headChar;
//Ask user for input values.
baseChar = object.nextInt();
headChar = object.nextInt();
//Show the head character with a space of 6 from the start.
System.out.printf("%6d ", headChar);
//Print the arrows.
System.out.println(baseChar + "" + baseChar + ""
+ baseChar + "" + baseChar + "" + baseChar + ""
+ headChar + "" + headChar);
System.out.println(baseChar + "" + baseChar
+ "" + baseChar + "" + baseChar + "" + baseChar
+ "" + headChar + "" + headChar + "" + headChar);
System.out.println(baseChar + "" + baseChar
+ "" + baseChar + "" + baseChar + "" + baseChar
+ baseChar + "" + headChar + "" + headChar);
//Show the head character with a space of 6 from the start.
System.out.printf("%6d ", headChar);
}
}
Output:
If you input 01, the output will appear as follows:
1
0000011
00000111
0000011
1
Answer details:
Grade: College Engineering
Subject: Computer Science and Engineering
Chapter: Java Programming
Keywords:
Java, input, output, programming, statements, if-else, loops, print, scan, right-facing arrows, body, main body, char, int, variables, scanner class, abstract class, constructor, destructor