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



Home Answers Viewqa Java-Beginners My first Java Program

Have Programming Question? Ask it here!
 
 
 


Sikelela Sigudhla
My first Java Program
1 Answer(s)      3 years and 2 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
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
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
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
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
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
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
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
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
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
First Program - Do Nothing
Prev: none | Next: Dialog Box Output Java NotesFirst Program - Do Nothing Here is just about the smallest legal program you can write. It starts up, does... // Description: This is the smallest program. It does NOTHING. // File: doNothing
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
Help Me in My Java Work
Help Me in My Java Work  Can you help me please... Write a Java application, to be called GpaCalculator, which will return a grade point average (GPA) when given a range of decimal figures representing a selection of exam marks
this is my code java - Date Calendar
this is my code java  /* * NewJFrame.java * * Created on 11...; jTextField1.setText(months); #### This My problem jTextField2.setText(days); #### This My problem jTextField3.setText(years); #### This My problem how
how to use yield(),join() methods in program.where it is usefull in my program
how to use yield(),join() methods in program.where it is usefull in my program  Hi i am using yield() in my program but the out put i can't... thread with same priority .but in my example i can't findout exact function
how to use yield(),join() methods in program.where it is usefull in my program
how to use yield(),join() methods in program.where it is usefull in my program  Hi i am using yield() in my program but the out put i can't... thread with same priority .but in my example i can't findout exact function
to add on to my queries - Java Beginners
to add on to my queries   Dear Experts, Sorry but I am worried that I did not explain clearly so I am adding in the error message I get from Netbean IDE when I run that queries using the last solution provided. I'm puzzled
clarify my question - Java Beginners
clarify my question  Dear Sirs/Expert, Thanks for writing back. Yes. I want a page to use id of parents to do the search for the match. So... the matching tutors to the parent. I was telling you that my degree
Sample Java program for beginners
Here beginners in Java can learn to create there first Hello World program... of the special class. Java First Example-Hello World: Now we will create our first program..., a programmer is ready to create their own Java program. Here we have also described
java program for
java program for   java program for printing documents,images and cards
Java Program
Java Program  I want the answer for this question. Question: Write a program to calculate and print the sum of odd numbers and the sum of even numbers for the first n natural numbers, where n is given as input from the user
Can someone review my script for an apparent parsing error? -it isn't quite finished yet, but I want to fix error first
Can someone review my script for an apparent parsing error? -it isn't quite finished yet, but I want to fix error first   import java.util.Scanner...;Does anyone know how to get it to be in java format instead of stickint
Addition to my previous post - Java Beginners
Addition to my previous post  Addition to my previous question about the address book program. I need to have separate classes: CmdLineAddressBook.java AddressBook.java Contact.java Address.java Name.java
Java Program
Java Program  A Java Program that print the data on the printer but buttons not to be printed
java program
java program  write a program to print 1234 567 89 10
Writing Simple Java Script Program
Writing Simple Java Script Program   ... of JavaScript and create your first JavaScript program. Creating your first JavaScript Program In the last lesson you learned how to create simple java script
java program
java program  Write a program to create an applet and display The message "welcome to java
java program
java program  java program to implement the reflection of a particular class details like constructor,methods and fields with its modifiers
Java Program
Java Program  java program to insert row in excel sheet after identifying an object
java program
java program  how to write an addition program in java without using arithematic operator
java program
java program  Write a java program to do matrix addition operation On two given matrices
 

 

 

DMCA.com