Computer Project
Computer Project
ALGORITHM
Step 1: take variables and define an array with 10 elements in it.
Step 2: make the user input the elements in the array by a loop with variable 'i'.
Step 4:take an if statement to check if one number is less than the other. if yes then swap both the numbers, and in this way the loop keeps repeating
until all elements are sorted.
//program 6
import java.util.*;
class BubbleSort
int i,j,t;
for(i=0;i<10;i++)
{ num[i]=sc.nextInt();
} for(i=0;i<9;i++)
{ for(j=0;j<(9-i);j++)
if(num[j]<num[j+1])
t=num[j];
num[j]=num[j+1];
num[j+1]=t;
} }} }
PROGRAM 7
ALGORITHM
Step 1: take variables and define an array with 10 elements in it.
Step 2: make the user input the elements in the array by a loop with variable 'i'.
Step 4:take an if statement to check if one number is less than the other. if yes then swap both the numbers, and in this way the loop keeps repeating
until all elements are sorted.
//program 7
import java.util.*;
class SelectionSort
int i,j,t,min;
for(i=0;i<10;i++){
num[i]=sc.nextInt();
for(i=0;i<9;i++){
min=i;
for(j=i+1;j<10;j++){
if(num[j]<num[min])
min=j; }
t=num[i]
num[i]=num[min];
num[min]=t;
for(i=0;i<10;i++)
System.out.println(num[i]);
} }
2
PROGRAM 8
ALGORITHM
Step 1: take variables n and y and define them with day number as ‘n’ and year as ‘y’
Step 2: take an if statement where if ‘y’ is a leap year then,February should have 29 days, else 28
Step 3:take another if statement inside this and check where the day lies and between which month with those if staements
Step 4: print the out put along with the day ,month and year.
import java.util.*;
class DatewithNumberOfDays
int n,y;
y=sc.nextInt();
n=sc.nextInt();
if(y%4==0)
if(n<=31)
{//jan
System.out.println("january "+n);
if(n<=31+29)//feb
System.out.println("feb "+(n-31));
if(n<=31+29+31)//march
System.out.println("march "+(n-(31+29)));
3
}
if(n<=31+29+31+31)//april
System.out.println("april "+(n-(31+29+31)));
if(n<=31+29+31+31+31)//may
System.out.println("may "+(n-(31+29+31+31)));
if(n<=31+29+31+31+31+31)//june
System.out.println("june "+(n-(31+29+31+31+31)));
if(n<=31+29+31+31+31+31+31)//july
System.out.println("july "+(n-(31+29+31+31+31+31)));
if(n<=31+29+31+31+31+31+31+31)//august
System.out.println("aug "+(n-(31+29+31+31+31+31+31)));
if(n<=31+29+31+31+31+31+31+31+31)//september
System.out.println("sept "+(n-(31+29+31+31+31+31+31+31)));
if(n<=31+29+31+31+31+31+31+31+31+31)//october
System.out.println("oct"+(n-(31+29+31+31+31+31+31+31+31)));
if(n<=31+29+31+31+31+31+31+31+31+31+31)//nov
System.out.println("nov "+(n-(31+29+31+31+31+31+31+31+31)));
4
if(n<=31+29+31+31+31+31+31+31+31+31+31+31)//dec
System.out.println("dec "+(n-(31+29+31+31+31+31+31+31+31+31)));
else if(y%4!=0)
if(n<=31)//jan
System.out.println("january "+n);
if(n<=31+28)//feb
System.out.println("february "+(n-31));
if(n<=31+28+31)//march
System.out.println("march "+(n-(31+28)));
if(n<=31+28+31+31)//april
System.out.println("april "+(n-(31+28+31)));
if(n<=31+28+31+31+31)//may
System.out.println("may "+(n-(31+28+31+31)));
if(n<=31+28+31+31+31+31)//june
System.out.println("june "+(n-(31+28+31+31+31)));
if(n<=31+28+31+31+31+31+31)//july
System.out.println("july "+(n-(31+28+31+31+31+31)));
if(n<=31+28+31+31+31+31+31+31)//august
System.out.println("augus "+(n-(31+28+31+31+31+31+31)));
if(n<=31+28+31+31+31+31+31+31+31)//september
System.out.println("septemebr "+(n-(31+28+31+31+31+31+31+31)));
if(n<=31+28+31+31+31+31+31+31+31+31)//october
System.out.println("october "+(n-(31+28+31+31+31+31+31+31+31)));
if(n<=31+28+31+31+31+31+31+31+31+31+31)//nov
System.out.println("november "+(n-(31+28+31+31+31+31+31+31+31)));
if(n<=31+28+31+31+31+31+31+31+31+31+31+31)//dec
System.out.println("december "+(n-(31+28+31+31+31+31+31+31+31+31))); } }}
5
PROGRAM 9
import java.util.*;
class WordToNumber
int n;
char ch;
s = sc.nextLine();
n = sc.nextInt();
ch = s.charAt(i);
ch = (char)(ch + n);
enstr += ch;
ch = (char)(ch + n);
6
enstr += ch;
else
enstr += ch;