0% found this document useful (0 votes)
5 views16 pages

Computer Project

Uploaded by

ritamta8
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)
5 views16 pages

Computer Project

Uploaded by

ritamta8
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

Question 1 :

import [Link] ;
class ParkingLot
{
int vno ;
int hours ;
double bill ;
void input()
{
Scanner sc = new Scanner ([Link]) ;
vno = [Link]();
hours = [Link]() ;
}
void calculate ()
{
if (hours == 1 )
bill = 3 ;
else
bill = 3 + (hours - 1 )* 1.50 ;

}
void display ()
{
[Link](bill) ;
[Link](vno) ;

}
public static void main (String args[])
{
ParkingLot t = new ParkingLot() ;
[Link]() ;
[Link]() ;
[Link]() ;
}
}
Question 2 :
import [Link] ;
class BookFair {
String Bname ; double price ;
BookFair()
{
Bname = "" ;
price = 0.0 ;
}
void input ()
{
Scanner sc = new Scanner([Link]) ;
Bname = [Link]() ;
price = [Link]() ;
}
void calculate ()
{
if (price <= 1000)
price = price - (0.02) * price ;
else if (price <= 3000)
price = price - (0.1)* price ;
else
price = price - (0.15)*price ;
}
void display ()
{
[Link](Bname) ;
[Link](price) ;
}
public static void main(String[] args) {
BookFair s = new BookFair() ;
[Link]() ;
[Link]() ;
[Link]() ;

}
}
Question 3 :
import [Link] ;
class ShowRoom {
String name ;
long mobno ;
double dis ;
double cost ;
double amount ;
ShowRoom()
{
name = "" ;
mobno = 0 ;
dis = 0.0 ;
cost = 0.0 ;
amount = 0.0 ;
}
void input ()
{
Scanner sc = new Scanner ([Link]);
name = [Link]() ;
mobno = [Link]() ;
cost = [Link]() ;

}
void calculate()
{
if (cost <= 10000)
dis = ((5*cost)/100) ;
else if (cost > 10000 && cost<= 20000)
dis = (10*cost)/100 ;
else if (cost > 20000 && cost <= 35000)
dis = (15*cost)/100 ;
else
dis = (20*cost) / 100 ;
amount = cost - dis ;
}
void display()
{
[Link]("Amount" + amount) ;
[Link]("pRICE IS " + cost ) ;
[Link]("dis is " + dis ) ;
}
public static void main(String[] args)
{
ShowRoom t = new ShowRoom() ;
[Link]() ;
[Link]() ;
[Link]() ;

}
}
Question 4 :
import [Link] ;
class S {
public static void main (String [] args)
{
Scanner sc = new Scanner ([Link]) ;
int a [] = new int[15] ;
for (int i = 0 ; i < 15 ; i ++)
{
a[i] = [Link]() ;
}
for (int i = 0 ; i < 14 ; i ++)
{
for (int j = 0 ; j < 14 - i ; j ++)
{
if (a[j] > a[j+1])

{
int temp = a[j] ;
a[j] = a[j+1] ;
a[j+1] = temp ;
}
}
}
for (int i = 0 ; i < 14 ; i ++)
{
[Link](a[i]) ;
}
}
}
Question 5 :
class S {
public static void main (String [] args)
{
for (int i = 1000 ; i < 10000 ; i ++)
{
int c = i ;
int t = i / 100 ;
int a = i % 100 ;
if (c == (t+a)*(t+a))
[Link](c+"is a tech number") ;

}
}
}
Question 6 :
import [Link];

