Java example with output

Top 100+ Java Programming Examples With Output

Java Programming Examples With Output | Learn Java Programming Language through examples. Develop java basic programs to understand the basic concepts of Java. These are the basic Java program examples with output. After learning the procedure to develop the program try to develop it on your own and then compare the code given on the website. This page contains frequently, unique, and popular Java programs. For all Java programs visit here:- Java Program List

Java Basic Programs

  1. Java Hello World program
  2. Java Addition Program
  3. Average of Two Numbers
  4. Total & Average of 3 Subjects
  5. Calculate Simple Interest
  1. Calculate Compound Interest
  2. Display ASCII value in Java
  3. Calculate Area of Circle in Java
  4. Find Area of Rectangle in Java
  5. Find the Area of Triangle in Java
  1. Swapping two Numbers in Java
  2. Distance Between 2 Points in Java
  3. Simple Mortgage Calculator in Java
  4. Miles to Kilometers Java Program
  5. Unit Conversion Java Program

Java Programming Examples on Flow Control

Java flow control programs are based on conditional control statements (if, if-else and switch-case), loop control statements (while loop, do-while loop, for-loop), and Jump control statements (continue, and break). This section contains multiple Java programs. Some of them are formula-based programs, programs on different types of numbers, different types of printing patterns, flow-control-based conversion programs, and e.t.c.

  1. Java code to Check Even Odd
  2. Find the Greatest of 3 numbers
  3. How to Find exponents in Java
  4. Students’ Grades using Switch Case
  5. Iterate digits of a number
  1. Leap year program in Java
  2. Print Multiplication table
  3. Find Reverse of a number
  4. Find Factors of a number
  5. LCM of two numbers in Java
  1. HCF of two numbers in Java
  2. Roots of a quadratic equation
  3. Square Root of a Number
  4. Perfect Square Program
  5. Print 1 to 100 Without Loop
  1. Simple Calculator Program
  2. BMI (Body Mass Index) Calculator
  3. Electric Bill Java Program
  4. Find runtime of a Java Program
  5. Factorial of a Number in Java
  6. Golden Ratio Java Program
  1. Even Number in Java
  2. Odd Number in Java
  3. Prime Number in Java
  4. Twin prime Number
  5. Magic Number in Java
  1. Armstrong Number
  2. Palindrome Number
  3. Perfect Number Java
  4. Spy Number in Java
  5. Tech Number in Java
  1. Sunny Number in Java
  2. Automorphic Number
  3. Krishnamurthy Number
  4. Evil Number in Java
  5. Strong Number in Java
  1. Disarium Number Java
  2. Neon Number in Java
  3. Pronic Number in Java
  4. Duck Number in Java
  5. Harshad Number Java
  1. Kaprekar Number Java
  2. Buzz Number in Java
  3. Nelson Number in Java
  4. Special Number in Java

Array Programs in Java

  1. Find Length of Array in Java
  2. Different ways to Print Array
  3. Find the Sum of Array in Java
  4. Average in Java using Array
  5. Sum of Two Arrays Elements
  1. Compare Two Arrays in Java
  2. Copy Array in Java
  3. Merge Two Arrays in Java
  4. Merge Two Sorted Arrays
  5. Largest Number in Array
  1. Smallest Number in Array
  2. 2nd Largest Number in Array
  3. How to Sort an Array in Java
  4. Reverse an Array in Java
  5. GCD of N Numbers in Java
  1. Find the LCM of an Array in Java
  2. Linear Search in Java
  3. Binary Search Program in Java
  4. Remove Duplicates From the Array
  5. Insert Element at Specific Position
  1. Add Element to Array in Java
  2. Remove Element From Array in Java
  3. Count Repeated Elements in an Array
  4. How To Reduce The Size Of An Array In Java
  5. Find Odd Occurrence Number Array in Java
  1. Java Primitive Array To Wrapper Array
  2. Java Array of Random Numbers
  3. Find the Median of an Array in Java
  • How To Print An Array In Java In One Line
  • How To Append An Array In Java
Читайте также:  Стили

Multi-dimensional array and Matrix Programs in Java

  1. Print 2D array in Java
  2. Program to Print 3×3 Matrix
  3. Sum of matrix elements in Java
  4. Sum of Diagonal Elements of Matrix
  5. Row sum and Column sum of Matrix
  1. Fill 2D Array With Random Numbers
  2. Sort 2D Array In Java
  3. Java Magic Square 2D Array
  4. Java Count Occurrences in 2D Array
  5. How to Find Minimum Value in 2D Array Java
  1. Matrix Addition in Java
  2. Subtraction of two matrices in Java
  3. Transpose of a Matrix in Java
  4. Matrix Multiplication in Java
  5. Menu-driven program for Matrix operations

Java Programming Examples on String

  1. Take String Input using Scanner
  2. How to Find Length of String in Java
  3. Length of String Without length()
  4. How to Iterate through String Java
  5. Java For Each Character In String
  1. Sum of digits in a String
  2. Count No of Vowels String
  3. String Pattern Programs in Java
  4. How To Reverse a String In Java
  5. String Palindrome In Java
  1. Sort String In Java
  2. How to Compare Strings In Java
  3. Check If Char is Uppercase
  4. Check If String is Uppercase Java
  5. String Contains Uppercase or Lowercase
  1. Swap Characters in String Java
  2. Generate Random Strings
  3. Java Program to Find Weight of String
  4. Find the Second Occurrence of Character
  5. Find the Last Occurrence of Character
  1. Split String By Line in Java
  2. Compare Strings Alphabetically Java
  3. Put Quotes in a String Java
  4. Java String Parsestring
  5. How to Check if String is Empty Java
  1. How to Compare String to Enum Java
  2. How to Concat Int to String in Java
  3. New Line In Java String
  4. Find Repeating Pattern In String Java
  5. Java Set Character in String
  1. Appending String In Java
  2. Concat Strings in Java
  3. Java String Interpolation

