字符串使用system.out.println时出错

时间:2017-04-04 20:52:41

标签: java

这是我的代码

import java.util.Scanner; //needed to use Scanner for input
public class Pandora {
public static void main(String[] args) {

//Declare variables
String lastName = ""; 
String newChannel = "";
int Selection=0;

//Create a Scanner object
Scanner input = new Scanner(System.in);


//Display the Opening Statement which includes the Pandora Menu
System.out.println("******WELCOME TO PANDORA!*******" );
System.out.println(" Pandora Menu:" );
System.out.println(" 1- Create New Pandora Channel" );
System.out.println(" 2- Play Pandora Channel" );
System.out.println(" 3 -Exit Pandora" );


//Prompt the user for their last name and menu choice option
System.out.print("Please Input last Name and Menu Choice");


//Read the user's lastname and read the user's menu choice; Parse string if          necessary!
lastName = input.nextLine();
Selection = input.nextInt();


//Convert last name to uppercase
lastName = lastName.toUpperCase(); 
input.nextLine();
//Control statement (if()/else if() or switch()) that is based on the user's menu choice
//process the user's menu choice (options: 1, 2, 3, other)
                if (Selection == 1){
                                System.out.println(" You have selected the   CREATE   NEW PANDORA CHANNEL menu item!");
                            System.out.println(" Please enter the name of the New Channel:");
                            newChannel = input.nextLine();
                            newChannel = newChannel.toUpperCase();
                          System.out.println( " You have successfully created the following Pandora Channel:)"+newChannel = newChannel.toUpperCase();

            }else if (Selection == 2){

                System.out.println("You have selected the PLAY PANDORA CHANNEL menu item!");
                System.out.println("The user:currently has the following channels");
                System.out.println(" 1- Justin Bieber");
                System.out.println(" 2- Heartland");
                System.out.println(" 3- Carrie Underwood");
                System.out.println(" 4- The Band Perry");
                System.out.println(" 5- Kelly Clarkson");
                System.out.println(" 6- Florida Georgia Line");
                System.out.println(" 7- Blake Shelton");
                System.out.println(" 8- Rihanna");
                System.out.println(" 9- Daughtry");
                System.out.println(" 10- Ashley Tisdale");
            //Prompt the user for their selection  
                System.out.print("\n Which channel would you like to listen to? (Enter 1, 2, 3, 4, 5, 6, 7, 8, 9 , or 10): ");
                int selection = input.nextInt();
                switch(selection){

                case 1:  System.out.println("You are now listening to: Justin Beiber");
                                    break;
                            case 2:  System.out.println(" You are now listening to: Heartland");
                                    break;
                            case 3:  System.out.println(" You are now listening to: Carrie Underwood");
                                    break;
                            case 4:  System.out.println(" You are now listening to: The Band Perry");
                                    break;
                            case 5:  System.out.println(" You are now listening to: Kelly Clarkson");
                                    break;
                            case 6:  System.out.println(" You are now listening to: Florida Georgia Line");
                                    break;
                            case 7:  System.out.println(" You are now listening to: Blake Shelton");
                                    break;
                            case 8:  System.out.println(" You are now listening to: Rihanna");
                                    break;
                            case 9:  System.out.println(" You are now listening to: Daughtry");
                                    break;
                            case 10:  System.out.println(" You are now listening to: Ashley Tisdale");
                                    break;

                            default:  System.out.println("Incorrect Selection");
                                    break;

                }
             System.out.println(lastName = lastName.toUpperCase() +" Thank you being a valued listener!" );
            }else if (Selection == 3) {
            System.out.println("You have selected the EXIT PANDORA menu item");
            System.out.println(lastName = lastName.toUpperCase() +" Thank you being a valued listener!" );
            }else{
            System.out.println(Selection + "is not a valid selection. Please try again.");
            System.out.println(lastName = lastName.toUpperCase() +" Thank you being a valued listener!" );
            //Display Thank you message
            System.out.println("*******GOODBYE PANDORA LISTENER*******");
            }
}
}//end of class

而且这是我得到的错误 Pandora.java:41:错误:')'预计                               System.out.println(“您已成功创建以下Pandora频道:)”+ newChannel = newChannel.toUpperCase();

3 个答案:

答案 0 :(得分:1)

愚蠢的语法错误。错误日志说它全部使用

array

而不是

System.out.println( " You have successfully created the following Pandora Channel: "+ newChannel );

答案 1 :(得分:0)

您在第41行的打印行语句中缺少右括号。您需要a)

之后
...newChannel.toUpperCase();
像这样

...newChannel.toUpperCase());

答案 2 :(得分:0)

您需要println方法的右括号,其中您打印“您已成功创建以下Pandora频道”+其他一些内容。这是对您的错误消息的解释。

此外,您可以将该行更改为:

System.out.println( " You have successfully created the following Pandora Channel:)" + newChannel.toUpperCase());