import java.util.Scanner;

public class array_Project
{
    int index;
    Scanner scan=new Scanner(System.in);
    System.out.println("Enter index number");
    int[]Project={10,15,20,25,30,35,40,45,50,55};
}   
public class array2
{
    switch (int index) {
        case 1:
            if(index=0)
            {
                System.out.print(Project[0]);
            }
        break;
        case 2:
            if(index=1)
            {
                System.out.print(Project[1]);
            }
        break;
        case 3:
            if(index=2)
            {
                System.out.print(Project[2]);
            }
        break;
        case 4:
            if(index=3)
            {
                System.out.print(Project[3]);
            }
        break;
        case 5:
            if(index=4)
            {
                System.out.print(Project[4]);
            }
        break;
        case 6:
            if(index=5)
            {
                System.out.print(Project[5]);
            }
        break;
        case 7:
            if(index=6)
            {
                System.out.print(Project[6]);
            }
        break;
        case 8:
            if(index=7)
            {
                System.out.print(Project[7]);
            }
        break;
        case 9:
            if(index=8)
            {
                System.out.print(Project[8]);
            }
        break;
        case 10:
            if(index=9)
            {
                System.out.print(Project[9]);
            }
        break;
        case 11:
            if(index=10)
            {
                System.out.print(Project[10]);
            }
        break;
    }
}

can anybody explain to me why case 1 is getting an orphaned case error?

Line 12 you appear to be trying to declare a new int inside the switch - obviously an error.

Anyway, each case looks like

switch (index) ...
    case n:
      if (index == (n-1)) ...

so you can guarantee that every if test will be false and nothing will ever be printed.
It's not clear why you are using a switch anyway - it looks like you simply mean

System.out.print(Project[index]);

logical errors tout court:

switch (int index) {
        case 1:
            if(index=0)

do you know what a switch and an if is? do you know the difference between = and == ?

what exactly are you trying to do in these three lines?

I guess this is wat you are looking for:

public int getArrayValue(int index){
    System.out.println(Project[index-1]);
}

use either switch or if else ladder to get desired output.
Don't use both.

sorry before,,,,,as a newbie,,,,i wanna ask you mr.aravind326 on your reply above,,, exactly on this code

`1. public int getArrayValue(int index){
 2.   System.out.println(Project[index-1]);
 3. }`

why did you put System.out.println on a method that have a return value?,,,,
will it have a problem when it is compiled or not?,,,,,,,
why didn't you put a variable or etc that return the value as return blablabla; on your method that have a data primitive type (int)?

CMIIW :)

Ah. yes...

It would have a problem as there is no return statement.

I just was trying to focus on the point being "Project[index-1]" holds the desired value.

Thanks for pointing it out. My bad. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.