The method of inputting multi-line data in the Java language for HDU topic

Source: Internet
Author: User

If you are doing HDU 1073,HDU 1075 you will find this problem.

Hey. This is for the novice to see,, after all, this problem let me too tangled, WA did not know how many times, the heart is stuffed.

Later I found that my input method is not right, we can compare the input data, of course, the first two questions I have posted in the blog, you can search the search bar.


Bad input:

Error 1)


Import Java.util.Scanner;

public class p1075 {public
	static void Main (string[] args) {
		Scanner sc = new Scanner (system.in);
		Enter a part of the dictionary
		string s = new string ();
		s = sc.nextline ();//  There may be tabs
		s = sc.nextline ();//overwrite Start row data while
		(!s.equals ("End")) {
			S + = \ n; Line breaks can be displayed in a single line to avoid data not showing
			S + + sc.nextline ();
		}
		System.out.println ("++s++" + s);
	}


No output results----




Error 2)

Import Java.util.Scanner;

public class p1075 {public
	static void Main (string[] args) {
		Scanner sc = new Scanner (system.in);
		Enter a part of the dictionary
		string s = new string ();
		s = sc.nextline ();//  There may be tabs
		s = sc.nextline ();//overwrite Start row data while
		(!s.equals ("End")) {
			S + = \ n; Line breaks can be displayed in a single line to avoid data not showing
			S + + sc.nextline ();
			System.out.println ("1" + s);
		}
		System.out.println ("++s++" + s);
	}


The output is the correct result





Error 3)


Import Java.util.Scanner;

public class p1075 {public
	static void Main (string[] args) {
		Scanner sc = new Scanner (system.in);
		Enter a part of the dictionary
		string s = new string ();
		s = sc.nextline ();//  There may be tabs
		s = sc.nextline ();//overwrite Start row data while
		(!s.equals ("End")) {
			S + = \ n; Line breaks can be displayed in a single line to avoid data not showing
			S + + sc.nextline ();
			System.out.println ("1" + s);
		}
		System.out.println ("++s++" + s);
		Re
		-Enter string s2 = new string ();
		s = Sc.nextline ();
		s = Sc.nextline ();
		while (The!s2.equals ("End")) {
			S2 = = \ n;//can be displayed single-line with a newline character to avoid the data not showing
			s2 + = Sc.nextline ();
		}
		System.out.println ("++s2++" + s2);
	}


Second entry Error




The correct input:


Import Java.util.Scanner;

public class p1075a {public
	static void Main (string[] args) {
		Scanner sc = new Scanner (system.in);
		string S1 = "";//Incoming character
		string a = "";
		S1 = Sc.nextline ();
		S1 = Sc.nextline ();
		int count = 0;
		while (!s1.equals ("End")) {
			if (count!= 0) {
				A + = "\ n";
			}
			count++;
			A + + S1;
			S1 = Sc.nextline ();
		}
		System.out.println ("A:" + a);
	}

}








Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.