如何定位这个java while循环?

时间:2017-04-21 04:18:40

标签: java while-loop

所以while循环不起作用,即使它编译。我该如何正确定位?

我尝试了一些东西,但他们有点工作。如果有人在这里可以帮助我,这将是伟大的

let bodyFontDescriptor = UIFontDescriptor.preferredFontDescriptor(withTextStyle: .body)
// This isn’t working either: let bodyFontDescriptor = UIFont.preferredFont(forTextStyle: .body).fontDescriptor
let oneStoreyAFontDescriptor = bodyFontDescriptor.addingAttributes(
    [
        UIFontDescriptorFeatureSettingsAttribute:
        [
            [
                UIFontFeatureTypeIdentifierKey: kStylisticAlternativesType,
                UIFontFeatureSelectorIdentifierKey: kStylisticAltSevenOnSelector
            ]
        ]
    ]
)
textView.font = UIFont(descriptor: oneStoreyAFontDescriptor, size: 0.0)

这是学生班:

import java.util.Scanner;
//This is a Driver program to test the external Class named Student
public class StudentDriver //BEGIN Class Definition
{
   //****************  Main Method*************************
   public static void main (String[] args)
   {Scanner scan = new Scanner(System.in);
   //Data Definitions:
   //Instance Data
   String courseName;
   int courseCredits;

   String name;
   String id;
   String street;
   String city;
   String state;
   String zip;
   String major;

   //Executable Statements:
   //Initialize first Student
   name = "Fred Fergel";
   id = "0123";
   street = "123 Main Street";
   city = "Smalltown";
   state = "NY";
   zip = "12345";
   major = "Computer Science";
   //instantiate the Student object
   Student student1 = new Student(name, id, street, city, state, zip, major);
   //Test toString
   System.out.println("Student 1\n\n" + student1.toString());
   //Print a blank line
   System.out.println();
   //Add a course
   student1.addCourse("CSC111", 4);//NOTE:  DO NOT PUT A SPACE BETWEEN CSC AND 111
   //Print schedule
   System.out.println("Student 1's Schedule:\n\n");
   student1.displaySchedule();//call method

    final String FLAG = "Y";
     String prompt = "Y";
   while (prompt.equals("y"))
   {
   System.out.println("Please enter the name of the course: ");
   courseName = scan.next();
   System.out.println("How many credits is the course? ");
   courseCredits = scan.nextInt();
   student1.addCourse(courseName, courseCredits);
   System.out.println("Do you wish to enter another course? y/n");
   prompt = scan.next();
   }
   //end while


   }//end main
}//end StudentDriver

1 个答案:

答案 0 :(得分:3)

String prompt = "Y";
while (prompt.equals("y"))

Y和y不是一回事。如果您希望忽略大小写,则需要使用.equalsIgnoreCase()而不是.equals()