1.Java program to print the “ Hello Java”
Import java.io.*;
Class A
{
public static void main(String args [])
{
System.out.println(“ Hello Java”);
}
}
2.Java program to take an integer as input and print it
import java.io.*;
import java.util.Scanner;
// Driver Class
class GFG {
// main function
public static void main(String[] args)
{
// Declare the variables
int num;
// Input the integer
System.out.println("Enter the integer: ");
// Create Scanner object
Scanner s = new Scanner(System.in);
// Read the next integer from the screen
num = s.nextInt();
// Display the integer
System.out.println("Entered integer is: " + num);
}
}
Input
, Enter the integer: 10
Output
Entered integer is: 10
3.Java Program to print Multiplication of two floating point Number.
import java.io.*;
class GFG {
public static void main(String[] args)
{
// f is to ensures that numbers are float DATA TYPE
float f1 = 1.5f;
float f2 = 2.0f;
// to store the multiplied value
float p = f1 * f2;
// to print the product
System.out.println("The product is: " + p);
}
}
Output
The product is: 3.0
4.Java Program to Swap Two values using third variable using temp variable
// Importing generic libraries
import java.util.*;
class GFG {
// Function to swap two numbers
// Using temporary variable
static void swapValuesUsingThirdVariable(int m, int n)
{
// Swapping the values
int temp = m;
m = n;
n = temp;
System.out.println("Value of m is " + m
Import java.io.*;
Class A
{
public static void main(String args [])
{
System.out.println(“ Hello Java”);
}
}
2.Java program to take an integer as input and print it
import java.io.*;
import java.util.Scanner;
// Driver Class
class GFG {
// main function
public static void main(String[] args)
{
// Declare the variables
int num;
// Input the integer
System.out.println("Enter the integer: ");
// Create Scanner object
Scanner s = new Scanner(System.in);
// Read the next integer from the screen
num = s.nextInt();
// Display the integer
System.out.println("Entered integer is: " + num);
}
}
Input
, Enter the integer: 10
Output
Entered integer is: 10
3.Java Program to print Multiplication of two floating point Number.
import java.io.*;
class GFG {
public static void main(String[] args)
{
// f is to ensures that numbers are float DATA TYPE
float f1 = 1.5f;
float f2 = 2.0f;
// to store the multiplied value
float p = f1 * f2;
// to print the product
System.out.println("The product is: " + p);
}
}
Output
The product is: 3.0
4.Java Program to Swap Two values using third variable using temp variable
// Importing generic libraries
import java.util.*;
class GFG {
// Function to swap two numbers
// Using temporary variable
static void swapValuesUsingThirdVariable(int m, int n)
{
// Swapping the values
int temp = m;
m = n;
n = temp;
System.out.println("Value of m is " + m