0% found this document useful (0 votes)
170 views18 pages

Sa Comprog To Tangina Talaga

The document contains code snippets for several Java programs that demonstrate different programming concepts: 1. A program that calculates the sum of two matrices by taking user input for the elements and adding the corresponding elements of the two matrices. 2. A program that demonstrates exception handling by allocating an array and catching any exceptions. 3. A program that prints the English alphabets from 'a' to 'z'. 4. A binary search algorithm program that searches for a given integer in a sorted array by repeatedly dividing the search interval in half. The document contains examples of common programming tasks like input/output, loops, arrays, exception handling and algorithms.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
170 views18 pages

Sa Comprog To Tangina Talaga

The document contains code snippets for several Java programs that demonstrate different programming concepts: 1. A program that calculates the sum of two matrices by taking user input for the elements and adding the corresponding elements of the two matrices. 2. A program that demonstrates exception handling by allocating an array and catching any exceptions. 3. A program that prints the English alphabets from 'a' to 'z'. 4. A binary search algorithm program that searches for a given integer in a sorted array by repeatedly dividing the search interval in half. The document contains examples of common programming tasks like input/output, loops, arrays, exception handling and algorithms.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 18

1

int sum[][] = new int[m][n];


1. AddNumbers
System.out.println("Enter the elements of first matrix");

for ( c = 0 ; c < m ; c++ )

for ( d = 0 ; d < n ; d++ )

first[c][d] = in.nextInt();

System.out.println("Enter the elements of second matrix");


import java.util.Scanner;
for ( c = 0 ; c < m ; c++ )
class AddNumbers
for ( d = 0 ; d < n ; d++ )
{
second[c][d] = in.nextInt();
public static void main(String args[])
for ( c = 0 ; c < m ; c++ )
{
for ( d = 0 ; d < n ; d++ )
int x, y, z;
sum[c][d] = first[c][d] + second[c][d]; //replace '+' with '-' to subtract
System.out.println("Enter two integers to calculate their sum "); Scanner
matrices
in = new Scanner(System.in);
System.out.println("Sum of entered matrices:-");
x= in.nextInt();
for ( c = 0 ; c < m ; c++ )
y= in.nextInt();
{
z= x + y;
for ( d = 0 ; d < n ; d++ )
System.out.println("Sum of entered integers = "+z);
System.out.print(sum[c][d]+"\t");
}
System.out.println();
}
}
2.AddTwoMatrix }

3.Allocate

import java.util.Scanner;

class AddTwoMatrix

