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.


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

Results 1 to 3 of 3

Thread: What is wrong with my code?

  1. #1
    Junior Member
    Join Date
    Sep 2018
    Thanked 0 Times in 0 Posts

    Default What is wrong with my code?

    Hey guys, so have this computer science project that I am working on, and it seems like I have an input Mismatch exeption in line 17(rate), but i do not understand why, since I used the nextDouble() and used a Double as input, can anyone help?
    1 package project2;
    3 import java.util.Scanner;
    5 public class file1 {
    7 public static void main(String[] args) {
    9 Scanner scan = new Scanner(System.in);
    10 System.out.print("Pool Lenght (feet): ");
    double lenght = scan.nextDouble(); //feet
    System.out.print("Pool Widht (feet): ");
    double width = scan.nextDouble(); //feet
    System.out.print("Desired Depth (inches): ");
    double depth = scan.nextDouble();//feet
    System.out.print("Rate (gallons/min): ");
    17 double rate = scan.nextDouble(); //gallon per minute
    double ratecubic = rate * 0.133681; //cubic feet per minute
    depth = depth/12;
    double volume = (lenght * width * depth); //cubic feet
    double second0 = ((volume/ratecubic)*60); //seconds
    double hour0 = second0/60; //hour pathwayble
    int second1 = (int)Math.round(second0%60); //seconds in a minute
    int minute =(int) Math.round(hour0%60); //minutes in an hour
    int hour1 = (int)Math.round(hour0/60); //hours
    System.out.println(hour1 +":"+ minute + ":" + second1);


    Here is the code.
    Last edited by aShibata; September 28th, 2018 at 10:35 AM.

  2. #2
    Junior Member tonya's Avatar
    Join Date
    Feb 2018
    Thanked 1 Time in 1 Post

    Default Re: What is wrong with my code?

    I can't see anything obvious, unfortunately your code is difficult to read, and so is your attached screen shot of the error. Could you please cut and paste your code and error message in a code block to make it easier to read? your just need to wrap it as per the below
    your code goes here

    according to the Java docs the error message you got is for the following reason:
    InputMismatchException - if the next token does not match the Float regular expression, or is out of range

  3. #3
    Join Date
    Sep 2018
    My Mood
    Thanked 38 Times in 36 Posts

    Default Re: What is wrong with my code?

    I compiled this and it ran just fine (whether the calculations are correct is another thing). The input mismatch exception would occur if you provide input that didn't match a double (e.g. entering chars for numbers). Also, your spellings of length and width are incorrect (you have "ht" instead of "th" in some places). Not a big deal unless you are doing this for someone else.


Similar Threads

  1. Help! What is wrong with this code?
    By Hemu in forum What's Wrong With My Code?
    Replies: 2
    Last Post: October 6th, 2014, 08:40 AM
  2. What is wrong with my code?
    By aznlitomik3 in forum What's Wrong With My Code?
    Replies: 8
    Last Post: June 13th, 2014, 08:54 AM
  3. [SOLVED] can anyone help me what is wrong with my code?
    By marc172 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: December 22nd, 2013, 09:53 PM
  4. What's wrong with my code?
    By Rara in forum What's Wrong With My Code?
    Replies: 8
    Last Post: April 8th, 2013, 01:02 PM
  5. What's wrong with my code
    By maronski in forum What's Wrong With My Code?
    Replies: 3
    Last Post: September 26th, 2012, 09:07 AM