Professional Documents
Culture Documents
BufferedReader;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
import java.io.InputStreamReader;
/**
*
* @author Srini
*/
public class Boat {
public static void main(String args[])
{
}
}
}
import java.io.BufferedReader;
import java.io.InputStreamReader;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Srini
*/
public class ArrayAddition {
public static void main(String args[])
{
System.out.println("Enter the number of elements in the 1st array");
}
System.out.println("Enter the number of elements in the 2nd array");
int count1=Integer.parseInt(br.readLine());
System.out.println("Enter the elements of the 2nd Array:");
for(j=0;j<count1;j++)
{
array2[j]=Integer.parseInt(br.readLine());
}
System.out.println("Enter Your
Choice:\n1.Merge\n2.Append\n3.Common\n4.Exit");
int choice=Integer.parseInt(br.readLine());
switch(choice)
{
case 1:
if(count>=count1)
{
m=0;
for(z=0;z<count;z++)
{
array3[m]=array1[z];
m++;
if(array2[z]!='\0')
{
array3[m]=array2[z];
m++;
}
}
}
else
{
z=0;
for(m=0;m<count1;m++)
{
if(array1[m]!='\0')
{
array3[z]=array1[m];
z++;
}
array3[z]=array2[m];
z++;
}
}
System.out.println("Arrays merged..");
for(i=0;array3[i]!='\0';i++)
System.out.print(array3[i]);
break;
case 2:
for(p=0;p<count;p++)
{
array3[p]=array1[p];
}
m=0;
for(;m<count1;p++)
{
array3[p]=array2[m];
m++;
}
System.out.println("Arrays Appended..");
for(i=0;array3[i]!='\0';i++)
System.out.print(array3[i]);
break;
case 3:
i=0;
for(p=0;p<count;p++)
{
for(m=0;m<count1;m++)
{
if(array1[p]==array2[m])
{
array3[i]=array1[p];
i++;
}
}
}
if(array3[0]!='\0')
{
System.out.println("Common Array Elements Addedd..");
for(i=0;array3[i]!='\0';i++)
System.out.print(array3[i]);
}
else
{
System.out.println("No Common Array Elements present..");
}
break;
case 4:
break;
default:
System.out.println("Invalid Choice");
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
import java.io.BufferedReader;
import java.io.InputStreamReader;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Srini
*/
public class Ball {
static float total=0.0f;
public static void main(String args[])
{
int count=0;
float final_height=0.0f,height;
System.out.println("Enter the height from where the ball is dropped(h) in metres");
InputStreamReader ins=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(ins);
try
{
height=Float.parseFloat(br.readLine());
total=height;
while(count<2 && height>0.0f)
{
final_height=(float)height*2/3;
System.out.println("final height"+final_height);
if(count<2)
{
total=total+2*final_height;
System.out.println("total"+total);
}
if(height==0.0f)
{
break;
}
height=final_height;
count++;
}
System.out.println("The balls would have travelled "+total+" metres by third
jump");
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
import java.io.BufferedReader;
import java.io.InputStreamReader;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Srini
*/
public class BtachDistribution {
public static void main(String args[])
{
System.out.println("Enter the number of batches");
}
}
}
import java.io.BufferedReader;
import java.io.InputStreamReader;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Srini
*/
public class Coins {
public static void main(String args[])
{
}
else
break;
}
count1=0;
diff=amount-total;
while(count1+1<=denomination[1])
{
if(25*count1<diff && total!=amount && diff/25!=0 )
{
count1++;
total=total+25;
diff=diff-25;
// System.out.println("came inside 25 paise");
}
else
break;
}
count2=0;
diff1=amount-total;
while(count2+1<=denomination[0])
{
if(10*count2<diff && total!=amount && diff1/10!=0 )
{
count2++;
total=total+10;
diff1=diff1-10;
// System.out.println("came inside 10 paise");
}
else
break;
}
if(total==amount)
{
System.out.println("Denominations are");
System.out.println(count+ " - 50 paise coins");
System.out.println(count1+ " - 25 paise coins");
System.out.println(count2+ " - 10 paise coins");
System.out.println("Total coins - "+(count+count1+count2));
}
else
{
System.out.println("Denominations cannot be made for the given amount");
}
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
import java.io.BufferedReader;
import java.io.InputStreamReader;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Srini
*/
public class DayOfWeek {
public static void main(String args[])
{
System.out.println("Enter the date(yyyy/mm/dd)");
InputStreamReader ins=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(ins);
String date;
int no_of_days,diff_years,diff_leap,day_of_week;
try
{
date=br.readLine();
int x=date.indexOf("/", 0);
String year=date.substring(0, x);
System.out.println("--"+year+"--");
String month=date.substring(x+1, date.indexOf("/", x+1));
String day=date.substring(date.lastIndexOf("/")+1);
System.out.println("--"+month+"--");
System.out.println("--"+day+"--");
diff_years=(Integer.parseInt(year)-1900);
diff_leap=diff_years/4;
no_of_days=diff_years*365+diff_leap;
if(Integer.parseInt(year)%4==0&& (Integer.parseInt(month)==1||
Integer.parseInt(month)==2))
no_of_days=no_of_days-1;
for(int i=1;i<Integer.parseInt(month);i++)
{
if(i==1||i==3||i==5||i==7||i==8||i==10||i==12)
no_of_days=no_of_days+31;
else if(i==2)
no_of_days=no_of_days+28;
else
no_of_days=no_of_days+30;
}
day_of_week=(no_of_days+Integer.parseInt(day))%7;
switch(day_of_week)
{
case 0:
System.out.println(date+" is a Sunday");
break;
case 1:
System.out.println(date+" is a Monday");
break;
case 2:
System.out.println(date+" is a Tueday");
break;
case 3:
System.out.println(date+" is a Wednesday");
break;
case 4:
System.out.println(date+" is a Thursday");
break;
case 5:
System.out.println(date+" is a Friday");
break;
case 6:
System.out.println(date+" is a Saturday");
break;
default:
System.out.println("Error");
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
import java.util.Iterator;
/**
*
* @author Srini
*/
public class Purchase {
public static void main(String args[])
{
ArrayList list=new ArrayList();
ArrayList updated_list=new ArrayList();
System.out.println("Enter the number of items in initial purchase list");
InputStreamReader ins=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(ins);
int initial_count,final_count,i,count=0;
Iterator i1=list.iterator();
Iterator i2=updated_list.iterator();
try
{
initial_count=Integer.parseInt(br.readLine());
System.out.println("Enter the items purchased (old list)");
for(i=1;i<=initial_count;i++)
{
System.out.println("Item "+i+": ");
list.add(br.readLine());
}
System.out.println("Enter the number of items in final/updated purchase list");
final_count=Integer.parseInt(br.readLine());
System.out.println("Enter the items purchased (updated list)");
for(i=1;i<=final_count;i++)
{
System.out.println("Item "+i+": ");
updated_list.add(br.readLine());
}
//System.out.println("size of old list"+list.size());
//System.out.println("size of new list"+updated_list.size());
i=0;
while(i<list.size())
{
if(updated_list.contains(list.get(i)))
{
count++;
}
else
{
System.out.println("Item "+list.get(i)+" Deleted");
}
i++;
}
i=0;
while(i<updated_list.size())
{
//System.out.println("came in");
if(list.contains(updated_list.get(i)))
{
}
else
{
count++;
System.out.println("Item "+updated_list.get(i)+" Added");
}
i++;
}
if(count==updated_list.size())
{
System.out.println("Results Validated....");
}
}
catch(Exception e)
{
}
}
}
import java.io.BufferedReader;
import java.io.InputStreamReader;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Srini
*/
public class SecondLargest {
public static void main(String args[])
{
System.out.println("Enter the number of elements in the array");
}
int temp=array[0];
for(int j=1;j<count;j++)
{
if(array[j]>temp)
{
temp=array[j];
}
}
System.out.println("largest"+temp);
int k=0,z,status=0;
z=1;
while(z<temp)
{
for(k=0;k<count;k++)
{
if(array[k]==temp-z)
{
System.out.println("Second largest element is "+array[k]);
status++;
break;
}
}
if(status>0)
break;
z++;
}
if(status==0)
{
System.out.println("Second largest element not present return (-1)");
}
}
catch(Exception e)
{
}
}