class S {
public static void main (String [] args)
{
Scanner sc = new Scanner([Link]);
int n = [Link]();
int r = 0, s = 0;
int c = n;

while (n > 0) {
r = n % 10;
s = s + r;
n = n / 10;
}

if (c % s == 0)
[Link]("It is a Niven number");
else
[Link]("It is not a Niven number");
}
}
Question 7 :
import [Link] ;
class multiple
{
public static void main (String args [] )
{
Scanner sc = new Scanner ([Link]) ;
String arr[] = new String[40] ;
for (int i = 0 ;i < 40 ; i ++ )
{
arr[i] = [Link]();
}
int n = [Link] ;
for (int i = 0 ; i < n-1 ; i ++)
{
int minind = i ;
for (int j = i + 1 ; j < n ; j ++)
{
if (arr[j] . length() > arr[minind].length())
{
minind = j ;
}
}
String temp = arr[i] ;
arr[i] = arr[minind] ;
arr[minind] = temp ;
}
for (int j = 0 ; j < n ; j ++)
{
[Link](arr[j]) ;
}
}
}

Question 8 :
import [Link] ;
class sw
{
public static void main(String[] args)
{
Scanner sc = new Scanner ([Link]) ;
int n = [Link]() ;
switch(n)
{
case 1 :
{
int count = 1 ;
for (int i = 1 ; i <= 5 ; i ++)
{
for (int j = 1 ; j <= i ; j ++)
{
[Link](count++ + " ") ;
}
[Link]() ;
}
break ;
}
case 2 :
{
String a = "ICSE" ;
for (int i = 1 ; i <= 4; i ++)
{
for (int j = 0 ; j <= i - 1 ; j ++)
[Link]([Link](j)) ;
[Link]() ;
}
break ;
}

}
}
}
Question 9 :
import [Link] ;
class sw
{
public static void main(String[] args)
{
Scanner sc = new Scanner ([Link]) ;
String s = [Link]() ;
boolean flag1 = true ;
for (int i = 0 ; i< [Link]() ; i ++)
{
if ([Link](i) != [Link]([Link]() - i - 1))
flag1 = false ;
}
if (flag1 == true )
[Link]("It is a palindrome") ;
else
{
if ([Link](0) == [Link]([Link]()-1))
[Link]("it is special");
else
[Link]("It aint special") ;
}
}
}
Question 10 :

class ain {
public static void main(String[] args) {
for (int j = 1 ; j <= 98 ; j ++)
{
if (prime (j) == true && prime (j+2)== true )
{
[Link](j +" ") ;
[Link](j+2 ) ;
[Link]() ;
}
}
}
static boolean prime (int n )
{
int count = 0 ;
for (int i = 1 ; i <= n ; i ++)
{
if (n % i == 0 )
count ++ ;
}
if (count == 2 )
return true ;
else
return false ;

}
}

Question 11
:import [Link] ;
class multipl
{
public static void main (String args [] )
{
Scanner sc = new Scanner ([Link]) ;
int n = [Link]() ;
int m =[Link]() ;
[Link]("The fact that first number is prime is " + primecheck(n)) ;
[Link]("The fact that first number is palindrome is " + palicheck(n)) ;
[Link]("The fact that second number is prime is " + primecheck(m)) ;
[Link]("The fact that second number is palindrome is " + palicheck(m)) ;
}
static boolean primecheck(int n )
{
int count = 0 ;
for (int i = 1 ; i <= n ; i ++)
{

if (n % i == 0 )
count ++ ;
}
if (count == 2)
return true ;
else
return false ;
}
static boolean palicheck(int n )
{
int c = n ;
int r = 0 ; int s = 0 ;
while (n > 0)
{
r = n % 10 ;
s = s * 10 + r ;
n = n / 10 ;
}
if (s == c )
return true ;
else
return false ;

}
}

Question 12 :
import [Link];
class spy {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]) ;
int n = [Link]() ;
int r = 0 ;
int p = 1 ;
int s = 0 ;
while (n > 0 )
{
r = n % 10 ;
p=r*p;
s=s+r;
n = n / 10 ;
}
if (p == s )
[Link]("it is a spy number ") ;
else
[Link]("it is not spy number") ;
}
}

