How to print hexagon using scanner in java | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How to print hexagon using scanner in java

Using java and scanner

4th Jan 2019, 3:14 PM
Sanyukta Joshi
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]
4th Jan 2019, 5:05 PM
Gaurav Agrawal
Gaurav Agrawal - avatar