Exception in thread "main" java.util.InputMismatchException at java.util.Scanner.throwFor(Unknown Source) at java.util.Scanner | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Exception in thread "main" java.util.InputMismatchException at java.util.Scanner.throwFor(Unknown Source) at java.util.Scanner

import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Scanner; public abstract class Account1 { Scanner s=new Scanner(System.in); public String name=s.next(); public double bal=s.nextDouble(); static Date strDate; public static void main(String[] args) { Scanner s=new Scanner(System.in); System.out.println("Enter the type of account (1/2)"); int type=s.nextInt(); Savings sav=new Savings(); Current c=new Current(); if(type==1) System.out.println(sav.calculateInterest(strDate)); else if(type==2) System.out.println(c.calculateInterest(strDate)); else System.out.println("Invalid request"); } abstract double calculateInterest(Date strDate); } class Savings extends Account1{ Savings sav=new Savings(); Scanner s=new Scanner(System.in); int Irate=12; //System.out.println("enter start date"); String date1=s.next(); //System.out.println("enter end date"); String date2=s.next(); double calculateInterest(Date strDate){ DateFormat d=new SimpleDateFormat("dd/mm/yyyy"); System.out.println("enter start date"); String date1=s.next(); System.out.println("enter end date"); String date2=s.next(); try { strDate=d.parse(date1); } catch (ParseException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } Date endDate = null; try { endDate = d.parse(date2); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } double rate=(strDate.getTime()-endDate.getTime())/84600000; int intrate=(int)Math.abs(rate); double Interest=(bal*intrate*Irate)/100; return Interest; } } class Current extends Account1{ Current c=new Current(); Scanner s=new Scanner(System.in); int Irate=5; double calculateInterest(Date strDate){ DateFormat d=new SimpleDateFormat("dd/mm/yyyy"); System.out.println("enter start date"); String date1=s.next(); System.out.println("enter end da

7th May 2020, 1:21 PM
Kuruva Sai Kiran
Kuruva Sai Kiran - avatar
1 Answer
0
That exception occurs when you give input mismatching type of data for example, if an integer value is required but you enter other than integer like double, or string.. then it raise InputMismatchException.... See Your code is missing due to charecter limit... But it is difficult for some one to identify with just looking.. So no one may put interest to try to solve it.. So it better to save code and share link instead code pasting.. https://www.sololearn.com/post/75089/?ref=app https://www.sololearn.com/discuss/333866/?ref=app
7th May 2020, 2:16 PM
Jayakrishna 🇮🇳