what input statement is used in a float..`

import java.util.Scanner;

public class Program1 {
  public static void main(String[] args) {
    float Fahrenheit, celsius;
    Scanner input = new Scanner(System.in);      

    System.out.print("Enter temperatue in Celsius");
    celsius = input.nextDouble();<---- this line is giving a run time error.

     Fahrenheit= ((9 * celsius)/5 +32 );

    System.out.println(celsius   +    "Celsius is"   +   Fahrenheit   +   "Fahrenheit");


Recommended Answers

All 2 Replies

celsius = input.nextFloat();//<---- this line is giving a run time error.
It will work...

What EXACTLY is the error message?

ps: reading a double, then assigning it to a float is a compile-time error becuase float is a "narrower" type than double - information will be lost on that conversion - but that's not a run-time error

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.