Can someone tell me what I'm doing wrong / missing? | SoloLearn: Learn to code for FREE!


Can someone tell me what I'm doing wrong / missing?

import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner Scanner = new Scanner(; double pi = 3.14; //your code goes here int r; r = Scanner.nextInt(); double perimeter = 2*pi*r; System.out.print(+ perimeter); } }

3/6/2021 12:54:39 AM

Gabriella Martinez

10 Answers

New Answer


It's probably a naming collision. Your Scanner variable name is also Scanner. Try changing it to something else or at least change the first letter so that it is a lower case s instead of S.


Gabriella Martinez Here your solution


You have a misplaced "+" in your System.out.print()


Apollo-Roboto The + here is just a unary operator signifying that the number is positive (or * 1 rather) and makes no difference in the functionality of the program. Gabriella Martinez What is your issue with the expected output? The output is mostly correct, with the exception of the least significant bits. This part can be solved using formatting or rounding to cut those parts off. This has to do with the use of floating point numbers. If you want more accuracy in your result of the circumference then you should use the PI constant found in the Math class. double circumference = Math.PI * 2 * r; System.out.println(String.format("%.2f", circumference));


Your code in the post works fine for me when I copied it into the playground.


Wow that small of a change fixed it lol. I feel super dumb now. Thank you so much!


put scanner instead of Scanner so that: Scanner scanner... and r = scanner.nextInt();


i kept getting an error message stating, “Exception in thread “main,” and i wasnt sure what it meant. Im trying to use radius to find perimeter


This is what it's telling me: It also won’t accept it for the test cases. Weird! Thanks for the help.


Remember this for next time you ask a question. If you had included the error information in your post you would have gotten your answer much faster. Lol I just thought it was a typo, and that you were trying to run the code in the playground (which it works there just fine, shouldn't, but does), so I didn't pay it any mind and thought you were wondering about why the fractional part of the output was that way.