Beta Coder

Learn code like Beta Coder.

Breaking

Saturday, September 12, 2020

JAVA HELLO WORLD & INPUT METHOD

HELLO WORLD & INPUT METHOD

HELLO WORLD & INPUT METHOD
In this program we learn how to print 'HELLO WORLD' and how to get inputs by user using Java.
Java 'HELLO WORLD' program and Input Method
// HELLO WORLD & INPUT METHOD
import java.util.*;
class HelloWorld
{
	public static void main(String []arg)
	{
		int a;
		float b;
		String s;
		System.out.println("HELLO WORLD!");       // Print Hello World.
		Scanner in = new Scanner(System.in);
		System.out.println("Enter a string ");    
		s = in.nextLine();		          // Get a String value
		System.out.println("Enter a integer ");
		a = in.nextInt();			          // Get a Integer value
		System.out.println("Enter a float ");
		b = in.nextFloat();			   // Get a Floating point value
		System.out.println("\n You entered a string : "+s);   // Print value of String
                System.out.println("\n You entered a integer : "+a)   // Print value of Integer
                System.out.println("\n You entered a float : "+b);    // Print value of Floating point
	}
}
OUTPUT:
   HELLO WORLD!
   Enter a string
    BetaCoder
   Enter a integer
    81
   Enter a float
    23.78

No comments:

Post a Comment