Question 13 :
import [Link] ;
class trans
{
public static void main (String args[])
{
Scanner sc = new Scanner ([Link]) ;
int arr [][] = new int [3][3] ;
for (int i = 0 ; i < 3 ; i ++)
{
for (int j = 0 ; j < 3 ; j ++)
{
arr[i][j] =[Link]() ;
}
}
int arr1[][] = new int[3][3];
for (int i = 0 ; i < 3 ; i ++)
{
for (int j = 0 ; j < 3 ; j ++)
{
arr1[j][i] = arr[i][j] ;
}
}
for (int i = 0 ; i < 3; i ++)
{
for (int j = 0 ; j < 3 ; j ++)
{
[Link](arr1[i][j] + " ") ;

}
[Link]() ;
}
}
}

Question 14 :

class pa{
public static void main(String[] args) {
[Link](" ") ;
for (int i = 1 ; i <= 3 ; i ++)
{
for (int k = 1 ; k <= 3 - i ; k ++)
{
[Link](" ") ;
}
for (int j = 1 ; j <= 2*i - 1 ; j ++)
{
[Link]("* ") ;
}
[Link]() ;
}
}
}
Question 15 :
import [Link] ;
class revs
{
public static void main (String args[])
{
Scanner sc = new Scanner ([Link]) ;
int n = [Link]() ;
int r = 0;
int s = 0 ;
int c = 0 ;
for (int i = 4 ; i <= (n+4) ; i ++)
{
s=i*i;
while (s > 0 )
{
r = s % 10 ;
c = c * 10 + r ;
s = s / 10 ;
}
[Link](c+",") ;
c=0;
}
}
}

Question 16 :
import [Link] ;
class palint {
public static void main(String[] args) {
Scanner sc = new Scanner ([Link]) ;
String s = [Link]() ;
int count = 0 ;
for (int i = 0 ; i < [Link]() ; i ++)
{
if ([Link](i) == 'a' || [Link](i) == 'e' || [Link](i) == 'i' || [Link](i) == 'o' ||
[Link](i) == 'u' || [Link](i) == 'A' || [Link](i) == 'E' || [Link](i) == 'I' || [Link](i) == 'O'
||[Link](i) == 'U')
count ++ ;
}
[Link](count) ;
}
}

Question 17 :
import [Link] ;
class multipica
{
public static void main (String args [] )
{
Scanner sc = new Scanner ([Link]) ;
int m = [Link]() ;
int n = [Link]() ;
int p = [Link]() ;
int q = [Link]() ;
int A [][] = new int[m][n] ;
int B[][] = new int [p][q] ;
for (int i = 0 ; i < m ; i ++)
{
for (int j = 0 ; j < n ; j ++)
{
A[i][j] = [Link]() ;
}
}
for (int i = 0 ; i < p ; i ++)
{
for (int j = 0 ; j < q ; j ++)
{
B[i][j] =[Link]() ;
}
}
if (n != p )
{
[Link]("Multiplication is not possible ") ;
break ;
}
int C[][] = new int[m][q] ;

for (int t = 0 ; t < m ; t ++)


{
for (int s = 0 ; s < q ; s ++)
{
}
}
}
}

Question 18 :
import [Link] ;
class palint {
public static void main(String[] args) {
Scanner sc = new Scanner ([Link]) ;
int n = [Link]() ;
int a [] = new int [n] ;
for (int i = 0 ; i < n ; i ++)
{
a [i] = [Link]() ;
}
for (int i = 0 ; i < n ; i ++)
{
if (pali(a[i]) == true )
[Link](a[i]) ;
}
}
static boolean pali (int n )
{
int c = n ;
int r = 0 ; int s = 0 ;
while (n > 0 )
{
r = n % 10 ;
s = s * 10 + r ;
n = n / 10 ;
}
if (s == c )
return true ;
else
return false ;
}
}
Question 19 :
Question 20 :
import [Link] ;
class palin {
public static void main(String[] args) {
Scanner sc = new Scanner ([Link]) ;
int a[] = new int [10] ;
int flag1 = 0 ;
for (int i = 0 ; i < 10 ; i ++)
{
a[i] = [Link]() ;
}
[Link]("What number should i search for ?") ;
int n = [Link]() ;
for (int i = 0 ; i < 9 ; i ++)
{
if (a[i] == n )
{
flag1 = 1 ;
break ;
}
}
if (flag1 == 0 )
[Link]("Search element not found") ;
else
[Link]("Search element found") ;
}
}

