Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: how to read an integer of DOUBLE datatype with type casting

  1. #1
    Member
    Join Date
    Nov 2010
    Posts
    40
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default how to read an integer of DOUBLE datatype with type casting

    please, tell me how to read an integer of DOUBLE data type using
    1-readInt() with tpe casting.
    2-any other approach


    ublic static void main(String [] args)
    {
    	Scanner read = new Scanner(System.in);
    	double radius;
       Circle []c1 =new Circle[5];
     
        for (int i=0;i<c1.length;i++)
        {
      	  System.out.println("radius("+(i+1)+")= ");
      	  radius=read.nextInt();
      	  c1[i] = double new Circle2(radius);
      	  System.out.print("obj("+(i+1)+").Area= "+c1[i].area());
      	  System.out.print("obj("+(i+1)+").Area= "+c1[i].circum());
      	  System.out.print("obj("+(i+1)+").Area= "+c1[i].diam());
        }


  2. #2
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: how to read an integer of DOUBLE datatype with type casting

    c1[i] = new Circle2((double)radius);

    However, Circle2 isn't defined anywhere.

    Second, why not make radius a double to start with by

    radius = readIn.nextDouble();

    ?

  3. #3
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: how to read an integer of DOUBLE datatype with type casting

    Perhaps you meant

    c1[i] = new Circle(radius);

    If there is a class called Circle2,

    try type casting it

    cl[i] = (Circle) new Circle2(radius);

  4. #4
    Member
    Join Date
    Nov 2010
    Posts
    40
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: how to read an integer of DOUBLE datatype with type casting

    Quote Originally Posted by javapenguin View Post
    Perhaps you meant

    c1[i] = new Circle(radius);

    If there is a class called Circle2,

    try type casting it

    cl[i] = (Circle) new Circle2(radius);
    Primmmmaaaa
    thank you

Similar Threads

  1. Typecasting of double variable to integer
    By JavaPF in forum Java Programming Tutorials
    Replies: 2
    Last Post: December 5th, 2010, 03:41 AM
  2. Need something like a "Hashtable<String[], Integer>" kind of data type @@
    By Albretch Mueller in forum Java Theory & Questions
    Replies: 2
    Last Post: November 27th, 2010, 10:24 PM
  3. Is there an integer-type variable bigger than "long"?
    By bardd in forum Java Theory & Questions
    Replies: 2
    Last Post: September 3rd, 2010, 02:43 PM
  4. Performance of Type Casting and Conversions
    By fritzoid in forum Java Theory & Questions
    Replies: 1
    Last Post: October 1st, 2009, 07:56 PM
  5. Type casting error in Java
    By Eric in forum Java Theory & Questions
    Replies: 3
    Last Post: December 13th, 2008, 04:11 PM