0

# How to print hexagon using scanner in java

Using java and scanner

1 Answer

+ 13

ā” For taking user input as integer :
ā import java.util.Scanner; //importing Scanner class
ā Scanner sc = new Scanner(System.in); //sc is object of Scanner class
ā int n = sc.nextInt(); //.nextInt() to take ineteger input.
ā” By hexagon, I am assuming U mean a regular hexagon.
ā A hexagon can be made using 2 isosceles triangles & a square. [U should give it a try] :
ā an isosceles triangle at top [with unequal side as base]
ābelow it an square with side as length of "unequal side of isosceles triangle"
ā below it same isosceles triangle [upside down]