Java programming issue

89 Views Asked by At

Can anyone help me to solve this issue . I do not understand where I can put the number of the area. Also what exactly this expression mean:

in.nextInt(); 

Here is the program:

Write a Java program that reads an integer value representing the side of a square shape and prints out the square’s area and perimeter. Use proper labels for all outputs and comment your code properly.

2

There are 2 best solutions below

0
On

That line of code is just allowing a user to input an Integer. You need to use Scanner or BufferedReader to read the input.

0
On

First of all, in.nextInt(); command means that the programme will allow the user to input an integer number from keyboard. Where as in means the Scanner type variable you have declared above your code. As for your code, it probably is :

Scanner in=new Scanner(System.in);

and nextInt(); means that the allowed input, must be of integer type.

You can also give a prompt text from the input by :

int x;
System.out.print("Enter Length : ");
x=in.nextInt();

Where variable x is an integer and it will assign the input value by the user.

When the programme is executed, it would show this on console :

Enter Length :

Hope that works for you, and I guess using x you can pretty much write the rest of your code by yourself.