Problem: Java Program To Print “Hello
World”
class HelloWorld {
public static void main(String args []) {
System.out.println("Hello
Java");
}}
Problem: Java Program To Calculate And Display Area Of A Circle
import java.util.*;
class CalculateCircleAreaExample {
private static Scanner s;
public static void main(String[] args) {
double r, area, pi = 3.14;
s = new Scanner(System.in);
System.out.print("Enter The Value
Of Radius: ");
r = s.nextDouble();
area = pi * r * r; // area of circle =
pi*r*r
System.out.println("The Area Of
Circle Of Radius "+r+" = "+area);
}}
Problem: Java Program To Print
Current Date And Time
import java.util.Calendar;
public class GetCurrentDateTimeExample {
public static void main(String[] args) {
Calendar now = Calendar.getInstance();
System.out.println("Current Year:
" + now.get(Calendar.YEAR));
System.out.println("Current Month:
" + (now.get(Calendar.MONTH) + 1 ));
System.out.println("Current Date:
" + now.get(Calendar.DATE));
System.out.println("Current Hour
(12 Hour Format): "
+ now.get(Calendar.HOUR));
+ now.get(Calendar.HOUR_OF_DAY));
System.out.println("Current Minute:
" + now.get(Calendar.MINUTE));
System.out.println("Current Second:
" + now.get(Calendar.SECOND));
System.out.println("Current
Millisecond: " + now.get(Calendar.MILLISECOND));
System.out.println("Current Date
& Time Is: "
+ (now.get(Calendar.MONTH) + 1) +
"-"
+ now.get(Calendar.DATE) + "-"
+ now.get(Calendar.YEAR) + " "
+ now.get(Calendar.HOUR_OF_DAY)
+ ":"+
now.get(Calendar.MINUTE)
+ ":" +
now.get(Calendar.SECOND)
+ "." +
now.get(Calendar.MILLISECOND));
}}
Problem: Java Program To Calculate
The Sum Of Odd And Even Numbers From 0 to N
import java.util.*;
public class SumOddEven {
public static void main(String args[]) {
int N, i, sum1 = 0, sum2 = 0;
Scanner n = new Scanner(System.in);
System.out.print("Enter An Integer:
");
N = n.nextInt();
for(i = 0; i <= N; i++){
if((i%2) == 1){
sum1 += i;
}
else sum2 += i;
}
System.out.println("Sum Of Odd
Numbers From 0 To " + N + " = " + sum1);
System.out.println("Sum Of Even
Numbers From 0 To "+ N + " = " + sum2);
n.close();
}}