0
// It's program of cars and it's colours
 
import java.util.Scanner;
    class Details
      {
      String name;
     String colour;
     public Details( String name, String colour)
      {
        this.name=name;
        this.colour=colour;
      }
        }

          public class Car {
         public static void main(String[] args) {
        int i, num;
        Scanner sc=new Scanner(System.in); 
        System.out.println("enter the size");
        num=sc.nextInt();
        Details cars[]=new Details[num];
        System.out.println("enter name and colour");
        for( i=0;i<cars.length;i++);
        {
            cars[i].name=sc.next();
            cars[i].colour=sc.next();
            System.out.println("name : "+cars[i].name+" \n colour :"+cars[i].colour);
        }
        sc.close();

    }
       
}
  • 1
    Please read: [How to debug small programs](https://ericlippert.com/2014/03/05/how-to-debug-small-programs/) – Turing85 Sep 02 '20 at 16:40

1 Answers1

1

You've left extra semicolon on the line with a declaration of for loop.

This is a valid syntax and if you break the code into logical blocks you'll get the following:

for (i = 0; i < cars.length; i++);
        
{
  cars[i].name = sc.next();
  cars[i].colour = sc.next();
  System.out.println("name : " + cars[i].name + " \n colour :" + cars[i].colour);
}

Here, you have for loop which does nothing until i is equal to 2. This loop is followed by a block, which performs some code with i already being equal to 2!