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









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... how to write your first program in Java. In this example I have created
details of my program - Java Beginners
details of my program  hi 1- allow the customer to order any thing... want to give a report for the whole saled stuff in 2 days (First and second... array but it could make the program much longer note: i want to use the method
First Java Program
First Java Program       In this section you will learn how to develop your first Java program... first Java program. Hello world program is the first step of 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... the java HelloWorld.java command and to execute the program use java
How to Run First Java Bean Program ?
How to Run First Java Bean Program ?  Hi My Dear Friend I can run many Java Programs Like, Applet,Swing,RMI ,Socket Programming and Java Servlet too But Now I need that How to run Java Bean Now I have BDK1.1 But still don't
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
doubt in my program code - Java Beginners
doubt in my program code  i have developed a web browser with the help of standard widget toolkit(swt) and java. i creted some buttons such as GO,REFRESH,STOP.... on which the name is not apppeared as GO,STOP...but the name
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
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 '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-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-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-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
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
Hello world (First java program)
Hello world (First java program) - Learning to write your first Java program.... Java application program is platform independent and can be run on any... is the first step of java programming  language. Be careful when you write
program to display the first ten terms of the series
program to display the first ten terms of the series  Write a program to display the first ten terms of the following series : 1) 1,-3,5,-7,9..... 2) 3,6,12,24..... 3) 2,5,10,17....... 4) 0,1,2,3,6............ 5) 0,3,8,15
ModuleNotFoundError: No module named 'my-first-lib-edward-colo'
ModuleNotFoundError: No module named 'my-first-lib-edward-colo'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'my-first-lib-edward-colo' How to remove
ModuleNotFoundError: No module named 'my-first-python-package-cdelacombaz'
ModuleNotFoundError: No module named 'my-first-python-package-cdelacombaz'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'my-first-python-package-cdelacombaz' How to remove
ModuleNotFoundError: No module named 'my-first-python-package-cdelacombaz'
ModuleNotFoundError: No module named 'my-first-python-package-cdelacombaz'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'my-first-python-package-cdelacombaz' How to remove
First Program
Now, lets move ahead for printing the first and most simple & common...;font color= “blue”>My PHP code makes this page say:</font>..., your computer name is your root URL. For instance, the name of my computer
Problem in running first hibernate program.... - Hibernate
Problem in running first hibernate program....  Hi...I am using eclipse ganymede and mysql.I have already configured mysql and did few sample programs.It worked fine.To run a hibernate sample program,I followed the tutorial below
ModuleNotFoundError: No module named 'my_print_haha_program'
ModuleNotFoundError: No module named 'my_print_haha_program'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'my_print_haha_program' How to remove the ModuleNotFoundError
Why is my program running an infinite loop? Parallel Arrays Program
Why is my program running an infinite loop? Parallel Arrays Program  Calculate and print the average (this works) Search for Joel in the list, print his data----for some reason this is outputting the wrong data and is outputting
Create First Program
Create First Program     ... program. For developing a java program you just need  a simple text editor...;   Here is the video tutorial of: "Learn Java in a day - Create First
ModuleNotFoundError: No module named 'Companies-classification-first-nanodegree-program-upload'
-program-upload'  Hi, My Python program is throwing following error... named 'Companies-classification-first-nanodegree-program-upload' error... library. You can install Companies-classification-first-nanodegree-program
ModuleNotFoundError: No module named 'Companies-classification-first-nanodegree-program-upload'
-program-upload'  Hi, My Python program is throwing following error... named 'Companies-classification-first-nanodegree-program-upload' error... library. You can install Companies-classification-first-nanodegree-program
ModuleNotFoundError: No module named 'Companies-classification-first-nanodegree-program-upload'
-program-upload'  Hi, My Python program is throwing following error... named 'Companies-classification-first-nanodegree-program-upload' error... library. You can install Companies-classification-first-nanodegree-program
Java Applet - Creating First Applet Example
Java Applet - Creating First Applet Example   ... the applet. An applet is a program written in java programming language... an applet program. Java source of applet is then compiled into java class file and we
i have problem in that program to my assignment sir - JavaMail
i have problem in that program to my assignment sir   Develop a programmer's editor in Java that supports syntax-highlighting, compilation support, debugging support, etc

Ads