Question

What is the newline character in Java? What is white-space in user input? Answer these questions...

  1. What is the newline character in Java?

  2. What is white-space in user input?

  3. Answer these questions for each of these Scanner input methods: next(), nextLine(), nextInt(), nextDouble()?

    (a) Does the method skip white-space to ”look” for the next input value? (b) Does the method return a single word or the rest of the line?

    (c) Does the method leave the data on the input stream or consume it? (d) Does the method leave the newline character on the input stream?

    (e) Does the method return the newline character with the input value?

  4. What happens if you connect PrintWriter to an existing file? Does it fail, overwrite,

    append?

  5. What happens if you do not have write permissions to the file (and path) used to create

    the PrintWriter instance?

0 0
Add a comment Improve this question Transcribed image text
Answer #1

NEWLINE CHARACTER IN JAVA

  • Newline Character used to move the cursor down to the next line without returning to the beginning of the line.
  • It represents the end of a line of a text and beginning of a new line.
  • It is represented as a \n escape sequence.
  • To write a newline character to a file in java \r\n (return and newline).

The newline character was intended to mean "go to the next line" or "advance the paper in the printer one line" This same character was also called a "Line feed" character on other systems.

WHITE SPACE IN USER INPUT

  • White space refers to spaces, tabs and newlines.
  • In some places of code it is necessary whereas mostly it is just given to improve readability.
  • example : void main() (as they are two different words)

ANSWERS

nextLine() method is used to get the input string that was skipped of the Scanner object.It is used to get the input string that was skipped of the Scanner object.

nextInt() It scans the next token of the input as an Int.

nextDouble() is a method of which is used to scan the next token of the input as a double. If the translation is successful, the scanner past the input that matched.

next() can read the input only till the space.It places the cursor in the same line after reading the input.

Java won't create it by itself since the File class is just a link to an entity that can also not exist at all.

FileNotFoundException - If the given string does not denote an existing, writable regular file and a new regular file of that name cannot be created, or if some other error occurs while opening or creating the file

Try creating a path for the folder it contains before:

File file = new File("C:/Users/Me/Desktop/directory/file.txt");
file.getParentFile().mkdirs();
PrintWriter printWriter = new PrintWriter(file);
Add a comment
Know the answer?
Add Answer to:
What is the newline character in Java? What is white-space in user input? Answer these questions...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • The Scanner class in Java has several methods for reading values entered from the keyboard. The...

    The Scanner class in Java has several methods for reading values entered from the keyboard. The methods include next, nextInt, and nextLine. Which of the following statements is INCORRECT about the methods? Pick the best applicable answer Assuming that the user has typed: Hello World! If you invoke the next method for the first time, it will return the string "Hello", and if you invoked next method for the second time, it will return the string "World!" If you want...

  • Create a class named Module2. You should submit your source code file (Module2.java). The Module2 class...

    Create a class named Module2. You should submit your source code file (Module2.java). The Module2 class should contain the following data fields and methods (note that all data and methods are for objects unless specified as being for the entire class) Data fields: A String object named firstName A String object named middleName A String object name lastName Methods: A Module2 constructor method that accepts no parameters and initializes the data fields from 1) to empty Strings (e.g., firstName =...

  • Capitalization JAVA In this program, you will read a file line-by-line. For each line of data...

    Capitalization JAVA In this program, you will read a file line-by-line. For each line of data (a string), you will process the words (or tokens) of that line one at a time. Your program will capitalize each word and print them to the screen separated by a single space. You will then print a single linefeed (i.e., newline character) after processing each line – thus your program will maintain the same line breaks as the input file. Your program should...

  • create a new Java application called "WeightedAvgDataAnalyzer" (without the quotation marks), that modifies the DataAnalyzer.java in...

    create a new Java application called "WeightedAvgDataAnalyzer" (without the quotation marks), that modifies the DataAnalyzer.java in Horstmann Section 7.5, pp. 350-351 according to the specifications below. The input file should be called 'data.txt' and should be created according to the highlighted instructions below. Note that even though you know the name of the input file, you should not hard-code this name into your program. Instead, prompt the user for the name of the input file. The input file should contain...

  • Topics: About Java What is a compiler, and what does it do? Characteristics of the languageStrongly...

    Topics: About Java What is a compiler, and what does it do? Characteristics of the languageStrongly typed and statically typed Everything has a data type & data types must be declared Case sensitive Object oriented System.out.print() vs. System.out.println() How to use the Scanner class to obtain user input Data typesWhat are they? Know the basic types like: int, double, boolean, String, etc. Variables What is a variable? Declarations Initialization Assignment Constants Reserved words like: What is a reserved word? Examples:...

  • In this lab you will write a spell check program. The program has two input files:...

    In this lab you will write a spell check program. The program has two input files: one is the dictionary (a list of valid words) and the other is the document to be spellchecked. The program will read in the words for the dictionary, then will read the document and check whether each word is found in the dictionary. If not, the user will be prompted to leave the word as is or type in a replacement word and add...

  • Consider the following C++ program. It reads a sequence of strings from the user and uses...

    Consider the following C++ program. It reads a sequence of strings from the user and uses "rot13" encryption to generate output strings. Rot13 is an example of the "Caesar cipher" developed 2000 years ago by the Romans. Each letter is rotated 13 places forward to encrypt or decrypt a message. For more information see the rot13 wiki page. #include <iostream> #include <string> using namespace std; char rot13(char ch) { if ((ch >= 'a') && (ch <= 'z')) return char((13 +...

  • Instructions: Consider the following C++ program. It reads a sequence of strings from the user and...

    Instructions: Consider the following C++ program. It reads a sequence of strings from the user and uses "rot13" encryption to generate output strings. Rot13 is an example of the "Caesar cipher" developed 2000 years ago by the Romans. Each letter is rotated 13 places forward to encrypt or decrypt a message. For more information see the rot13 wiki page. #include <iostream> #include <string> using namespace std; char rot13(char ch) { if ((ch >= 'a') && (ch <= 'z')) return char((13...

  • Need help with java programming. Here is what I need to do: Write a Java program...

    Need help with java programming. Here is what I need to do: Write a Java program that could help test programs that use text files. Your program will copy an input file to standard output, but whenever it sees a “$integer”, will replace that variable by a corresponding value in a 2ndfile, which will be called the “variable value file”. The requirements for the assignment: 1.     The input and variable value file are both text files that will be specified in...

  • !!!!!!!Java!!!!! When you are confident that your methods work properly and that you can generate random...

    !!!!!!!Java!!!!! When you are confident that your methods work properly and that you can generate random text with my generateText method, you can move on to the second step. Create a third class called Generator within the cs1410 package. Make class. This class should have a main method that provides a user interface for random text generation. Your interface should work as follows: Main should bring up an input dialog with which the user can enter the desired analysis level...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT