You are on page 1of 11

Q4_2011 import java.util.

*; public class mobike { int bno; int phno; String name; int days; int charge; void input() { Scanner kb = new Scanner(System.in); System.out.println("Enter bike's number :"); bno = kb.nextInt(); System.out.println("Enter phone number of the customer:"); phno = kb.nextInt(); System.out.println("Enter name of the customer :"); name = kb.next(); System.out.println("Enter number of days bike is taken on rent :");

days = kb.nextInt(); } void compute(){ int temp; if ( days < 5) charge = days * 500; else if (days < 10 ) { temp = days -5 ;

charge = temp * 400 + (5 * 500) ; } else charge = (days -10) * 200+ (5 * 400) + ( 5 * 500 ); } void display( ) { System.out.println("Bike No. \t Phone No \t Name \t No.of Days \t Charge"); System.out.println(bno + "\t" + phno +"\t"+name +"\t"+days + "\t"+charge); } } Q5_2011 import java.util.*;

class Selection { double [] weight; public void input() { weight = new double[10]; Scanner kb = new Scanner(System.in); for (int i=0; i<10; i++) { System.out.println("Enter weight "+(i+1)); weight[i] = kb.nextDouble(); } } public void selectionSort() { int i, j, maxIndex; double tmp; int n = weight.length; for (i = 0; i < n -1; i++) { maxIndex =

i;

for (j = i + 1; j < n; j++) if (weight[j] > weight[maxIndex]) maxIndex = j; if (maxIndex != i) { tmp = weight[i]; weight[i] = weight[maxIndex]; weight[maxIndex] = tmp; } } } public void display() { int n = weight.length; for( int i=0; i<n ; i++) { System.out.println(weight[i]+""); } } public static void main(String[] args ) {

Selection sel = new Selection(); sel.input(); sel.selectionSort(); sel.display(); } } Q6_2011 import java.util.*; public class Number {

public static int Factorial(int a ) { int fact =1; for(int i=1;i<=a;i++) { fact = fact*i; } return fact; } public static boolean specialNumber(int n) { int n1 = n, dig, sum =0; while (n1>0) { dig = n1 % 10; sum = sum + Factorial(dig) ; n1 = n1 /10; } if ( sum == n) return true;

else return false; } public static void main(String [] args ) { Scanner kb = new Scanner(System.in); System.out.println("Enter number "); int num = kb.nextInt(); if ( specialNumber(num) == true ) System.out.println(num+" is a special number "); else

System.out.println(num+" is NOT a special number "); } }

You might also like