E
Engineering , 17.02.2022 22:21

Given two input integers for an arrowhead and arrow body, print a right-facing arrow. ex: if the input is 0 1, the output is
1
11
111
11
1
(perferrably without if-else statements or loops)
in java

Step-by-step answers

answer
Answered by a new expert

For printing a right facing with input 01, define the class for right facing arrow and give the value with appropriate space using '%6d'  and then display the right facing arrow.

Further Explanation:

The code to print the arrowhead and arrow body is as follows:

Import java.util.Scanner;

//Define the method.

public class RightfacingArrow

{

//Define the main method.

public static void main(String[] args)

{

//Create an object of Scanner class.

Scanner object = new Scanner(System.in);

//Declare the variables.

int baseChar;

int headChar;

//Prompt the user to enter the input values.

baseChar = object.nextInt();

headChar = object.nextInt();

 

//Display the headchar in position 6 from the  starting.

System.out.printf("%6d ", headChar);

//Display 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+""+headChar+""+headChar);

//Display the headchar in position 6 from the  starting.

System.out.printf("%6d ", headChar);

}

}

Output:

If the input is 01, the output will be as below:

    1

0000011

00000111

0000011

    1

Learn more:

1. A company that allows you to license software monthly to use online is an example of ? link  

2. Prediction accuracy of a neural network depends on and . link  

Answer details:

Grade: College Engineering

Subject: Computer Science and Enginnering

Chapter: Java Programming

Keyword:

Java, input, output, programming, statements, if-else, loops, print, scan. right facing arrows, body, main body, char, int, variables, scanner class, abstract class, constructor, desctructor

Show answers

Other questions on the subject: Engineering

E
Engineering, 07.05.2021 17:58
Sarah files a patent for submarine telescope due to its usefulness in operation. What type of patent will be filed under
Answers: 0
E
Engineering, 04.11.2021 18:19
If the print scale indicates one-half size, what is the print length of a dimension listed as 12.00 ?
Answers: 0
E
Engineering, 20.06.2021 14:14
Consider an LZW encoder and decoder system works with a table of size 1024 entry. The table is initially filled with entries 0-255 corresponding to the ASCII characters. Characters ‘d and e are located at indices 101 and 102 respectively. Suppose that the LZW decoder receives the following sequence
Answers: 0
E
Engineering, 20.06.2021 14:12
Consider an LZW encoder and decoder system works with a table of size 1024 entry. The table is initially filled with entries 0-255 corresponding to the ASCII characters. Characters ‘d and e are located at indices 101 and 102 respectively. Suppose that the LZW decoder receives the following sequence
Answers: 0

Popular questions today: