Results 1 to 3 of 3
- 12-14-2010, 07:18 PM #1
Member
- Join Date
- Nov 2010
- Posts
- 75
- Rep Power
- 0
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
Java Code: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()); }Last edited by amrmb09; 12-14-2010 at 07:22 PM.
- 12-14-2010, 07:51 PM #2
Member
- Join Date
- Sep 2010
- Posts
- 56
- Rep Power
- 0
You can just use "nextDouble()" instead of "nextInt()".
- 12-14-2010, 08:01 PM #3
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,377
- Blog Entries
- 7
- Rep Power
- 17
A (primitive) data type is either int or double; it can't be an int of double type or vice versa; casting is easy though:
It doesn't matter how d got its value, you don't even need an explicit d variable:Java Code:double d= ...; int i= (int)d;
In this code fragment a scanner reads a double value which is cast to an int and assigned to an int variable i. Casting the other way around (ints to doubles) is even easier, i.e. you don't need the explicit cast operation.Java Code:int i= scanner.nextDouble();
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
Similar Threads
-
Why is there (Integer) casting?
By hitesh_public in forum New To JavaReplies: 1Last Post: 11-15-2010, 10:43 AM -
how to plot a curve which has double datatype coordinates
By murdplacid in forum Java 2DReplies: 6Last Post: 11-02-2010, 04:14 PM -
Type Casting
By Shaheen Mohamed in forum New To JavaReplies: 6Last Post: 08-17-2010, 07:56 PM -
type casting
By alvations in forum New To JavaReplies: 1Last Post: 10-13-2008, 07:07 PM -
Type Casting Help
By rhm54 in forum New To JavaReplies: 2Last Post: 02-07-2008, 12:06 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks