ืืื ืืชืืืื ืืืืฉืื ื-Java?
ืื ืืืคืืก "\n" ื-Java?
ืืืื ื ืกืชืื ืขื ืืืืื ืฉื ืืืคืกืช "\n" ืขื ืืืกืืฃ.ืืืืื
public class NewLineChar {
public static void main(String[] args) {
System.out.println("Hi, I am Sponge Bob.\nI just signed up at Code Gym.\nI love the Java learning experience here so far!");
}
}
ืชึฐืคืึผืงึธื
ืืื, ืื ื ืืื ืกืคืื. ืืจืืข ื ืจืฉืืชื ื-Code Gym. ืื ื ืืืื ืืช ืืืืืช ืืืืืื ืฉื Java ืืื ืขื ืื!
ืืืฆื ืืืืกืืฃ ืชื ืืืฉ ืืืืจืืืช?
ืืฉื ื ืืจืืื ืืจืืืืช ืืืืกืืฃ ืืช ืชื ืืฉืืจื ืืืืฉื ืืืืจืืืช. ืืชื ืืืื ืืืฉืชืืฉ ื-"\n" ืื "\r\n" ืืื ืืืืกืืฃ ืืขืืจ ืฉืืจื ืืคืกืงื ืจืฆืืคื. ืืืื ื ืกืชืื ืขื ืืื ืืจืืื ืืขืฉืืช ืืืช.ืืืืื
public class NewLineChar {
public static void main(String[] args) {
// Method 1: newline after every sentence
String sentence1 = "What a beautiful day to be alive!";
String sentence2 = "Let's be thankful for all the blessings we've been showered with.";
String sentence3 = "It only makes sense to be helpful, cooperative and generous to those who are less fortunate.";
// without newline after each sentence
System.out.println("-------Printing without newline character--------");
System.out.println(sentence1 + sentence2 + sentence3);
// newline character after each sentence
System.out.println("\n-------Printing with newline character-----------");
System.out.println(sentence1 + "\n" + sentence2 + "\n" + sentence3);
// Method 2: new line after each paragraph
String paragraph1 = "Java is the most dynamic and easy to plug and play language. It has been transforming lives for more than 2 decades now. It still continues to grow to date.";
String paragraph2 = "If you're a beginner who wants to be a professional in Java, you need to focus on targeted learning with consistent practice. If you're looking for a responsive community to grow with, then Code Gym is the way to go!";
// without newline after each paragraph
System.out.println("\n-------Printing without newline character--------");
System.out.println(paragraph1 + paragraph2);
// new line character after each paragraph
System.out.println("\n-------Printing with newline character-----------");
System.out.println(paragraph1 + "\r\n" + paragraph2);
}
}
ืชึฐืคืึผืงึธื
-------ืืืคืกื ืืื ืืืืช ืืืฉื-------- ืืืื ืืื ืืคื ืืืืืช! ืืืื ื ืืื ืืกืืจื ืชืืื ืขื ืื ืืืจืืืช ืฉืืจืขืืคื ืขืืื ื. ืื ืจืง ืืืืื ื ืืืืืช ืืืขืื, ืืฉืชืฃ ืคืขืืื ืื ืืื ืืื ืฉืคืืืช ืืจ ืืื. -------ืืืคืกื ืขื ืชื ืืืฉ----------- ืืืื ืืื ืืคื ืืืืืช! ืืืื ื ืืื ืขื ืื ืืืจืืืช ืฉืืจืขืืคื ืขืืื ื. ืื ืจืง ืืืืื ื ืืืืืช ืืืขืื, ืืฉืชืฃ ืคืขืืื ืื ืืื ืืื ืฉืคืืืช ืืจื ืืื. -------ืืืคืกื ืืื ืชื ืืืฉ-------- Java ืืื ืืฉืคื ืืืื ืืืช ืืืงืื ืืืืชืจ ืืืืืืจ ืืืืคืขืื. ืื ืืฉื ื ืืืื ืืืจ ืืืชืจ ื-2 ืขืฉืืจืื. ืื ืขืืืื ืืืฉืื ืืฆืืื ืขื ืืืื. ืื ืืชื ืืชืืื ืฉืจืืฆื ืืืืืช ืืงืฆืืขื ื-Java, ืืชื ืฆืจืื ืืืชืืงื ืืืืืื ืืืืงืืช ืขื ืชืจืืื ืขืงืื. ืื ืืชื ืืืคืฉืื ืงืืืื ืืืืื ืืฆืืื ืืืชื, ืื Code Gym ืืื ืืืจื ืืืืช! -------ืืืคืกื ืขื ืชื ืืืฉ----------- Java ืืื ืืฉืคื ืืืื ืืืช ืืืงืื ืืืืชืจ ืืืืืืจ ืืืืคืขืื. ืื ืืฉื ื ืืืื ืืืจ ืืืชืจ ื-2 ืขืฉืืจืื. ืื ืขืืืื ืืืฉืื ืืืืื ืขื ืืืื. ืื ืืชื ืืชืืื ืฉืจืืฆื ืืืืืช ืืงืฆืืขื ื-Java, ืืชื ืฆืจืื ืืืชืืงื ืืืืืื ืืืืงืืช ืขื ืชืจืืื ืขืงืื. ืื ืืชื ืืืคืฉืื ืงืืืื ืืืืื ืืฆืืื ืืืชื, ืื Code Gym ืืื ืืืจื ืืืืช!
GO TO FULL VERSION