# Finding square root

• October 18th, 2010, 05:25 PM
Tracy22
Finding square root
anyone know how to make a program that will ask the user to enter a number and also a choice (1 for square or 2 for cube). It will then output the result? This is all I got so far and am lost:
Code Java:

```public static void main(String[] args) { new Scanner(System.in);   Scanner input = new Scanner(System.in); float square;   System.out.println("Enter a number."); System.out.println("Select 1 for square or 2 for cube: "); square = input.nextFloat();   if(square>= 2) { System.out.println(square*2); } else { System.out.println(square + " }     }```
• October 18th, 2010, 06:18 PM
aussiemcgr
Re: Finding square root
I have put some questions in your code. Answer those for me and I can help you from there. Who knows, maybe answer those questions will clear some things up for you while you answer them.

```public static void main(String[] args) { //This is a variable that you immediately garbage collecting new Scanner(System.in);   //Why do you have the previous line if you have this? Scanner input = new Scanner(System.in); //Why a float? float square;   System.out.println("Enter a number."); //Where do you get the number the user enters? System.out.println("Select 1 for square or 2 for cube: "); //Is this supposed to be 1 or 2 or the number the user entered? square = input.nextFloat();   //Why greater than or equal to 2? if(square>= 2) { //Why multiply by 2? System.out.println(square*2); } else { //Why didn't you finish this line of code? System.out.println(square + " } }```