So I am using eclipse to practice coding using java and till now it was doing great, until i wrote this program.......
import java.util.*;
public class cars {
String name;
int dom;
Scanner in = new Scanner(System.in);
void takedata()
{
name=in.next();
dom=in.nextInt();
}
void displaydata()
{
System.out.print("Enter the name of the car" name);
System.out.print("Enter the Date of Manufacture of the car" dom);
}
public static void main(String[] args)
{
cars x = new cars();
cars y = new cars();
cars z = new cars();
x.takedata();
y.takedata();
z.takedata();
x.displaydata();
y.displaydata();
z.displaydata();
}
}
whenever i am trying to run the code it is showing me nothing.
I need help....
CodePudding user response:
It wont show anything. Your code will wait till you enter the care name. So, first you need to provide input as your takeData() method is getting called before displayData(). Modify your takeData() method as shown below:
void takedata()
{
System.out.println("Enter Name of the Car: ");
name=in.next();
System.out.println("Enter Date of Manufacture: ");
dom=in.nextInt();
}
Then after executing your program your will be able to see below message:
Enter Name of the Car: