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

0

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(System.in); 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

+4

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.

+3

Gabriella Martinez Here your solution https://code.sololearn.com/cUp4bhW9lQ3Y/?ref=app

+2

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

+2

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));

+2

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

+2

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

+1

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

0

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

0

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

0

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.