REMEMBER JAVA

MINTE9
2REMEMBER




Multilines

Java does not permit strings to span lines. You must use + concatenation operator at the end of each line.
 RunCode
class LearningApp {

    public static void main(String[] args) {
        
        String quote = "Now is the time for all good " +
            "men to come to the aid of their country.";

        System.out.println(quote);
    }
}
... 7 lines
˄˄˄

Converting

Conveting Strings to Numbers
 RunCode
class LearningApp {

    public static void main(String[] args) {
        
        String a1 = "1";
        String a2 = "1.11";

        Integer b1 = Integer.valueOf(a1);
        Float b2 = Float.valueOf(a2);

        System.out.println(b1 + b2); // 2.1100001
    }
}
... 9 lines
˄˄˄
Converting Numbers to Strings.
 RunCode
class LearningApp {

    public static void main(String[] args) {
        
        int i = 11;
        String s = "";

        s = "" + i; // or
        s = String.valueOf(i);
        s = Integer.toString(i);

        System.out.println(s); // 11
    }
}
... 10 lines
˄˄˄

Padding

Use String.format() for padding strings.
 RunCode
public class LearningApp {

    public static void main(String[] args) {
        
        /**
         * padding Left
         */
        String a = String.format("%6s", "123").replace(" ", "0");
        System.out.println(a); // 000123

        /**
         * padding Right
         */
        String b = String.format("%-6s", "123").replace(" ", "0");
        System.out.println(b); // 123000
    }
}
... 14 lines
˄˄˄
Task

 CompleteTask
class LearningApp {

    public static void main(String[] args) {
        
        /**
         * Define a string s1 = "1"
         * Define a number n1 = 2
         * Display the sum of s1 + n1 = 3
         * (convert the string to number)
         */
        
        ...
    }
}
solution code
Questions    
No. 8   Inheritance
CARD
07
63

        A B C D E F
🔔
1/2