-1
    String name;
String count;
Scanner keyboardn = new Scanner(System.in);
Scanner keyboard = new Scanner(System.in);
System.out.println("Enter Full Product Name");
name = keyboard.nextLine();
count = keyboard.nextLine();
String [] p = name.split(" ");
for(String s : p) { 
    if (count == "1"){  System.out.println(p[0]);}
    if (count == "2"){  System.out.println(p[1]);}
    if (count == "3"){System.out.println(p[1]);}
    if (count == "4"){System.out.println(p[1]);}
    if (count == "5"){System.out.println(p[1]);}
    if (count == "6"){System.out.println(p[1]);}
    if (count == "7"){System.out.println(p[1]);}
    if (count == "8"){System.out.println(p[1]);}
    if (count == "9"){System.out.println(p[1]);}
    if (count == "10"){System.out.println(p[0]+", "+p[1]+", "+ p[2]+", "+p[3]+", "+p[4]+", "+p[5]+", "+p[6]+", "+p[7]+", "+p[8]+", "
                + ""+p[9]+", "+p[1]+p[2]+", "+p[1]+p[2]+p[4]+", "+p[1]+p[2]+p[4]+p[5]+", "  );
    }
}

the program is not out puting any response using if statments i thought would work the best let me know if there are any other sugestions

Sotirios Delimanolis
  • 274,122
  • 60
  • 696
  • 724
Robbie
  • 3
  • 1
  • 1
  • 3

1 Answers1

1

You've declared count as a String. You need to either declare it as an int or use count.equals("1"). You can not compare Strings in Java using ==.

nhgrif
  • 61,578
  • 25
  • 134
  • 173
  • 3
    You can, you just have to really know what you're doing ;) In principal I agree though, you shouldn't do this. – Amir Afghani Sep 26 '13 at 03:24
  • 2
    Well, you CAN... but the `String` variables are simply pointers, and the `==` just check to see if they point to the same memory address, not whether or not the contents of two strings are equal (regardless of their locations in memory). – nhgrif Sep 26 '13 at 03:26