473,416 Members | 1,698 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

How to fix Circle.java:18: variable radius might not have been initialized error

I keep getting the error: Circle.java:18: variable radius might not have been initialized

Expand|Select|Wrap|Line Numbers
  1.  import java.util.Scanner;
  2.    import java.io.*; 
  3.  
  4.     public class Circle
  5.    {
  6.        public static void main(String args[]) 
  7.       {
  8.          double radius, area;
  9.          double pi = 3.14159;
  10.  
  11.          System.out.println("Enter radius >= 0 ");
  12.  
  13.  
  14.          System.out.println("Circles radius = " + radius);
  15.          area = pi * radius * radius;
  16.          System.out.println("Circles Area = " + area);
  17.       }
  18.    }
  19.  
  20.  
May 15 '10 #1
1 2557
Curtis Rutland
3,256 Expert 2GB
@blknmld69
The error is telling you exactly what is wrong.

You have declared a variable called "radius", but you have never assigned a value to it. Therefore you are trying to use an uninitialized variable.

You print the prompt to enter a radius but you never use a Scanner to get the input.
May 17 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Stub | last post by:
In statement: Circle c1=c2; Is the assignment operator= of Circle called? In statement Circle c1(c2); Is the copy constructor called?
9
by: Banaticus Bart | last post by:
I wrote an abstract base class from which I've derived a few other classes. I'd like to create a base class array where each element is an instance of a derived object. I can create a base class...
2
by: Zardoz | last post by:
I've created a new header file in which one will find : #using <mscorlib.dll> using namespace System; __gc class G { public: int k; int sum(int){return 0;}
3
by: Ed Leafe | last post by:
In Dabo, we create cursor classes that combine the backend-specific dbapi cursor class with our own mixin class that adds framework- specific behaviors. This has been working well for a couple of...
2
by: Suneeel | last post by:
Hi all, I'm new at templates. I've written this code and am compiling it with gcc 4.1.0 on RedHat Linux 9. /////////temptest.h////////////// template <class T> class tempclass { public:
2
by: RitualDave | last post by:
I get a C2811 error when I compile the following (with the /clr switch): template <class T> ref class Base {}; template <template <class> class TBase> ref class Derived : TBase<int> {};
2
by: paranic | last post by:
Hi there i suppose we have the following class file database.php class InSQL { function query($query, $link_identifier=null) { global $query_totals;
1
by: Bruce | last post by:
public ref class GpsDevice abstract { /* Please note GarXface4::GpsDevice* is in a different namespace from this one and GarXface4::GpsDevice is an unmanaged class */ virtual...
14
by: DeadSilent | last post by:
I have this code and for some reason I keep getting an error where it says "exporting non-public type through public api ".. I'm not sure why this keeps happening but it does so for getCircleInfo /...
10
by: Meganutter | last post by:
Hello, I have been stuck with this error for a while now and really want to get it fixed. The catch here is, i need to rewrite code and update it. when i use the old code the page loads as its...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.