import java.util.Arrays;
class sorting
{
public static void main(String args[])
{
if (args.length>0)
{
Arrays.sort(args);
System.out.println("");
for(int i=0;i
{
System.out.println(args[i]);
}
}
}
}
class sorting
{
public static void main(String args[])
{
if (args.length>0)
{
Arrays.sort(args);
System.out.println("");
for(int i=0;i
{
System.out.println(args[i]);
}
}
}
}
class rfactorial
{
public static void main(String args[])
{
int num=Integer.parseInt(args[0]);
int fact;
recursion r1=new recursion();
fact=r1.rec(num);
System.out.println("The factorial for "+num+" is = "+fact);
}
}
class recursion
{
public int rec(int a)
{
int f;
if(a==1 || a==0)
{
return(1);
}
else
{
f=a*rec(a-1);
return(f);
}
}
}
class rupeeDollar
{
public static void main(String args[])
{
double rup,dol;
dol=Double.parseDouble(args[0]);
if(dol>0)
{
rup=dol*45.38;
System.out.println("$"+dol+" is equal to "+rup+" INR");
}
}
}
class PrimeNumber {
public static void main (String args[])
{
int num=Integer.parseInt(args[0]);
int i,j;
for(i=1;i
{
for(j=2;j
{
int n=i%j;
if(n==0) {break;}
}
if(i==j)
{
System.out.print(" " + i);
}
}
}
}
class one{
public static void main(String args[])
{
double p,n,r,SI;
p=Double.parseDouble(args[0]);
n=Double.parseDouble(args[1]);
r=Double.parseDouble(args[2]);
SI=(p*n*r)/100;
System.out.println("The simple interese is: "+SI);
}
}
class occurance
{
public static void main(String args[])
{
String a;
String[] Arr;
Arr = new String[20];
int f=0,len;
len=args[0].length();
String str=args[0];
System.out.println(str);
for(int i=0;i
{
Arr[i]=str.substring(i,i+1);
System.out.println(Arr[i]);
}
}
}
class oddEven
{
public static void main(String args[])
{
int num=Integer.parseInt(args[0]);
if(num%2==0)
{
System.out.println("The number "+num+" is EVEN");
}
else
{
System.out.println("The number "+num+" is ODD");
}
}
}
class vehicle
{
vehicle(String c)
{
System.out.println(" Color is " +c+" ");
}
}
class bicycle extends vehicle
{
String name;
double speed;
bicycle(String c,String n, double s)
{
super(c);
speed=s;
name=n;
System.out.println(" Bicycle Name is "+name+" ");
}
void maxspeed()
{
System.out.println(" Max Speed is "+ speed);
}
}
class car extends vehicle
{
String name;
double speed;
car(String c,String n, double s)
{
super(c);
speed=s;
name=n;
System.out.println(" Car Name is "+name+" ");
}
void maxspeed()
{
System.out.println(" Max Speed is "+ speed);
}
}
class motors
{
public static void main(String args[])
{
bicycle b1=new bicycle("Black","BMW R1200",175F);
b1.maxspeed();
System.out.println("");
car c1=new car("Red","Lamborghini Galardo",382F);
c1.maxspeed();
}
}
class length
{
public static void main(String args[])
{
String val=args[0];
System.out.println("The length of "+val+" is : "+val.length());
}
}
class interChange
{
public static void main(String args[])
{
String val=args[0];
String f,l,newrep;
int len;
len=val.length();
f=val.substring(0,1);
l=val.substring(len-1,len);
System.out.println(val);
newrep=l+val.substring(1,len-1)+f;
System.out.println(newrep);
}
}
class digits
{
public static void main(String args[])
{
int dig=Integer.parseInt(args[0]);
int sum=0,rev=0;
float avg;
int len=args[0].length();
while(dig>0)
{
int r=dig%10;
sum=sum+r;
dig=dig/10;
rev=rev*10;
rev=rev+r;
}
avg=(float)sum/len;
System.out.println("The sum of digits is: "+sum);
System.out.println("The length of number is: "+len);
System.out.println("The average of the digits is: "+avg);
System.out.println("The reverse of digits is: "+rev);
}
}
class fibonacci{
public static void main(String args[])
{
int n=Integer.parseInt(args[0]);
int f=0,s=1;
int cur;
System.out.print(f+" "+s+" ");
do{
cur=f+s;
f=s;
s=cur;
System.out.print(cur+" ");
}while(cur
}
}
public class JavaPalindromeNumberExample {
public static void main(String[] args) {
//array of numbers to be checked
int numbers[] = new int[]{121,13,34,11,22,54};
//iterate through the numbers
for(int i=0; i < numbers.length; i++){
int number = numbers[i];
int reversedNumber = 0;
int temp=0;
/*
* If the number is equal to it's reversed number, then
* the given number is a palindrome number.
*
* For example, 121 is a palindrome number while 12 is not.
*/
//reverse the number
while(number > 0){
temp = number % 10;
number = number / 10;
reversedNumber = reversedNumber * 10 + temp;
}
if(numbers[i] == reversedNumber)
System.out.println(numbers[i] + " is a palindrome number");
else
System.out.println(numbers[i] + " is not a palindrome number");
}
}
}
JDBC Connection code to insert data using prepared statement.
import java.sql.*;
public class jdbc_insert
{
public static void main(String args[])
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn=DriverManager.getConnection("jdbc:odbc:Darshana");
PreparedStatement ps=conn.prepareStatement("insert into Students
values(?,?,?,?,?)");
ps.setString(1,"4");
ps.setString(2,"Priyanka");
ps.setString(3,"Punjab");
ps.setString(4,"9877654321");
ps.setString(5,"Classic");
ps.executeUpdate();
ps.close();
conn.close();
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
}
}
JDBC Connection code to get Name and roll no. of student from database Students.
import java.sql.*;
public class jdbc_select
{
public static void main(String args[])
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn=DriverManager.getConnection("jdbc:odbc:Students");
Statement st=conn.createStatement();
String sql1="select * from Student ";
ResultSet rs=st.executeQuery(sql1);
while(rs.next())
{
System.out.println(rs.getString("Roll_no"));
System.out.println(rs.getString("Name"));
}
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
}
}
import java.util.*;
import java.lang.*;
public class sort{
public static void main(String args[]){
int a[]={2,3,1,5,4};
for(int i=0;i<5;i++)
{
for(int j=i;j<5;j++)
{
if(a[i]>a[j])
{
int temp;
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
System.out.print(" " + a[i]);
}
}
}