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

6th Mar 2021, 12:54 AM
Gabriella Martinez
Gabriella Martinez - avatar
10 ответов
+ 2
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.
6th Mar 2021, 4:31 AM
ChaoticDawg
ChaoticDawg - avatar
7th Mar 2021, 8:35 PM
Gaurav Dixit🇮🇳
Gaurav Dixit🇮🇳 - avatar
+ 2
You have a misplaced "+" in your System.out.print()
6th Mar 2021, 1:28 AM
Apollo-Roboto
Apollo-Roboto - avatar
+ 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));
6th Mar 2021, 3:31 AM
ChaoticDawg
ChaoticDawg - avatar
+ 2
Your code in the post works fine for me when I copied it into the playground.
6th Mar 2021, 4:24 AM
ChaoticDawg
ChaoticDawg - avatar
+ 2
Wow that small of a change fixed it lol. I feel super dumb now. Thank you so much!
6th Mar 2021, 4:33 AM
Gabriella Martinez
Gabriella Martinez - avatar
+ 2
put scanner instead of Scanner so that: Scanner scanner... and r = scanner.nextInt();
7th Mar 2021, 10:15 PM
Bartek Rocławski
Bartek Rocławski - avatar
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
6th Mar 2021, 4:20 AM
Gabriella Martinez
Gabriella Martinez - avatar
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.
6th Mar 2021, 4:28 AM
Gabriella Martinez
Gabriella Martinez - avatar
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.
6th Mar 2021, 4:37 AM
ChaoticDawg
ChaoticDawg - avatar