My first Java Program

My first Java Program

I have been caught with a practical exam to do the following:

  1. Write a program that takes input from a user through the command line.
  2. The user must be prompt to enter a sentence (anything). The sentence may not be less that 100 characters, else, you must ask the user to enter the sentence again of 100 characters.
  3. Take the user input break it up into different lines: 3.1 Each line that you write out may not more than 20 characters 3.3 You may not "cut off" any words in the middle

I can be able to code step 1, but I can not the number 2, and 3,

Kindly assist.

SK.

View Answers

January 23, 2013 at 7:13 PM

hi friend try this code may this helpful for you.

public class CommandLineInput
{
public static String newline = System.getProperty("line.separator");
    public static void main(String args[])
      {          
          if(args.length <= 0)
            {
                System.out.println("Enter 100 words");                
            }
          else if(args.length < 100)
            {
                System.out.println("Enter at least 100 words");
            }
           else
            {
                 for(int i=0; i < args.length; i++)
                    {                          
                int r = i%20;            
                          if(r == 0)
                            {
           String str = args[i];
           System.out.print(args[i]+newline);
                                /*String[] tokens = str.split(" ");
                                for(int k=0; k<tokens.length; k++)
                                  {
                                     System.out.println(tokens[k]);
                                  }
            */
                            }
                else
                            {
                                  System.out.print(args[i]);
        }                   

                    }
    }// else closed

      }// main closed
}// class closed

Ads









Related Tutorials/Questions & Answers:
My first Java Program
My first Java Program  I have been caught with a practical exam to do the following: Write a program that takes input from a user through the command line. The user must be prompt to enter a sentence (anything). The sentence
My first struts 2 program
My first struts 2 program  Hi, Please help me for my first struts 2... from one page to another. Details: I am trying my first Struts 2 example program. I want to pass values from first loginpage.jsp to displaypage.jsp. I
Advertisements
Java Program MY NAME
Java Program MY NAME   Write a class that displays your first name vertically down the screen where each letter uses up to 5 rows by 5 columns of a character input by you with a blank line between each letter. Note: each letter
How to create first Java Program?
How to create first Java Program?  Hi, I am beginner and I want to write first Java program. How I can setup my machine and write first Java program... on creating First Java Program Thanks   HI, Here are the steps to write
How to create first program in Java?
How to create first program in Java?  Hi, I am new in Java programming. Tell me How to create first program in Java? Thanks   Hi, Read more at First Java Program. Thanks
First Java Program Example
First Java Program Example In this section we will discuss about the first java program example. To create a Java program we would be required to create... your first program in Java. In this example I have created a simple class named
First Java Program
First Java Program       In this section you will learn how to develop your first Java program... Machine.  You can write a Hello World program as your first Java
First Java Program
your first Java program. In Java, all source code is written in plain text file... Machine. You can write a Hello World program as your first Java program. To write... and using java command, you can interpret and run the program as shown on your
I need add my java program with a picture.
I need add my java program with a picture.  Good evng Frnds Friends i created 1 jar file in my desktop. I need add this program with 1 picture. Whenever the user double clicking on that picture The program must start instead
java program for me to see who are on my server
java program for me to see who are on my server  Hello, Im a beginner in java, doing some tutorials and stuff. I wanna write a java program to put on my server where i wanna see if like 3 people are on my server PLUS that i want
Hello world (First java program)
Hello world (First java program)   ... for compiling and running. Hello world program is the first step of java... and it is used to develop the robust application. Java application program
ModuleNotFoundError: No module named 'my-first'
ModuleNotFoundError: No module named 'my-first'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'my-first' How to remove the ModuleNotFoundError: No module named 'my-first
ModuleNotFoundError: No module named 'my-first'
ModuleNotFoundError: No module named 'my-first'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'my-first' How to remove the ModuleNotFoundError: No module named 'my-first
ModuleNotFoundError: No module named 'first_program'
ModuleNotFoundError: No module named 'first_program'  Hi, My... 'first_program' How to remove the ModuleNotFoundError: No module named 'first_program' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'first_program'
ModuleNotFoundError: No module named 'first_program'  Hi, My... 'first_program' How to remove the ModuleNotFoundError: No module named 'first_program' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'my-first-code-in-python'
ModuleNotFoundError: No module named 'my-first-code-in-python'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'my-first-code-in-python' How to remove the ModuleNotFoundError
ModuleNotFoundError: No module named 'my-first-app'
ModuleNotFoundError: No module named 'my-first-app'  Hi, My Python... 'my-first-app' How to remove the ModuleNotFoundError: No module named 'my-first-app' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'My-First-BOT'
ModuleNotFoundError: No module named 'My-First-BOT'  Hi, My Python... 'My-First-BOT' How to remove the ModuleNotFoundError: No module named 'My-First-BOT' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'my-first-code-in-python'
ModuleNotFoundError: No module named 'my-first-code-in-python'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'my-first-code-in-python' How to remove the ModuleNotFoundError
ModuleNotFoundError: No module named 'my-first-app'
ModuleNotFoundError: No module named 'my-first-app'  Hi, My Python... 'my-first-app' How to remove the ModuleNotFoundError: No module named 'my-first-app' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'My-First-BOT'
ModuleNotFoundError: No module named 'My-First-BOT'  Hi, My Python... 'My-First-BOT' How to remove the ModuleNotFoundError: No module named 'My-First-BOT' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'my-first-helloworld-script'
ModuleNotFoundError: No module named 'my-first-helloworld-script'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'my-first-helloworld-script' How to remove
ModuleNotFoundError: No module named 'my_first_module'
ModuleNotFoundError: No module named 'my_first_module'  Hi, My... named 'my_first_module' How to remove the ModuleNotFoundError: No module named 'my_first_module' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'my_first_package'
ModuleNotFoundError: No module named 'my_first_package'  Hi, My... named 'my_first_package' How to remove the ModuleNotFoundError: No module named 'my_first_package' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'my_first_python_app'
ModuleNotFoundError: No module named 'my_first_python_app'  Hi, My... named 'my_first_python_app' How to remove the ModuleNotFoundError: No module named 'my_first_python_app' error? Thanks   Hi
ModuleNotFoundError: No module named 'my_first_python_app'
ModuleNotFoundError: No module named 'my_first_python_app'  Hi, My... named 'my_first_python_app' How to remove the ModuleNotFoundError: No module named 'my_first_python_app' error? Thanks   Hi
ModuleNotFoundError: No module named 'my-first-python-library'
ModuleNotFoundError: No module named 'my-first-python-library'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'my-first-python-library' How to remove the ModuleNotFoundError
ModuleNotFoundError: No module named 'my_first_submission_test'
ModuleNotFoundError: No module named 'my_first_submission_test'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'my_first_submission_test' How to remove
ModuleNotFoundError: No module named 'My-first-python-package'
ModuleNotFoundError: No module named 'My-first-python-package'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'My-first-python-package' How to remove the ModuleNotFoundError
ModuleNotFoundError: No module named 'my-first-test'
ModuleNotFoundError: No module named 'my-first-test'  Hi, My... 'my-first-test' How to remove the ModuleNotFoundError: No module named 'my-first-test' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'my_first_submission_test'
ModuleNotFoundError: No module named 'my_first_submission_test'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'my_first_submission_test' How to remove

Ads