Saturday, August 16, 2014

NETBEANS Java Basics 105 – String And Char

NETBEANS Java Basics 105 – String and Character

PREREQUISITE

Download NetBeans from https://netbeans.org/downloads/ 

STEPS

1) Open the Startup Project.

package firstproject;
public class FirstProject {
    public static void main(String[] args) {
        // TODO code application logic here
    }  
}

2) EDIT THE CODES.

2-1) Add:
a) String variable declaration statement.
b) String variable assignment statement.
c) Output statement. 
package firstproject;
public class FirstProject {
    public static void main(String[] args) {
                String first_name;
                first_name = "William";
                System.out.println(first_name);
    }  
}
2-2) Run.
2-3) Add:
a) A Character variable declaration and init statement, and
b) A String variable declaration and init statement.
package firstproject;
public class FirstProject {
    public static void main(String[] args) {
                String first_name;
                first_name = "William";
                System.out.println(first_name);
                char wordSeparator=',';
                String family_name = "H";
    }  
}
2-4) Edit:
Include the new variables into the Output Statement.
package firstproject;
public class FirstProject {
    public static void main(String[] args) {
                String first_name;
                first_name = "William";
                System.out.println(first_name);
                char wordSeparator=',';
                String family_name = "H";
                System.out.println(first_name+wordSeparator+family_name);
    }  
}
2-5) Run.

3) STRING/CHARACTER VALUE CONVERSION AND OUTPUT

3-1) Add the following variable declaration statements and output statement.
package firstproject;
public class FirstProject {
    public static void main(String[] args) {
                String first_name;
                first_name = "William";
                System.out.println(first_name);
                char wordSeparator=',';
                String family_name = "H";
                System.out.println(first_name+wordSeparator+family_name);
                char char_letter=first_name.charAt(0);
                String string_letter=Character.toString(char_letter);
                System.out.println(char_letter);
                System.out.println(string_letter);
    }  
}
3-2) Run.
3-3) Add the following output statement at the end of the above codes.
package firstproject;
public class FirstProject {
    public static void main(String[] args) {
                String first_name;
                first_name = "William";
                System.out.println(first_name);
                char wordSeparator=',';
                String family_name = "H";
                System.out.println(first_name+wordSeparator+family_name);
                char char_letter=first_name.charAt(0);
                String string_letter=Character.toString(char_letter);
                System.out.println(char_letter);
                System.out.println(string_letter);
                System.out.println(char_letter+wordSeparator+string_letter);
    }  
}
3-4) Run. What is the outcome?
3-5) Add another output statement at the end of the above codes.
package firstproject;
public class FirstProject {
    public static void main(String[] args) {
                String first_name;
                first_name = "William";
                System.out.println(first_name);
                char wordSeparator=',';
                String family_name = "H";
                System.out.println(first_name+wordSeparator+family_name);
                char char_letter=first_name.charAt(0);
                String string_letter=Character.toString(char_letter);
                System.out.println(char_letter);
                System.out.println(string_letter);
                System.out.println(char_letter+wordSeparator+string_letter);
                System.out.println(""+char_letter+wordSeparator+string_letter);
    }  
}
3-6) Run. What is the outcome?

REFERENCE

No comments:

Post a Comment