Question 21 : import [Link] ;


class binary
{
public static void main (String args[])
{
Scanner sc = new Scanner ([Link]) ;
String arr[] = new String[10] ;
for (int i = 0 ; i < 10 ; i ++)
{
arr[i] = [Link]() ;
}
[Link]("What should i search for ?") ;
String search = [Link]() ;
int mid = 0 ;
int pos = 0 ;
int s = 0 ; int e = [Link] - 1 ;
while (s <= e )
{
mid = (s+e) /2 ;
if (arr[mid].equals(search))
{
pos = mid ;
break ;
}
if (arr[mid].compareTo(search) < 0)
s = mid + 1 ;
else
e = mid - 1 ;
}
[Link]("The required element is present at " + (pos +1) ) ;
}
}

Question 22 :
import [Link] ;
class unique
{
public static void main (String args[])
{
int r = 0 ; int s = 0 ; int c = 0 ; int p = 0 ;
int flag1 = 0 ;
int flag = 0 ;
Scanner sc = new Scanner ([Link]) ;
[Link]("Please enter any number") ;
int n = [Link]() ;
int copy = n ;
int cop = n ;
while (copy > 0 )
{
r = copy % 10 ;
while (cop > 0 )
{
p = cop % 10 ;
if (p == r )
flag ++ ;
cop = cop / 10 ;
}
if (flag >=2 )
{
flag1 = 1 ;
break ;
}
flag = 0 ;
cop = n ;
copy = copy / 10 ;

}
if (flag1 == 0 )
{
[Link]("Its an unique number" ) ;
}
else
[Link]("it is not an unique number ");
}
}
Question 23 :
import [Link] ;
class inte
{
public static void main(String args[])
{
Scanner sc = new Scanner ([Link]) ;
int a [] = new int [10] ;
for (int i = 0 ; i < 10 ; i ++)
{
a[i] = [Link]() ;
if (a[i] == 0)
break ;
}
for (int j = 0 ; j < 10 ; j ++)
{
int c = a[j] ;
int r= 0 ;
int s = 0 ;
while (c>0)
{
r = c % 10 ;
s = s * 10 + r ;
c = c / 10 ;
}
[Link](a[j] + " " + s) ;
}
}
}

Question 24:
import [Link] ;
class ldrd {
public static void main(String[] args) {
Scanner sc = new Scanner ([Link]) ;
int ld = 0 ; int rd = 0 ;
int arr[][] = new int[3][3] ;
for (int i = 0 ; i < 3 ; i ++)
{
for (int j = 0 ; j < 3 ; j ++)
{
arr[i][j] = [Link]() ;
}
}
for (int i = 0 ; i < 3 ; i ++)
{
for (int j = 0 ; j < 3 ; j ++)
{
if (i == j )
ld = ld + arr[i][j] ;
}
}
for (int i = 0 ; i < 3 ; i ++)
{
for (int j = 0 ; j < 3 ; j ++)
{
if (i + j == 2)
rd = rd + arr[i][j] ;
}
}
[Link]("Sum of left diagonals is " + ld) ;
[Link]("Sum of right diagonals is " + rd) ;
}
}
Question 25 :
import [Link] ;
class ldrd {
public static void main(String[] args) {
Scanner sc = new Scanner ([Link]) ;
String s = [Link]() ;
s=[Link]() ;
for (int i = 0 ; i < [Link]() ; i ++)
{
if ([Link](i) == 'A' ||[Link](i) == 'E'||[Link](i) == 'I'||[Link](i) == 'O' || [Link](i)
== 'U')
{
String r = [Link](i) ;

String t = [Link] (0,i );


[Link](r + t + "AY") ;
break ;
}
}

}
}

You might also like