public static void main(String args[]) class Allocate {

{ public static void main(String[] args) {

int m, n, c, d; try {

Scanner in = new Scanner(System.in); long data[] = new long[10];

System.out.println("Enter the number of rows and columns of matrix"); }

m= in.nextInt(); catch (Exception e) {

n= in.nextInt(); System.out.println(e);

int first[][] = new int[m][n]; }

int second[][] = new int[m][n]; finally {


2

System.out.println("finally block will execute always.");


6.ArmStrongNumber
}

import java.util.Scanner;

class ArmstrongNumber

4.Alphabets {

public static void main(String args[])

int n, sum = 0, temp, remainder, digits = 0;

Scanner in = new Scanner(System.in);

System.out.println("Input a number to check if it is an Armstrong


number");

n= in.nextInt(); temp = n;

// Count number of digits

while (temp != 0) {

digits++;

temp = temp/10;
class Alphabets
}
{
temp = n;
public static void main(String args[])
while (temp != 0) {
{
remainder = temp%10;
char ch;
sum = sum + power(remainder, digits);
for( ch = 'a' ; ch <= 'z' ; ch++ )
temp = temp/10;
System.out.println(ch);
}
}
if (n == sum)
}
System.out.println(n + " is an Armstrong number."); else

5.Argument System.out.println(n + " is not an Armstrong number.");

static int power(int n, int r) {

int c, p = 1;

class Arguments { for (c = 1; c <= r; c++)

public static void main(String[] args) { p= p*n;

System.out.println("This Is A Argument"); return p;

} }

} }
3

array = new int[n];


7.Arrylist
System.out.println("Enter " + n + " integers");

for (c = 0; c < n; c++)

array[c] = in.nextInt();

System.out.println("Enter value to find"); search = in.nextInt();

first = 0;
import java.util.*;
last = n - 1;
class Arrylist{
middle = (first + last)/2;
public static void main(String args[]){
while( first <= last )
ArrayList<String> list=new ArrayList<String>();//Creating arraylist
{
list.add("Rajendra");//Adding object in arraylist
if ( array[middle] < search )
list.add("Mahendra");
first = middle + 1;
list.add("Raja");
else if ( array[middle] == search )
list.add("Technolamror");
{
//Traversing list through Iterator
System.out.println(search + " found at location " + (middle + 1) +
Iterator itr=list.iterator();
".");
while(itr.hasNext()){
break;
System.out.println(itr.next());
}
}
else
}
last = middle - 1;
}
middle = (first + last)/2;
8.BinarySearch }

if ( first > last )

System.out.println(search + " is not present in the list.\n");

9.BreakWhileLoop
import java.util.Scanner;

class BinarySearch

public static void main(String args[])

int c, first, last, middle, n, search, array[]; import java.util.Scanner;

Scanner in = new Scanner(System.in); class BreakContinueWhileLoop {

System.out.println("Enter number of elements"); public static void main(String[] args) { int n;

n = in.nextInt(); Scanner input = new Scanner(System.in);


4

while (true) { }

System.out.println("Input an integer");
11.BubbleSort
n= input.nextInt();

if (n != 0) {

System.out.println("You entered " + n);

continue;

else {

break;

}
import java.util.Scanner;
}
class BubbleSort {
}
public static void main(String []args) { int n, c, d, swap;
}
Scanner in = new Scanner(System.in);

10.BreakContinueWhileLoop System.out.println("Input number of integers to sort");

n = in.nextInt();

int array[] = new int[n];

System.out.println("Enter " + n + " integers");

for (c = 0; c < n; c++)

array[c] = in.nextInt();

for (c = 0; c < ( n - 1 ); c++) {

for (d = 0; d < n - c - 1; d++) {


import java.util.Scanner;
if (array[d] > array[d+1]) /* For descending order use < */
class BreakContinueWhileLoop {
{
public static void main(String[] args) { int n;
swap = array[d];
Scanner input = new Scanner(System.in);
array[d] = array[d+1];
while (true) {
array[d+1] = swap;
System.out.println("Input an integer");
}
n= input.nextInt();
}
if (n != 0) {
}
System.out.println("You entered " + n);
System.out.println("Sorted list of numbers");
continue;
for (c = 0; c < n; c++)
}
System.out.println(array[c]);
else {
}
break;
}
}

} 12.CheckBoxExample
}
5

import java.awt.*;
import javax.swing.*; public class ChoiceExample
public class CheckBoxExample {
{ ChoiceExample(){
CheckBoxExample(){ Frame f= new Frame();
JFrame f= new JFrame("CheckBox Example by Technolamror"); Choice c=new Choice();
JCheckBox checkBox1 = new JCheckBox("C++");
checkBox1.setBounds(100,100, 50,50); c.setBounds(100,100, 75,75);
JCheckBox checkBox2 = new JCheckBox("Java", true); c.add("Item 1 by Rajendra");
checkBox2.setBounds(100,150, 50,50); c.add("Item 2 by Lamror");
f.add(checkBox1); c.add("Item 3 by Technolamror");
f.add(checkBox2); c.add("Item 4");
f.setSize(400,400); c.add("Item 5");
f.setLayout(null); f.add(c);
f.setVisible(true); f.setSize(400,400);
} f.setLayout(null);
public static void main(String args[]) f.setVisible(true);
{ }
new CheckBoxExample(); public static void main(String args[])
} {
} new ChoiceExample();

13.ChoiceExxample }

14. CompareStrings

import java.util.Scanner;
6

class CompareStrings public static void main(String[] args) {


{ display(); //calling without object
public static void main(String args[])
Difference t = new Difference();
{
t.show(); //calling using object
String s1, s2;
}
Scanner in = new Scanner(System.in);
static void display() {
System.out.println("Enter the first string"); s1 = in.nextLine();
System.out.println("Programming is amazing.");
System.out.println("Enter the second string"); s2 = in.nextLine();
}
if ( s1.compareTo(s2) > 0 )

System.out.println("First string is greater than second."); else if void show(){


( s1.compareTo(s2) < 0 )
System.out.println("Java is awesome.");
System.out.println("First string is smaller than second."); else
}
System.out.println("Both strings are equal.");
}
}

} 17.EnhancedForLoop
15.Condition

class EnhancedForLoop {
class Condition {
public static void main(String[] args) {
public static void main(String[] args) { boolean learning =
true; int primes[] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29};
if (learning) { for (int t: primes) {
System.out.println("Java programmer"); System.out.println(t);
} }
else { }
System.out.println("What are you doing here?"); }
}
18.Factorial
}

16.Difference
import java.util.Scanner;

class Factorial

{
class Difference {
public static void main(String args[])
7

{
20. FirstSwingExample
int n, c, fact = 1;

System.out.println("Enter an integer to calculate it's


factorial"); Scanner in = new Scanner(System.in);

n= in.nextInt();

if ( n < 0 )

System.out.println("Number should be non-negative."); else

for ( c = 1 ; c <= n ; c++ )

fact = fact*c;

System.out.println("Factorial of "+n+" is = "+fact);


import javax.swing.*;
}
public class FirstSwingExample {
}
public static void main(String[] args) {
}
JFrame f=new JFrame();//creating instance of JFrame
19. FahrenheitToCelsuis JButton b=new JButton("click");//creating instance of JButton

b.setBounds(130,100,100, 40);//x axis, y axis, width, height

f.add(b);//adding button in JFrame

f.setSize(400,500);//400 width and 500 height


import java.util.*;
f.setLayout(null);//using no layout managers
class FahrenheitToCelsius {
f.setVisible(true);//making the frame visible
public static void main(String[] args) { float temperatue;
}
Scanner in = new Scanner(System.in);
}
System.out.println("Enter temperatue in Fahrenheit");
temperatue = in.nextInt(); 21.FloydTriangle
temperatue = ((temperatue - 32)*5)/9;

System.out.println("Temperatue in Celsius = " + temperatue);

import java.util.Scanner;

class FloydTriangle

public static void main(String args[])

{
8

int n, num = 1, c, d;

Scanner in = new Scanner(System.in);

System.out.println("Enter the number of rows of floyd's


triangle you want");

n= in.nextInt(); import java.util.*;

System.out.println("Floyd's triangle :-"); class GarbageCollection

for ( c = 1 ; c <= n ; c++ ) {

{ public static void main(String s[]) throws Exception

for ( d = 1 ; d <= c ; d++ ) {

{ Runtime rs = Runtime.getRuntime();

System.out.print(num+" "); System.out.println("Free memory in JVM before Garbage


Collection = "+rs.freeMemory());
num++;
rs.gc();
}
System.out.println("Free memory in JVM after Garbage
System.out.println(); Collection = "+rs.freeMemory());

} }

} }

22.ForLoop 24.GetInputFromUser

class ForLoop {
import java.util.Scanner;
public static void main(String[] args) { int c;
class GetInputFromUser
for (c = 1; c <= 10; c++) {
{
System.out.println(c);
public static void main(String args[])
}
{
}
int a;
}
float b;

23.GarbageCollection String s;

Scanner in = new Scanner(System.in);

System.out.println("Enter a string");
9

s= in.nextLine(); }

System.out.println("You entered string "+s); }

System.out.println("Enter an integer"); }

a= in.nextInt();
27.InsertImage
System.out.println("You entered integer "+a);

System.out.println("Enter a float");

b= in.nextFloat();

System.out.println("You entered float "+b);

} import java.sql.*;

25.HelloWorld import java.io.*;

public class InsertImage {

public static void main(String[] args) {

try{

Class.forName("oracle.jdbc.driver.OracleDriver");
class HelloWorld
Connection con=DriverManager.getConnection(
{
"jdbc:oracle:thin:@localhost:1521:xe","system","oracle");
public static void main(String args[])
PreparedStatement ps=con.prepareStatement("insert into
{ imgtable values(?,?)");
System.out.println("Hello World"); ps.setString(1,"Technolamror");
} FileInputStream fin=new FileInputStream("d:\\g.jpg");
ps.setBinaryStream(2,fin,fin.available()); int
}
i=ps.executeUpdate();

26.InetDemo System.out.println(i+" records affected");

con.close();

}catch (Exception e) {e.printStackTrace();}

}
import java.io.*;
}
import java.net.*;

public class InetDemo{


28.Integers
public static void main(String[] args){

try{

InetAddress ip=InetAddress.getByName("www.google.com");

System.out.println("Host Name: "+ip.getHostName());


System.out.println("IP Address:
"+ip.getHostAddress()); }catch(Exception
e){System.out.println(e);
10

class Integers {
31.LabelExample
public static void main(String[] arguments) { int c; //declaring
a variable

/* Using for loop to repeat instruction execution */

for (c = 1; c <= 10; c++) {

System.out.println(c);

29.IntToStringExample1
import java.awt.*;

class LabelExample{

public static void main(String args[]){

Frame f= new Frame("Label Example by Technolamror"); Label l1,l2;

class IntToStringExample1{ l1=new Label("First Label.");

public static void main(String args[]){ l1.setBounds(50,100, 100,30);

int i=200; l2=new Label("Second Label.");

l2.setBounds(50,150, 100,30);
String s=String.valueOf(i);
f.add(l1); f.add(l2);
System.out.println(i+100);//300 because + is binary plus
operatorSystem.out.println(s+100);//200100 because + is f.setSize(400,400);
string concatenation operator
f.setLayout(null);
}
f.setVisible(true);
} }

30.IPAddress }

31.Language

import java.net.InetAddress;

class IPAddress class Language {


{ String name;
public static void main(String args[]) throws Exception Language() {
{ System.out.println("Constructor method called.");
System.out.println(InetAddress.getLocalHost()); }
} Language(String t) {
} name = t;
11

} System.out.println("Third number is largest."); else

public static void main(String[] args) { Language cpp = new System.out.println("Entered numbers are not distinct.");
Language(); Language java = new Language("Java");
}
cpp.setName("C++");
}
java.getName();
33.LAstIndexOfExample
cpp.getName();

void setName(String t) {

name = t;

}
public class LastIndexOfExample{
void getName() {
public static void main(String args[]){
System.out.println("Language name: " + name);
String s1="hello";
}
String s2="hello";
}
String s3="meklo";

32.LargestOfThreeNumbers String s4="hemlo";

System.out.println(s1.compareTo(s2));

System.out.println(s1.compareTo(s3));

System.out.println(s1.compareTo(s4));

}
import java.util.Scanner;
34.LinearSearch
class LargestOfThreeNumbers

public static void main(String args[])

int x, y, z;

System.out.println("Enter three integers "); Scanner in = new


Scanner(System.in);

x= in.nextInt(); import java.util.Scanner;

y= in.nextInt(); class LinearSearch

z= in.nextInt(); {

if ( x > y && x > z ) public static void main(String args[])

System.out.println("First number is largest."); else if ( y > x {


&& y > z )
int c, n, search, array[];
System.out.println("Second number is largest."); else if ( z > x
&& z > y ) Scanner in = new Scanner(System.in);
12

System.out.println("Enter number of elements"); }

n = in.nextInt(); }

array = new int[n]; 36.MatrixMultiplication

System.out.println("Enter " + n + " integers");

for (c = 0; c < n; c++)

array[c] = in.nextInt();

System.out.println("Enter value to find"); search =


in.nextInt();
import java.util.Scanner;
for (c = 0; c < n; c++)
class MatrixMultiplication
{
{
if (array[c] == search) /* Searching element is present */
public static void main(String args[])
{
{
System.out.println(search + " is present at location " + (c + 1)
+ int m, n, p, q, sum = 0, c, d, k;

"."); Scanner in = new Scanner(System.in);

break; System.out.println("Enter the number of rows and columns


of first matrix");
}
m= in.nextInt();
}
n= in.nextInt();
if (c == n) /* Searching element is absent */
int first[][] = new int[m][n];
System.out.println(search + " is not present in array.");

}
System.out.println("Enter the elements of first matrix");
}
for ( c = 0 ; c < m ; c++ )
35.MapInterfaceExample
for ( d = 0 ; d < n ; d++ )

first[c][d] = in.nextInt();

System.out.println("Enter the number of rows and columns


of second matrix");
import java.util.*;
p= in.nextInt();
class MapInterfaceExample{
q= in.nextInt();
public static void main(String args[]){ Map<Integer,String>
map=new HashMap<Integer,String>(); if ( n != p )
map.put(100,"Rajendra");
System.out.println("Matrices with entered orders can't be
map.put(101,"Lamror"); multiplied with each other.");

map.put(102,"Technolamror"); else

for(Map.Entry m:map.entrySet()){ {

System.out.println(m.getKey()+" "+m.getValue()); int second[][] = new int[p][q];

} int multiply[][] = new int[m][q];


13

System.out.println("Enter the elements of second matrix"); System.out.println("Constructor method is called when an


object of it's class is created");
for ( c = 0 ; c < p ; c++ )
}
for ( d = 0 ; d < q ; d++ )
// Main method where program execution begins
second[c][d] = in.nextInt();
public static void main(String[] args) { staticMethod();
for ( c = 0 ; c < m ; c++ )
Methods object = new Methods();
{
object.nonStaticMethod();
for ( d = 0 ; d < q ; d++ )
}
{
// Static method
for ( k = 0 ; k < p ; k++ )
static void staticMethod() {
{
System.out.println("Static method can be called without
sum = sum + first[c][k]*second[k][d]; creating object");

} }

multiply[c][d] = sum; // Non static method

sum = 0; void nonStaticMethod() {

} System.out.println("Non static method must be called by


creating an object");
}
}
System.out.println("Product of entered matrices:-");
}
for ( c = 0 ; c < m ; c++ )
38.MultiArray
{

for ( d = 0 ; d < q ; d++ )

System.out.print(multiply[c][d]+"\t");

System.out.print("\n");

} class MultiArray{

} public static void main(String args[]){

} //declaring and initializing 2D array

} int arr[][]={{1,2,3},{2,4,5},{4,4,5}};

37.Methods //printing 2D array

for(int i=0;i<3;i++){

for(int j=0;j<3;j++){

System.out.print(arr[i][j]+" ");

}
class Methods {
System.out.println();
// Constructor method
}
Methods() {
}
14

} marksObtained = input.nextInt();

39.MultiplicationTable if (marksObtained >= passingMarks) {

if (marksObtained > 90)

grade = 'A';

else if (marksObtained > 75)

grade = 'B';

else if (marksObtained > 60)

grade = 'C';
import java.util.Scanner; else
class MultiplicationTable grade = 'D';
{ System.out.println("You passed the exam and your grade is "
+ grade);
public static void main(String args[])
}
{
else {
int n, c;
grade = 'F';
System.out.println("Enter an integer to print it's
multiplication table"); System.out.println("You failed and your grade is " + grade);
Scanner in = new Scanner(System.in); }
n= in.nextInt(); }
System.out.println("Multiplication table of "+n+" is :-"); }
for ( c = 1 ; c <= 10 ; c++ ) 41.Notepad
System.out.println(n+"*"+c+" = "+(n*c));

40.NestedIfElse

import java.util.*;

import java.io.*;

class Notepad {
import java.util.Scanner;
public static void main(String[] args) { Runtime rs =
class NestedIfElse { Runtime.getRuntime();
public static void main(String[] args) { int marksObtained, try {
passingMarks; char grade;
rs.exec("notepad");
passingMarks = 40;
}
Scanner input = new Scanner(System.in);
catch (IOException e) {
System.out.println("Input marks scored by you");
System.out.println(e);
15

} con=DriverManager.getConnection("jdbc:oracle:thin:@localh
ost:1521:xe","system","oracl e");
}
//step3 create the statement object
}
Statement stmt=con.createStatement();
42.OddOrEven
//step4 execute query

ResultSet rs=stmt.executeQuery("select * from emp");


while(rs.next())

System.out.println(rs.getInt(1)+" "+rs.getString(2)+"
"+rs.getString(3)); //step5 close the connection object
import java.util.Scanner;
con.close();
class OddOrEven
}catch(Exception e){ System.out.println(e);}
{
}
public static void main(String args[])
}
{
44.Palindrome
int x;

System.out.println("Enter an integer to check if it is odd or


even "); Scanner in = new Scanner(System.in);

x= in.nextInt()
import java.util.*;
if ( x % 2 == 0 )
class Palindrome
System.out.println("You entered an even number."); else
{
System.out.println("You entered an odd number.");
public static void main(String args[])
}
{
}
String original, reverse = "";
43.OracleCon
Scanner in = new Scanner(System.in);

System.out.println("Enter a string to check if it is a


palindrome"); original = in.nextLine();

int length = original.length();

for ( int i = length - 1; i >= 0; i-- ) reverse = reverse +


import java.sql.*; original.charAt(i);
class OracleCon{ if (original.equals(reverse))
public static void main(String args[]){ System.out.println("Entered string is a palindrome."); else
try{ System.out.println("Entered string is not a palindrome.");
//step1 load the driver class }
Class.forName("oracle.jdbc.driver.OracleDriver"); //step2 }
create the connection object

Connection
16

45.PrimeNumbers status = 1;

num++;

}
import java.util.*;
46.Proc
class PrimeNumbers

public static void main(String args[])

int n, status = 1, num = 3;


import java.sql.*;
Scanner in = new Scanner(System.in);
public class Proc {
System.out.println("Enter the number of prime numbers you
public static void main(String[] args) throws
want");
Exception{ Class.forName("oracle.jdbc.driver.OracleDriver");
n= in.nextInt(); Connection

if (n >= 1) con=DriverManager.getConnection("jdbc:oracle:thin:@localh
ost:1521:xe","system","oracl e");
{
CallableStatement stmt=con.prepareCall("{call insertR(?,?)}");
System.out.println("First "+n+" prime numbers are :-"); stmt.setInt(1,1011);
System.out.println(2);
stmt.setString(2,"Amit");
}
stmt.execute();
for ( int count = 2 ; count <=n ; )
System.out.println("success");
{
}
for ( int j = 2 ; j <= Math.sqrt(num) ; j++ )
}
{
47.Programming
if ( num%j == 0 )

status = 0;

break; class Programming {

} //constructor method

} Programming() {

if ( status != 0 ) System.out.println("Constructor method called.");

{ }

System.out.println(num); public static void main(String[] args) {

count++; Programming object = new Programming(); //creating object

} }
17

} 50.ReplaceAllExample

48.RandomNumber

public class ReplaceAllExample2{

public static void main(String args[]){

String s1="My name is Rajendra. My name is lamror. My


name is Rhay."; String
replaceString=s1.replaceAll("is","was");//replaces all
occurrences of "is" to "was"

import java.util.*; System.out.println(replaceString);

class RandomNumber { }

public static void main(String[] args) { int c; }

Random t = new Random(); 51.Reversenumber

// random integers in [0, 100]

for (c = 1; c <= 10; c++) {

System.out.println(t.nextInt(100));

}
import java.util.Scanner;
}
class ReverseNumber
}
{
49.Recursion
public static void main(String args[])

int n, reverse = 0;

System.out.println("Enter the number to reverse");


public class Recursion {
Scanner in = new Scanner(System.in);
static int factorial(int n){
n= in.nextInt();
if (n == 1)
while( n != 0 )
return 1;
{
else
reverse = reverse * 10;
return(n * factorial(n-1));
reverse = reverse + n%10;
}
n = n/10;
public static void main(String[] args) {
}
System.out.println("Factorial of 5 is: "+factorial(5));
System.out.println("Reverse of entered number is "+reverse);
}
}
}
}
18

52.ReverseString SimpleDateFormat formatter = new


SimpleDateFormat("MM/dd/yyyy");

String strDate = formatter.format(date);

System.out.println("Date Format with MM/dd/yyyy :


"+strDate);

formatter = new SimpleDateFormat("dd-M-yyyy hh:mm:ss");


import java.util.*; strDate = formatter.format(date);

class ReverseString System.out.println("Date Format with dd-M-yyyy hh:mm:ss :


"+strDate);
{
formatter = new SimpleDateFormat("dd MMMM yyyy");
public static void main(String args[])
strDate = formatter.format(date);
{
System.out.println("Date Format with dd MMMM yyyy :
String original, reverse = ""; "+strDate);
Scanner in = new Scanner(System.in); formatter = new SimpleDateFormat("dd MMMM yyyy zzzz");
strDate = formatter.format(date);
System.out.println("Enter a string to reverse"); original =
in.nextLine(); System.out.println("Date Format with dd MMMM yyyy zzzz :
"+strDate);
int length = original.length();
formatter = new SimpleDateFormat("E, dd MMM yyyy
for ( int i = length - 1 ; i >= 0 ; i-- ) reverse = reverse +
HH:mm:ss z"); strDate = formatter.format(date);
original.charAt(i);
System.out.println("Date Format with E, dd MMM yyyy
System.out.println("Reverse of entered string is: "+reverse);
HH:mm:ss z : "+strDate);
}
}
}
}
53.DateFormat
54.

import java.text.ParseException;

import java.text.SimpleDateFormat;

import java.util.Date;

import java.util.Locale;

public class SimpleDateFormatExample2 {

public static void main(String[] args) {

Date date = new Date();

System.out.println("Date formate chnage by Technolamror


");

You might also like