Home Answers Viewqa Java-Beginners My first Java Program

 
 


Sikelela Sigudhla
My first Java Program
1 Answer(s)      a year and 11 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.

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 Pages:
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
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
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
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
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
spring first example - Spring
spring first example  I am trying my first example of spring from...\Intel\DMIX;C:\Program Files\Java\jdk1.6.0\bin;C:\ANT\bin; Jul 16, 2010 2:07:52...:\Program Files\Apache Software Foundation\Tomcat 5.5\bin;.;C:\WINDOWS\Sun\Java\bin;C
Depth-first Polymorphism - tutorial
Depth-first Polymorphism 2001-02-15 The Java Specialists' Newsletter [Issue 009] - Depth-first Polymorphism Author: Dr. Heinz M. Kabutz If you... of Common Lisp." And Java? Depth-first Polymorphism (or Customised
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 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 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
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
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
Sum of first n numbers
Sum of first n numbers  i want a simple java program which will show the sum of first n numbers....   import java.util.*; public class SumOfNumbers { public static void main(String[]args){ Scanner input=new
First Window
Java NotesExample - First Window This is about the simplest GUI...(String[] args) { JFrame window = new JFrame("My First Window... program must look like this. JFrame is the Java class for a "window
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
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
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
plz. answer my ques - Java Beginners
plz. answer my ques  I want to ask a prog. prob which would create... such type of program is possible in c.  can you mention technology..."); } } }   1) first create "retry.jsp" page (this displays
Some additions for my previous question - Java Beginners
Some additions for my previous question  This is the question I posted several hours ago: "I'm trying to write a program that has a text field.... The first button when pressed should tell the user if that number is prime
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
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
my sql innodb
my sql innodb  Write a java program that connects to a MySQL server and checks if the InnoDB plug-in is installed on it. If so, your program should print the total number of disk writes by MySQL
Java Program - Java Beginners
Java Program  My friend has a java project. He wanted to have java program that has 4 menu options which are (1)Add Data(from the user:last name, first name and age),(2)Sort Data,(3)Insert Data and (4)Delete Data, but he didn't
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
Replacing the first subsequence of the input
pattern p. matcher.replaceFirst("Java"):-This method will replace only the first...;} } Output of the program:- Text before replacing first... Replacing the first subsequence of the input  
Get first day of week
in the java program. This calendar is used in most of world.  Description of program: The following program helps us in getting the first day of the week... Get first day of week      
Need help with my project
Need help with my project  Uses a while loop to perform the following... results to a file in the same directory as the program, placing an appropriate label between each section of output. Note that your program must be able to run
Java program? - Java Beginners
Java program?  In order for an object to escape planet's.... The escape velocity varies from planet to planet.Create a Java program which calculates the escape velocity for the planet. Your program should first prompt
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
Java Program - Java Beginners
Java Program  Hi I'm having trouble with this problem, I keep getting errors. Write a program GuessGame.java that plays the game ?guess the number? as follows: Your program chooses the number to be guessed by selecting
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
Import My Own Package (Automatically)
Import My Own Package (Automatically)   How can I import my own package in every java program ( automatically )....? For example :- java.lang.String... automatically imported, we need not to import
To find first two maximum numbers in an array
To find first two maximum numbers in an array  Java program to find first two maximum numbers in an array,using single loop without sorting array
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
What is the first argument of the String array in main() method?
. This is unlike C/C++ where the first element by default is the program name. You also.... This article gives your a very easy java program which illustrates about the string...What is the first argument of the String array in main() method?  Hi
recursion program
recursion program  Hi this is my first java class, and i have been trying for hours to do this program. it is a recursion problem where the user will enter a continuous monthly investment, at a rate of 1% the program should say
Java Program HELP - Java Beginners
Java Program HELP  Hi I'm having trouble with this problem, I keep getting errors. Write a program GuessGame.java that plays the game ?guess the number? as follows: Your program chooses the number to be guessed by selecting
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
Program - Java Beginners
\bin>_ But As per my code,The No OF Records is 2.. But as per my requirement..."); System.out.println("3.Insert First"); System.out.println("4.Insert Last..."); System.out.println("6.Delete First"); System.out.println("7.Delete Last
please help.. this my importtant project..!!!!!
) Write a Java test program that creates object with a=3, b=4 and c=1. Display the result based on discriminant. The program will prompt the user to enter values...please help.. this my importtant project..!!!!!  Consider the Algebra
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 Step towards JDBC!
JDBC - Java Database Connectivity Tutorials    Java Database Connectivity or in short JDBC  is a technology that enables the java program to manipulate data stored into the database. Here

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.