Java input output example

This is a little example in Java how to print an info text and then read a number from the terminal, calculate the square and then print the result:

public class HelloWorld{
     public static void main(String []args){
        System.out.print("write your number: ");//Info text 
        String str = System.console().readLine();//read input
        System.out.println("your number: "+str);//print input
        int i = Integer.parseInt(str);//convert to intager
        i = i*i;//calculate
        System.out.println("your result: "+i);//print result

To compile your file run this in your terminal:


now we have the file test, to execute run this:

java -Xmx128M -Xms16M test

This is the output:

write your number: 4                                                       
your number: 4                                                               
your result: 16

The same Program in C# is here : C# input output example

6 thoughts on “Java input output example”

  1. Thanks in favor of sharing such a pleasant opinion, paragraph
    is nice, thats why i have read it entirely

  2. Excellent items from you, man. I have have in mind
    your stuff prior to and you’re just too great. I actually like what you’ve received right
    here, really like what you’re saying and the way
    in which in which you say it. You are making it entertaining and
    you continue to take care of to keep it sensible.

    I cant wait to learn far more from you. That is actually
    a wonderful website.

  3. Hello there, I found your website by way of Google while looking for a related subject, your
    site got here up, it appears good. I’ve bookmarked it
    in my google bookmarks.
    Hi there, simply changed into alert to your blog through Google, and found
    that it is really informative. I am going to watch out for
    brussels. I’ll be grateful in case you continue this in future.
    Lots of other people will be benefited out of your writing.

  4. Hello, i think that i saw you visited my web site so i
    came to return the desire?.I am trying to to find issues to improve
    my web site!I suppose its good enough to make use of a
    few of your ideas!!

  5. I’ll right away seize your rss feed as I can not find your e-mail subscription hyperlink or e-newsletter service.
    Do you have any? Kindly let me recognise so that
    I could subscribe. Thanks.

  6. Great goods on your part, man. I have got take into account your stuff ahead of and you’re simply too wonderful.
    I actually like what you might have acquired on this site, certainly like what you will be saying and the
    way in which where you happen to be saying it.
    You are making it enjoyable and you continue to care for to keep it smart.
    I cant wait to learn far more by you. This is certainly
    actually a wonderful website.

Leave a Reply

Your email address will not be published.

four × two =