ITM 200 Lecture Notes - Delimiter, Substring

77 views4 pages
yhuJOptionPane.showMessageDialog() method of JOptionPane(class). It has a textbox in which the
user may type in a string (input).
String test=JOptionPane.showInputDialog(“Enter your first integer”);
A input box will appear on the screen asking you to Enter your first integer.
Suspose you type 42 into the text field, when the user presses the OK button, the showInputDialog
method will return with a string of “42”. If you do another input integer of 24 with test2 string, you will
have 42 and 24.
You must convert these string variables into integers in order to do calculations. Therefore, use parse.
Integers: parseInt()
Doubles: parseDouble()
Characters: charAt()
*Note: for charAt(), the position starts at 0. It is required to find the character at a specific position in a
particular string*
String s=”Hello”;
s.charAt(0); is H
s.charAt(1); is E
s.charAt(2); is L
Declare a integer variable (mytest) so you can store the int equilvaent of the String (test1) in the
Int mytest= Integer.parseint(test1);
Primitive Type Variables: float numbers, chars, doubles, and integers = literal values
Reference Types: does not actually contain its associated data but contains a reference to the data (the
address of the location where the data is stored in the computer’s memory) = string variables
Objects: can contain more than one piece of data (so it is possible to over write strings and leave one
string with no value which will eventually be collected by the garbage collector)
Strings are a class, and objects are the reference variables
String Comparisons
+equals(s1:String) boolean = returns true if this string is equal to string s1
String s1= new String("Welcome");
String s2= "Welcome";
1) if (s1.equals(s2)) //s1 and s2 have the same contents
2) if (s1 == s2) //s1 and s2 have the same reference
Unlock document

This preview shows page 1 of the document.
Unlock all 4 pages and 3 million more documents.

Already have an account? Log in

Get OneClass Notes+

Unlimited access to class notes and textbook notes.

YearlyBest Value
75% OFF
$8 USD/m
$30 USD/m
You will be charged $96 USD upfront and auto renewed at the end of each cycle. You may cancel anytime under Payment Settings. For more information, see our Terms and Privacy.
Payments are encrypted using 256-bit SSL. Powered by Stripe.