Question

The scanner takes the name of a text file from the command line. It outputs to the console error if there is any non-valid to

56 Chapter 2 Programming Language Syntax co homecene (a) base case O G O (6) smertention a o (b) concatenation AB (c) alterna

Would you please do Pseudocode for this progarm in Java??

Using scanner algorithm, The scanner takes the name of a text file from the command line and prints out the list of tokens. If there is non-valid token in the input file, print out “error”.

please help me to write Pseudocode!

thank you!!

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

Hi dear,

Here I am providing you both pseudo code and sample program

1. Pass text. txt file as an command line argument while running java jar file.

2.Declare scanner class object inside the main method block, and get argument string from the formal parameter of main method.

3.Finally, pass that string in scanner class object that indicates specified path to read content from the file.

4. Take while loop and check condition input file have next token or not. If have new token to read then store that word in string array.

5.close the scanner class object.

Sample program.

class ScannerAlgorithm{

public static void main (String args[]) {

Scanner scanner=new Scanner (args[0]) ;

String []tokens;

int i=0;

While(scanner.hasNextline()) {

System. out. println (scanner.next()) ;

tokens [i++]=scanner.next() ;

}

scanner. close () ;}

}

Add a comment
Know the answer?
Add Answer to:
Would you please do Pseudocode for this progarm in Java?? Using scanner algorithm, The scanner takes...
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
  • Please Do it In Java: Objectives: To Java programming language To understand the lexical analysis phase...

    Please Do it In Java: Objectives: To Java programming language To understand the lexical analysis phase of program compilation Assignment: The first phase of compilation is called scanning or lexical analysis. This phase interprets the input program as a sequence of characters and produces a sequence of tokens, which will be used by the parser. Write a Java, program that implements a simple scanner for a source file given as a command-line argument. The format of the tokens is described...

  • For this assignment, you will use your knowledge of arrays and ArrayLists to write a Java...

    For this assignment, you will use your knowledge of arrays and ArrayLists to write a Java program that will input a file of sentences and output a report showing the tokens and shingles (defined below) for each sentence. Templates are provided below for implementing the program as two separate files: a test driver class containing the main() method, and a sentence utilities class that computes the tokens and shingles, and reports their values. The test driver template already implements accepting...

  • Submit Chapter6.java with a public static method named justifyText that accepts two parameters; a Scanner representing...

    Submit Chapter6.java with a public static method named justifyText that accepts two parameters; a Scanner representing a file as the first parameter, and an int width specifying the output text width. Your method writes the text file contents to the console in full justification form (I'm sure you've seen this in Microsoft Word full.docx ).  For example, if a Scanner is reading an input file containing the following text: Four score and seven years ago our fathers brought forth on this...

  • The following code uses a Scanner object to read a text file called dogYears.txt. Notice that...

    The following code uses a Scanner object to read a text file called dogYears.txt. Notice that each line of this file contains a dog's name followed by an age. The program then outputs this data to the console. The output looks like this: Tippy 2 Rex 7 Desdemona 5 1. Your task is to use the Scanner methods that will initialize the variables name1, name2, name3, age1, age2, age3 so that the execution of the three println statements below will...

  • Need help understanding this question from CodeStepByStep in Java, any help is appreciated! Write a method...

    Need help understanding this question from CodeStepByStep in Java, any help is appreciated! Write a method named coinFlip that accepts as its parameter a string holding a file name, opens that file and reads its contents as a sequence of whitespace-separated tokens. Assume that the input file data represents results of sets of coin flips. A coin flip is either the letter H or T, or the word Heads or Tails, in either upper or lower case, separated by at...

  • Homework description::::: Write JAVA program with following description. Sample output with code will be helful... A...

    Homework description::::: Write JAVA program with following description. Sample output with code will be helful... A compiler must examine tokens in a program and decide whether they are reserved words in the Java language, or identifiers defined by the user. Design a program that reads a Java program and makes a list of all the identifiers along with the number of occurrences of each identifier in the source code. To do this, you should make use of a dictionary. The...

  • (Java) Rewrite the following exercise below to read inputs from a file and write the output...

    (Java) Rewrite the following exercise below to read inputs from a file and write the output of your program in a text file. Ask the user to enter the input filename. Use try-catch when reading the file. Ask the user to enter a text file name to write the output in it. You may use the try-with-resources syntax. An example to get an idea but you need to have your own design: try ( // Create input files Scanner input...

  • Hello, Could you please input validate this code so that the code prints an error message...

    Hello, Could you please input validate this code so that the code prints an error message if the user enters in floating point numbers or characters or ANYTHING but VALID ints? And then could you please post a picture of the output testing it to make sure it works? * Write a method called evenNumbers that accepts a Scanner * reading input from a file with a series of integers, and * report various statistics about the integers to the...

  • 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...

  • If i could get any guidance on how to get this started it will be great....

    If i could get any guidance on how to get this started it will be great. My prof. literally just gave us the information below (which are literally just instructions) and I am unsure on how to get started. For this assignment we are going to create a function that reads an input stream and classifies it into “tokens” from a language that we define here. In this language we make the following rules: ● An identifier is a letter...

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
ADVERTISEMENT