{"id":5178,"date":"2021-03-23T11:46:36","date_gmt":"2021-03-23T11:46:36","guid":{"rendered":"https:\/\/ded9.com\/?p=5178"},"modified":"2026-02-17T11:09:29","modified_gmt":"2026-02-17T11:09:29","slug":"input-and-output-tutorial-in-java-in-very-simple-language","status":"publish","type":"post","link":"https:\/\/ded9.com\/tr\/input-and-output-tutorial-in-java-in-very-simple-language\/","title":{"rendered":"Java Input &#038; Output \u2014 Easy Guide to Reading and Writing Data"},"content":{"rendered":"<p><span style=\"box-sizing: border-box; margin: 0px; padding: 0px;\"><span style=\"font-size: 12pt;\">Input and Output Tutorial in Java (In Very Simple Language)<\/span>.<span style=\"font-size: 12pt;\">\u00a0In this tutorial, you will learn simple ways to display output and get\u00a0<\/span><a href=\"https:\/\/www.programiz.com\/java-programming\/basic-input-output\" target=\"_blank\" rel=\"noopener\"><span style=\"font-size: 12pt;\">input<\/span><\/a><span style=\"font-size: 12pt;\"> from the user.<\/span><\/span><\/p>\n<h2><span style=\"font-size: 18pt;\">Java output<\/span><\/h2>\n<p>It can be from<\/p>\n<p dir=\"ltr\">System.out.println ()<\/p>\n<p dir=\"ltr\">Or System.out.print ()<\/p>\n<p dir=\"ltr\">System.out.printf ()<\/p>\n<p>Used to send output to standard output (screen).<\/p>\n<p>System is a class, and out is a general static field that takes the output data. Do not worry if you do not notice. The following chapters will explain the classes, public, and static.<\/p>\n<p>Let&#8217;s take an example of printing a sentence as an output.<\/p>\n<blockquote>\n<ol>\n<li dir=\"ltr\">class AssignmentOperator {<\/li>\n<li dir=\"ltr\">public static void main (String [] args) {<\/li>\n<li dir=\"ltr\"><\/li>\n<li dir=\"ltr\">System.out.println (\u201cJava programming is interesting.\u201d);<\/li>\n<li dir=\"ltr\">}<\/li>\n<li dir=\"ltr\">}<\/li>\n<\/ol>\n<\/blockquote>\n<p><strong>Output<\/strong><\/p>\n<blockquote>\n<p dir=\"ltr\">Java programming is interesting.<\/p>\n<\/blockquote>\n<p>Here, println is the method that displays the String inside the quotes.<\/p>\n<h2 dir=\"ltr\">What is it? The difference between println (), print (), and printf ()<\/h2>\n<p>Print () &#8211; Prints the String inside the quote.<\/p>\n<p>Println () &#8211; Prints the String inside the quote. The cursor then moves to the beginning of the following line.<\/p>\n<p>Printf () &#8211; Provides String formatting (similar to printf in C++ \/ C programming).<\/p>\n<p><strong>Example 2: print () and println ()<\/strong><\/p>\n<blockquote>\n<ol>\n<li dir=\"ltr\">class Output {<\/li>\n<li dir=\"ltr\">public static void main (String [] args) {<\/li>\n<li dir=\"ltr\"><\/li>\n<li dir=\"ltr\">System.out.println (&#8220;1. println&#8221;);<\/li>\n<li dir=\"ltr\">System.out.println (&#8220;2. println&#8221;);<\/li>\n<li dir=\"ltr\"><\/li>\n<li dir=\"ltr\">System.out.print (&#8220;1. print&#8221;);<\/li>\n<li dir=\"ltr\">System.out.print (&#8220;2. print&#8221;);<\/li>\n<li dir=\"ltr\">}<\/li>\n<li dir=\"ltr\">}<\/li>\n<\/ol>\n<\/blockquote>\n<p><strong>Output<\/strong><\/p>\n<blockquote>\n<p dir=\"ltr\">1.\u00a0println<\/p>\n<p dir=\"ltr\">\u06f2.\u00a0println<\/p>\n<p dir=\"ltr\">1.\u00a0print 2. print<\/p>\n<\/blockquote>\n<p>Do not use quotation marks to display integers, variables, etc.<\/p>\n<p><strong>Example 3: Printing <a href=\"https:\/\/ded9.com\/variables-and-data-types-in-java-in-very-simple-language\/\">variables<\/a> and literals<\/strong><\/p>\n<blockquote>\n<ol>\n<li dir=\"ltr\">class Variables {<\/li>\n<li dir=\"ltr\">public static void main (String [] args) {<\/li>\n<li dir=\"ltr\"><\/li>\n<li dir=\"ltr\">Double number = -10.6;<\/li>\n<li dir=\"ltr\"><\/li>\n<li dir=\"ltr\">System.out.println (5);<\/li>\n<li dir=\"ltr\">System.out.println (number);<\/li>\n<li dir=\"ltr\">}<\/li>\n<li dir=\"ltr\">}<\/li>\n<\/ol>\n<\/blockquote>\n<p><strong>Output<\/strong><\/p>\n<blockquote>\n<p dir=\"ltr\">5<\/p>\n<p dir=\"ltr\">10.6<\/p>\n<\/blockquote>\n<p>You can use the + operator to join strings and print them.<\/p>\n<p><strong>Example 4: Print interconnected strings<\/strong><\/p>\n<blockquote>\n<ol>\n<li dir=\"ltr\">class PrintVariables {<\/li>\n<li dir=\"ltr\">public static void main (String [] args) {<\/li>\n<li dir=\"ltr\"><\/li>\n<li dir=\"ltr\">Double number = -10.6;<\/li>\n<li dir=\"ltr\"><\/li>\n<li dir=\"ltr\">System.out.println (\u201cI am\u201d + \u201cawesome.\u201d);<\/li>\n<li dir=\"ltr\">System.out.println (\u201cNumber =\u201d + number);<\/li>\n<li dir=\"ltr\">}<\/li>\n<li dir=\"ltr\">}<\/li>\n<\/ol>\n<\/blockquote>\n<p><strong>Output<\/strong><\/p>\n<blockquote>\n<p dir=\"ltr\">I am awesome.<\/p>\n<p dir=\"ltr\">Number = -10.6<\/p>\n<\/blockquote>\n<p>Consider the following line:<\/p>\n<blockquote>\n<p dir=\"ltr\">System.out.println (\u201cI am\u201d + \u201cawesome.\u201d);<\/p>\n<\/blockquote>\n<p>The &#8220;I am&#8221; and &#8220;awesome&#8221; strings are appended to the page before printing.<\/p>\n<p>In the following line:<\/p>\n<div class=\"wp-block-codemirror-blocks code-block \">\n<pre class=\"CodeMirror\" data-setting=\"{&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-java&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;lineWrapping&quot;:false,&quot;styleActiveLine&quot;:false,&quot;readOnly&quot;:true,&quot;align&quot;:&quot;&quot;}\">System.out.println (\u201cNumber =\u201d + number);<\/pre>\n<\/div>\n<p>First, the compiler evaluates the value of the number variable and converts it to a string. Then, the strings are collected and printed on the screen.<\/p>\n<h2><span style=\"font-size: 18pt;\">Java input<\/span><\/h2>\n<p>There are several ways to get user input in Java. Here, you will learn how to use the Scanner object.<\/p>\n<p>To do this, you need to import the Scanner class into the program:<\/p>\n<blockquote>\n<p dir=\"ltr\">import java.util.Scanner;<\/p>\n<\/blockquote>\n<p>Then, we create an object of the Scanner class that is used to receive input from the user.<\/p>\n<div class=\"wp-block-codemirror-blocks code-block \">\n<pre class=\"CodeMirror\" data-setting=\"{&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-java&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;lineWrapping&quot;:false,&quot;styleActiveLine&quot;:false,&quot;readOnly&quot;:true,&quot;align&quot;:&quot;&quot;}\">Scanner input = new Scanner (System.in);\r\n\r\nint number = input.nextInt ();<\/pre>\n<\/div>\n<p><strong>Example 5: Get the input integer from the user<\/strong><\/p>\n<blockquote>\n<ol>\n<li dir=\"ltr\">import java.util.Scanner;<\/li>\n<li dir=\"ltr\">class Input {<\/li>\n<li dir=\"ltr\">public static void main (String [] args) {<\/li>\n<li dir=\"ltr\"><\/li>\n<li dir=\"ltr\">Scanner input = new Scanner (System.in);<\/li>\n<li dir=\"ltr\"><\/li>\n<li dir=\"ltr\">System.out.print (&#8220;Enter an integer:&#8221;);<\/li>\n<li dir=\"ltr\">int number = input.nextInt ();<\/li>\n<li dir=\"ltr\">System.out.println (&#8220;You entered&#8221; + number);<\/li>\n<li dir=\"ltr\">}<\/li>\n<li dir=\"ltr\">}<\/li>\n<\/ol>\n<\/blockquote>\n<p><strong>Output<\/strong><\/p>\n<blockquote>\n<p dir=\"ltr\">Enter an integer: 23<\/p>\n<p dir=\"ltr\">You entered 23<\/p>\n<\/blockquote>\n<p>Here, the input object of the Scanner class is created. The nextInt () method in the Scanner class then receives the integer input from the user.<\/p>\n<p>To get long, float, double, and String input from the user, you can use the methods, respectively<\/p>\n<p dir=\"ltr\">nextLong (), nextFloat (), nextDouble (), and next ()<\/p>\n<p>use.<\/p>\n<p><strong>Example 6: Get float, double, and String inputs<\/strong><\/p>\n<p><strong><img fetchpriority=\"high\" decoding=\"async\" class=\"aligncenter wp-image-258224 size-full\" src=\"https:\/\/ded9.com\/wp-content\/uploads\/2021\/03\/string-name-is-base-address.png\" alt=\"Example 6: Get float, double, and String inputs\" width=\"840\" height=\"519\" srcset=\"https:\/\/ded9.com\/wp-content\/uploads\/2021\/03\/string-name-is-base-address.png 840w, https:\/\/ded9.com\/wp-content\/uploads\/2021\/03\/string-name-is-base-address-300x185.png 300w, https:\/\/ded9.com\/wp-content\/uploads\/2021\/03\/string-name-is-base-address-768x475.png 768w\" sizes=\"(max-width: 840px) 100vw, 840px\" \/><\/strong><\/p>\n<blockquote>\n<ol>\n<li dir=\"ltr\">import java.util.Scanner;<\/li>\n<li dir=\"ltr\">class Input {<\/li>\n<li dir=\"ltr\">public static void main (String [] args) {<\/li>\n<li dir=\"ltr\"><\/li>\n<li dir=\"ltr\">Scanner input = new Scanner (System.in);<\/li>\n<li dir=\"ltr\"><\/li>\n<li dir=\"ltr\">\/\/ Getting float input<\/li>\n<li dir=\"ltr\">System.out.print (&#8220;Enter float:&#8221;);<\/li>\n<li dir=\"ltr\">float myFloat = input.nextFloat ();<\/li>\n<li dir=\"ltr\">System.out.println (&#8220;Float entered =&#8221; + myFloat);<\/li>\n<li dir=\"ltr\"><\/li>\n<li dir=\"ltr\">\/\/ Getting double input<\/li>\n<li dir=\"ltr\">System.out.print (&#8220;Enter double:&#8221;);<\/li>\n<li dir=\"ltr\">double myDouble = input.nextDouble ();<\/li>\n<li dir=\"ltr\">System.out.println (&#8220;Double entered =&#8221; + myDouble);<\/li>\n<li dir=\"ltr\"><\/li>\n<li dir=\"ltr\">\/\/ Getting String input<\/li>\n<li dir=\"ltr\">System.out.print (&#8220;Enter text:&#8221;);<\/li>\n<li dir=\"ltr\">String myString = input.next ();<\/li>\n<li dir=\"ltr\">System.out.println (&#8220;Text entered =&#8221; + myString);<\/li>\n<li dir=\"ltr\">}<\/li>\n<li dir=\"ltr\">}<\/li>\n<\/ol>\n<\/blockquote>\n<p><strong>Output<\/strong><\/p>\n<blockquote>\n<p dir=\"ltr\">Enter float: 2,343<\/p>\n<p dir=\"ltr\">Float entered = 2,343<\/p>\n<p dir=\"ltr\">Enter double: -23.4<\/p>\n<p dir=\"ltr\">Double entered = -23.4<\/p>\n<p dir=\"ltr\">Enter text: Hey!<\/p>\n<p dir=\"ltr\">Text entered = Hey!<\/p>\n<\/blockquote>\n<h2 dir=\"ltr\">FAQ<\/h2>\n<div id=\"rank-math-rich-snippet-wrapper\"><div id=\"rank-math-faq\" class=\"rank-math-block\">\n<div class=\"rank-math-list \">\n<div id=\"faq-1\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \">What is I\/O in Java?<\/h3>\n<div class=\"rank-math-answer \">\n\n<p>I\/O stands for Input\/Output \u2014 it refers to how a Java program reads data (input) from sources like keyboard or files and writes data (output) to destinations like the console or files.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-2\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \">How do I print output on the screen in Java?<\/h3>\n<div class=\"rank-math-answer \">\n\n<p>Use System.out.print() or System.out.println() to send text or variable values to the console; println adds a new line after output, while print does not.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-3\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \">How can I read user input in Java?<\/h3>\n<div class=\"rank-math-answer \">\n\n<p>You can use the Scanner class (from java.util), e.g. Scanner input = new Scanner(System.in); int num = input.nextInt(); String text = input.nextLine();<\/p>\n\n<\/div>\n<\/div>\n<\/div>\n<\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Input and Output Tutorial in Java (In Very Simple Language).\u00a0In this tutorial, you will learn simple ways to display output and get\u00a0input from the user. Java output It can be from System.out.println () Or System.out.print () System.out.printf () Used to send output to standard output (screen). System is a class, and out is a general [&hellip;]<\/p>\n","protected":false},"author":6,"featured_media":5179,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1077],"tags":[840],"class_list":["post-5178","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-javascript","tag-java"],"acf":[],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/ded9.com\/tr\/wp-json\/wp\/v2\/posts\/5178","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ded9.com\/tr\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ded9.com\/tr\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ded9.com\/tr\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/ded9.com\/tr\/wp-json\/wp\/v2\/comments?post=5178"}],"version-history":[{"count":4,"href":"https:\/\/ded9.com\/tr\/wp-json\/wp\/v2\/posts\/5178\/revisions"}],"predecessor-version":[{"id":266019,"href":"https:\/\/ded9.com\/tr\/wp-json\/wp\/v2\/posts\/5178\/revisions\/266019"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ded9.com\/tr\/wp-json\/wp\/v2\/media\/5179"}],"wp:attachment":[{"href":"https:\/\/ded9.com\/tr\/wp-json\/wp\/v2\/media?parent=5178"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ded9.com\/tr\/wp-json\/wp\/v2\/categories?post=5178"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ded9.com\/tr\/wp-json\/wp\/v2\/tags?post=5178"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}