# Thread: How to make user input be of the type double?

1. Member
Join Date
Aug 2012
Posts
4
Rep Power
0

## How to make user input be of the type double?

this line

arr[i] = sc.nextDouble();

gives this warning

- Type mismatch: cannot convert from double to int

2. ## Re: How to make user input be of the type double?

How do you declare your array, arr? is it double[] arr or int [] arr?

3. Member
Join Date
Aug 2012
Posts
4
Rep Power
0

## Re: How to make user input be of the type double?

it's double[]

4. ## Re: How to make user input be of the type double?

Originally Posted by abv
it's double[]
Hm,... what about i? Is that double or int? To make it easier on us all, could you post your code?

5. Member
Join Date
Aug 2012
Posts
4
Rep Power
0

## Re: How to make user input be of the type double?

public static void main(String[] args) {
@SuppressWarnings("resource")
Scanner sc = new Scanner(System.in);
System.out.println("Enter array size: ");
int n = sc.nextInt();
double[] arr = new double[n];
double min = 0;
for(double i = 0; i <n; i++){
System.out.println("Enter element " + (i + 1));
arr[i] = sc.nextDouble();
if(i%3 == 0 && i <= min){
min = i;
}
}
if(min != 0){
System.out.println("The smallest number divisible by 3 is" + min);
}
else{
System.out.println("No number is divisible by 3");
}
}
so i had to be int

7. ## Re: How to make user input be of the type double?

Why exactly did you declare your for-loop index as of type double?

db

8. ## Re: How to make user input be of the type double?

Originally Posted by DarrylBurke
Why exactly did you declare your for-loop index as of type double?
Yikes! so i is in fact a double when it should be an int. You should be able to fix this now.

9. ## Re: How to make user input be of the type double?

Originally Posted by DarrylBurke
Why exactly did you declare your for-loop index as of type double?

db
Maybe in the future they plan on accessing the 1 and halfth element of the array.

10. ## Re: How to make user input be of the type double?

Originally Posted by Junky
Maybe in the future they plan on accessing the 1 and halfth element of the array.
Fuzzy logic?

db

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•