Sunday, January 18, 2015

JAVA String

Java String

June 2014. This month marked one year since I went to take that summer course in Beginning Java.

About this time, I was continuing into my next stint tutoring programming in college. The summer course was only 2 months long, and there were more students wanting to learn about Microsoft’s software, particularly Word and Excel. The students had to take their IC3 examinations and most of the students who were going to the Tutorial Lab needed some help in passing their exams.

This was the first time the college has a summer tutoring for programming. One or some of the tutees I had tutored in Microsoft’s software wrote the Tutorial Services some impressive comments that the Director asked me if I was interested in doing tutoring during the summer. Since I had nothing else to do, of course, I said yes.

For the summer tutoring sessions, I wrote a Python program as a sign-in sheet for the students going to the Tutorial Lab. It save to a file, including the current time when their name was entered in the file.

Here’s a Java program segment that illustrates how the Java String class is used. This program segment is capable of authenticating an email address and the corresponding password that are entered by the user.

    String[] emails = {"ant", "bat", "cat"};   
    String[] passwords = {"aa", "bb", "cc"};

    Scanner keyboard = new Scanner(System.in);
    System.out.print("Enter your email address: ");
    String response1 = keyboard.nextLine();
    System.out.print("Enter your password: ");
    String response2 = keyboard.nextLine();
    for (int index = 0; index < emails.length; index++) {
      if (emails[index].compareToIgnoreCase(response1) == 0) {
        if (passwords[index].equals(response2)) {
          System.out.println("You may proceed");
          break;
        }
      }
      if (index >= emails.length - 1) {
        System.out.println("Incorrect email or password");
        break;
      }
      else
        continue;
    }

CYK:
Is a Java string immutable?
What's the length of an empty string?
What data type holds single precision value?

Happy computing!

John Sindayen

1 comment:

  1. JAVA String which is a class in lang package of JAVA. Online Java Course

    Java Online Training Strings are immutable which cannot be changed and so we are moving to String Buffer and String Builders

    ReplyDelete