CodeGym /ื‘ืœื•ื’ Java /Random-HE /ืื™ืš ืžืฉื™ื’ื™ื ืชื• ืงื• ื—ื“ืฉ ื‘ื’'ืื•ื•ื”?
John Squirrels
ืจึธืžึธื”
San Francisco

ืื™ืš ืžืฉื™ื’ื™ื ืชื• ืงื• ื—ื“ืฉ ื‘ื’'ืื•ื•ื”?

ืคื•ืจืกื ื‘ืงื‘ื•ืฆื”

ืžื”ื ื”ืชื•ื•ื™ื ื”ื—ื“ืฉื™ื ื‘-Java?

ื”ืชื•ื•ื™ื ื”ืฉืžื•ืจื™ื "\n" ืื• "\r\n" ื‘-Java ื ืงืจืื™ื ืชื•ื•ื™ ื”ืฉื•ืจื” ื”ื—ื“ืฉื”.
ื‘-Java, ืงื™ื™ืžื•ืช ืžื™ืœื•ืช ืžืคืชื— ืœื‘ื™ืฆื•ืข ืคื•ื ืงืฆื™ื•ืช ืกืคืฆื™ืคื™ื•ืช. ืœื“ื•ื’ืžื”, ืฉื™ืžื•ืฉ ื‘ืžื™ืœืช ื”ืžืคืชื— " int " ื™ื”ืคื•ืš ืืช ืกื•ื’ ื”ื ืชื•ื ื™ื ืฉืœ ืžืฉืชื ื” ืœืžืกืคืจ ืฉืœื . ื‘ืื•ืคืŸ ื“ื•ืžื”, ื‘ืืžืฆืขื•ืช " \n " ืื• " \r\n " ื‘ื–ืžืŸ ื”ื“ืคืกืช ืžื—ืจื•ื–ืช ื›ืœืฉื”ื™ ื‘-Java, " ืงื• ื ื˜ื•ื™ n " ืœื ื™ื•ื“ืคืก. ื‘ืžืงื•ื ื–ืืช, ืžืขื‘ืจ ืฉื•ืจื” ื—ื“ืฉ ื™ื•ื“ืคืก ื‘ืงื•ื ืกื•ืœื” .

ืžื” ืžื“ืคื™ืก "\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 ื”ื™ื ื”ื“ืจืš ืœืœื›ืช!

ืกื™ื›ื•ื

ืขื“ ืขื›ืฉื™ื• ืืชื” ืืžื•ืจ ืœื”ื™ื•ืช ื‘ื ื•ื— ืขื ื”ืฉื™ืžื•ืฉ ื‘ืชื•ื•ื™ ื”ืฉื•ืจื” ื”ื—ื“ืฉื” ื‘-Java. ืœืฉืœื™ื˜ื” ืžืขืžื™ืงื” ื™ื•ืชืจ ื‘ื ื•ืฉื, ืื ื• ืžืžืœื™ืฆื™ื ืœืš ืœื”ืžืฉื™ืš ืœื”ืชืืžืŸ ืขื ื”ืชื•ื•ื™ื ื”ื—ื“ืฉื™ื ื‘ืฉื•ืจื” ื‘-Strings ื‘-Java. ื‘ื”ืฆืœื—ื” ื•ืœืžื™ื“ื” ืžื”ื ื”!
ื”ืขืจื•ืช
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION