0

Input mismatch error

i write this code but when trying to run its giving me errors can any body tell me what is the error and why its occurring ? errors are given below 1 : java.base/java.util.Scanner.throwFor(Scanner.java:939) 2 : java.base/java.util.Scanner.next(Scanner.java:1594) 3 : java.base/java.util.Scanner.nextDouble(Scanner.java:2564) 4 : Vehicle.getattributes(Vehicle.java:22) 5 : MyClass.main(MyClass.java:10) Code is given below import java.util.Scanner; public class Vehicle { int maxSpeed; int wheels; String color; double fuelCapacity; void horn() { System.out.println("Beep!"); } void getattributes() { Scanner myVar = new Scanner(System.in); System.out.println("Enter max speed : "); this.maxSpeed = myVar.nextInt(); System.out.println("Enter number of wheels : "); this.wheels = myVar.nextInt(); System.out.println("Enter color of vehicle : "); this.color = myVar.nextLine(); System.out.println("Enter fuel capacity : "); this.fuelCapacity = myVar.nextDouble(); } void showattributes() { System.out.println("Your max speed is : " + this.maxSpeed); System.out.println("Total number of wheels are " + this.wheels); System.out.println("Color of vehicle is : " + this.color); System.out.println("Fuel capacity of vehicle is : " + this.fuelCapacity); } } class MyClass { public static void main(String[ ] args) { Vehicle v1 = new Vehicle(); Vehicle v2 = new Vehicle(); v2.horn(); v1.getattributes(); v1.showattributes(); } }

6th Feb 2019, 8:18 AM
Aamir Naseer
Aamir Naseer - avatar
3 Antworten
+ 1
-> To input color remove nextLine n make it to next only i.e. this.color= myVar.next(); //Hope this help n if der any other problem den u can discuss here only
6th Feb 2019, 3:51 PM
Harsh Agrawal
Harsh Agrawal - avatar
0
color is a string variable and i'm also giving a string in input for color
6th Feb 2019, 11:38 AM
Aamir Naseer
Aamir Naseer - avatar
0
ok i will try
9th Feb 2019, 2:43 AM
Aamir Naseer
Aamir Naseer - avatar