Java Sample Program
Java Sample Program
Import java.io.*;
Class A
import java.io.*;
import java.util.Scanner;
// Driver Class
class GFG {
// main function
int num;
num = s.nextInt();
Input
Enter the integer: 10
Output
import java.io.*;
class GFG {
float f1 = 1.5f;
float f2 = 2.0f;
float p = f1 * f2;
Output
4.Java Program to Swap Two values using third variable using temp variable
import java.util.*;
class GFG {
int temp = m;
m = n;
n = temp;
System.out.println("Value of m is " + m
+ " and Value of n is " + n);
int m = 9, n = 5;
swapValuesUsingThirdVariable(m, n);
Output
import java.io.*;
import java.util.Scanner;
// Main class
class GFG {
// via remainder
if (num % 2 == 0) {
}
else {
// odd
Output
import java.io.*;
class GFG {
int a, b, c;
int largest;
a = 5;
b = 10;
c = 3;
}
}
Output
// Importing Classes/Files
import java.io.*;
// If year is divisible by 4
if (year % 4 == 0) {
is_leap_year = true;
// To identify whether it is a
if (year % 100 == 0) {
if (year % 400 == 0)
is_leap_year = true;
else
is_leap_year = false;
else
is_leap_year = false;
if (!is_leap_year)
System.out.println(year + " : Non Leap-year");
else
// Driver Code
isLeapYear(2000);
isLeapYear(2002);
Output
2000 : Leap-year