String Programs on Replace/Remove

Conversion of/to String Programs in Java

String Array Programs

Java Programming Examples on Collection

  1. Print Vowels & Consonants in String
  2. Convert Comma Separated String to List Java
  3. Convert Pipe Delimited String to List Java
  4. How To Find Repeated Characters In A String In Java
  5. Cast Object to List String in Java
  6. Java Convert Object List To String List
  1. Java Convert String List To Array
  2. Java String Array to String List
  3. Convert Map to String Java
  4. Convert String to Map Java
  5. Join List Of Strings in Java
  • Java.lang.integer Cannot Be Cast To Java.lang.boolean
  • Convert Integer To Byte In Java
  • Compare Integer And Int Java
  • Java Convert Integer To Short and Vice-Versa
  • How To Reverse an Integer in Java
  • Java Integer compareTo() Method
  • Integer.compare() in Java
  • How To Compare String And Integer In Java
  • Print Byte Array in Java
  • Convert Integer To Char in Java
  • Java Integer decode() Method
  • Convert Byte Array To Integer In Java
  • Int vs Integer in Java
  • Int to Integer in Java
  • Convert Integer To Int in Java
  • Integer To Double in Java
  • Java Integer getInteger() Method
  • Java Integer hashCode() Method
  • Java List Integer To Int Array
  • Integer To Long in Java
  • Java Integer parseInt() Method
  • Long Data Type In Java
  • Short Data Type in Java
Читайте также:  Vuex typescript vue 3

Others

More Programs are coming soon, keep visiting. Subscribe to our newsletter and follow us on Facebook, Instagram, and Twitter to receive the latest tutorial and programs to improve your programming skills.

Источник

Java Output / Print

You learned from the previous chapter that you can use the println() method to output values or print text in Java:

Example

System.out.println("Hello World!"); 

You can add as many println() methods as you want. Note that it will add a new line for each method:

Example

System.out.println("Hello World!"); System.out.println("I am learning Java."); System.out.println("It is awesome!"); 

Double Quotes

When you are working with text, it must be wrapped inside double quotations marks «» .

If you forget the double quotes, an error occurs:

Example

System.out.println("This sentence will work!");
System.out.println(This sentence will produce an error);

The Print() Method

There is also a print() method, which is similar to println() .

The only difference is that it does not insert a new line at the end of the output:

Example

System.out.print("Hello World! "); System.out.print("I will print on the same line."); 

Note that we add an extra space (after «Hello World!» in the example above), for better readability.

In this tutorial, we will only use println() as it makes it easier to read the output of code.

Unlock Full Access 50% off

COLOR PICKER

colorpicker

Join our Bootcamp!

Report Error

If you want to report an error, or if you want to make a suggestion, do not hesitate to send us an e-mail:

Thank You For Helping Us!

Your message has been sent to W3Schools.

Top Tutorials
Top References
Top Examples
Get Certified

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.

Читайте также:  Document getelementbyid javascript form

Источник

Java IO : Input-output in Java with Examples

Java brings various Streams with its I/O package that helps the user to perform all the input-output operations. These streams support all the types of objects, data-types, characters, files etc to fully execute the I/O operations.

Before exploring various input and output streams lets look at 3 standard or default streams that Java has to provide which are also most common in use:

  1. System.in: This is the standard input stream that is used to read characters from the keyboard or any other standard input device.
  2. System.out: This is the standard output stream that is used to produce the result of a program on an output device like the computer screen. Here is a list of the various print functions that we use to output statements:
  3. print(): This method in Java is used to display a text on the console. This text is passed as the parameter to this method in the form of String. This method prints the text on the console and the cursor remains at the end of the text at the console. The next printing takes place from just here.
    Syntax:
System.out.println(parameter);
Printing simple integer: x = 100 Formatted with precision: PI = 3.14 Formatted to specific width: n = 5.2000 Formatted to right margin: n = 2324435.2500
Enter characters, and '0' to quit. G e e k s f o r G e e k s 0
  • Depending on the type of operations, streams can be divided into two primary classes:
    1. Input Stream: These streams are used to read data that must be taken as an input from a source array or file or any peripheral device. For eg., FileInputStream, BufferedInputStream, ByteArrayInputStream etc.
    2. Output Stream: These streams are used to write data as outputs into an array or file or any output peripheral device. For eg., FileOutputStream, BufferedOutputStream, ByteArrayOutputStream etc.
  • Depending on the types of file, Streams can be divided into two primary classes which can be further divided into other classes as can be seen through the diagram below followed by the explanations.
    1. ByteStream: This is used to process data byte by byte (8 bits). Though it has many classes, the FileInputStream and the FileOutputStream are the most popular ones. The FileInputStream is used to read from the source and FileOutputStream is used to write to the destination. Here is the list of various ByteStream Classes:
      Stream class Description
      BufferedInputStream It is used for Buffered Input Stream.
      DataInputStream It contains method for reading java standard datatypes.
      FileInputStream This is used to reads from a file
      InputStream This is an abstract class that describes stream input.
      PrintStream This contains the most used print() and println() method
      BufferedOutputStream This is used for Buffered Output Stream.
      DataOutputStream This contains method for writing java standard data types.
      FileOutputStream This is used to write to a file.
      OutputStream This is an abstract class that describe stream output.

      Example:

Источник

Оцените статью