Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners My first Java Program
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Sikelela Sigudhla
My first Java Program
1 Answer(s)      3 years and 7 months ago
Posted in : Java Beginners


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.


Advertisement
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 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
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
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
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)   ... and running. Hello world program is the first step of java programming  language... to develop the robust application. Java application program is platform
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
Hello world (First java program)
Hello world (First java program)   .... Hello world program is the first step of java programming  language... to develop the robust application. Java application program is platform independent
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
First Program
Now, lets move ahead for printing the first and most simple & common...;My PHP code makes this page say:</font> 9. 10. <p> 11. 12.<.... For instance, the name of my computer is ‘Deepak’, so I’ll have to type
java not run on my pc
java not run on my pc  i have installed java in pc but when i run and compile any program the massage is display that 'javac' is not recognized as an internal or external command
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
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
Create First Program
Create First Program     ... program. For developing a java program you just need  a simple text editor like... to the directory ("C:\vinod" in this example) where your program is saved. Java
My name, java project
My name, java project  Write a class that displays your first name vertically down the screen ?? where each letter uses up to 5 rows by 5 columns... displayLetterA() { code goes in here }, ...and my names hayley ... anyone
My name, java project
My name, java project  Write a class that displays your first name vertically down the screen ?? where each letter uses up to 5 rows by 5 columns... displayLetterA() { code goes in here }, ...and my names hayley ... anyone
Help With My Java Project?
Help With My Java Project?  Write a console program that repeatedly... the first dimension contains exactly what they type and the second dimension contains the first non-whitespace character of what they type, in lowercase. If they enter
PLEASE HELP WITH MY JAVA
PLEASE HELP WITH MY JAVA  Hey my name is Gavin and im a student at school that takes IT. my teacher has gave me a problem and i can't figure it out please help!!!!!!!! it is a for-loop question: Display the first 5 multiples
First Lambda Expressions in Java
How to create First Lambda Expression in Java? The Lambda Expression is the hot features added to the Java 8. The Lambda expression is the first major... first Lambda expression in Java 8. I am am assuming you have installed the JDK 8
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
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
How to make my first JSP page?
application and run on Tomcat Server. How to create First JSP Page? Java Server Pages... In the first tutorial we will use the JSP expression  for adding the Java...Tutorial of creating your first JSP Page In this tutorial you will learn how
When were generics first introduced in Java?
When were generics first introduced in Java?  Hi, I want to know when were generics first introduced in java?   Generics were introduced to the Java programming language with the release of Java 5.0 in 2014. Check
Java How to Program
Java program on your computer and also how to write and run your first java... the program with the Java executable. Here is the first Java Hello World code... with the tradition Java Hello World app. But first take a look at the various requirements
a Java program
a Java program    Write a Java program to print even numbers from 2 to 1024? Write a Java program to print ? My Name is Mirza? 100 times? Write a Java program to print Fibonacci Series? Write a Java program to reverse a number
 

 

 

DMCA.com