Saturday, November 27, 2021
Saturday, July 17, 2021
Methods in Java
What is method?
What is the advantages of using methods?
What is method prototype?
What is method signature?
What is formal parameter?
What is actual parameter?
Code 01
- import java.util.Scanner;
- public class ParkingLot
- {
- int vno;
- int hours;
- double bill;
- public static void main(String args[])
- {
- ParkingLot ob = new ParkingLot();
- ob.input();
- ob.calculate();
- ob.display();
- }
- void input()
- {
- Scanner sc = new Scanner(System.in);
- System.out.print("Enter the vehicle number: ");
- vno = sc.nextInt();
- System.out.print("Enter the hours vehicle is parked: ");
- hours = sc.nextInt();
- }
- void calculate()
- {
- if(hours<=1)
- bill = 3;
- else
- bill = 3+(hours-1)*1.5;
- }
- void display()
- {
- System.out.println("Vehicle Number = "+vno);
- System.out.println("Hours Parked = "+hours);
- System.out.println("Bill Amount = "+bill);
- }
- }
- import java.util.Scanner;
- public class FunctionOverload
- {
- void compare(int a,int b)
- {
- if(a>b)
- System.out.println(a+" is greater.");
- else if(a<b)
- System.out.println(b+" is greater.");
- else
- System.out.println("Both are equal.");
- }
- void compare(char a,char b)
- {
- if((int)a>(int)b)
- System.out.println(a+" is greater.");
- else if((int)a<(int)b)
- System.out.println(b+" is greater.");
- else
- System.out.println("Both are equal.");
- }
- void compare(String a,String b)
- {
- int l1 = a.length();//6
- int l2 = b.length();//7
- if(l1>l2)
- System.out.println(a+" is greater in length");
- else if(l1<l2)
- System.out.println(b+" is greater in length");
- else
- System.out.println("Both are equal");
- }
- public static void main(String args[])
- {
- FunctionOverload ob = new FunctionOverload();
- Scanner sc = new Scanner(System.in);
- int p,q;
- p = sc.nextInt();
- q = sc.nextInt();
- ob.compare(p,q);
- char ch1,ch2;
- ch1 = sc.next().charAt(0);
- ch2 = sc.next().charAt(0);
- ob.compare(ch1,ch2);
- String s1,s2;
- s1 = sc.next();
- s2 = sc.next();
- ob.compare(s1,s2);
- }
- }
Saturday, February 13, 2021
Previous Year Questions on Strings
ICSE Class 10 Computer Applications
Previous Year Questions on String
Tuesday, February 2, 2021
Java Language Fundamentals
Hi All,
Here we all will be discussing about some fundamental concepts of Java.
1. Identifiers
Identifiers can be defined as a name in java program which can be used for identification purpose. It can be a method name, variable name, class name, label name, package name or interface name.
For example:
For example:
1. Identifiers can have alphabets (a-z, A-Z), digits(0-9), underscore(_) and dollar sign($).
2. Identifiers can be of any length.
3. Identifiers must not begin with digits.
4. Identifiers are case sensitive i.e. uppercase and lowercase letters are treated differently.
5. We cannot use reserved words as identifiers.
6. All predefined classes and interfaces can be use as identifiers name. Even though it is valid but it is not a good programming practice.
Reserved Words:
Java has 53 reserved words.
Saturday, January 30, 2021
Different type of numbers generally asked in Java ICSE Board exams
1. Disarium Number
2. Amicable Pair
3. Unique Number
4. BUZZ number
My only motive is to provide you most simplest and easy way to do coding. Targeted Audience ICSE 9th and 10th Class. More numbers will be added soon.........................
Write a java program to check whether the entered number is a Disarium Number. A number is called a Disarium if sum of the digits powered with its respective positions is equal to original number itself.
For example: 175 is a Disarium number.
175 = 11+72+53 = 1+49+125 = 175
Here in this program we will be using Scanner class to take the input from the user.
public class Disarium
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter a number : ");
int num = sc.nextInt();
int temp = num, rem = 0, sum = 0;//to keep original number intact taking temp
String s = Integer.toString(num);
int len = s.length(); //to calculate the length of number converted to string
while(temp>0)
{
rem = temp % 10;
sum = sum + (int)Math.pow(rem,len--);
temp = temp/10;
}
if(sum == num) //to check whether the original number is equal to the sum
System.out.println("Disarium Number.");
else
System.out.println("Not a Disarium Number.");
}
Question 2 : Amicable Pair
Write a java program to check whether the entered pair is a Amicable Pair. Amicable pair are so related that sum of proper divisors of each is equal to other number.
Amicable numbers are:(220,284), (1184,1210), (2620,2924), (5020,5564), etc.
For Example: 220 and 284 are amicable pair.
Divisors of 220 = 1,2,4,5,10,11,20,22,44,55,110
Sum of divisors of 220 = 1+2+4+5+10+11+20+22+44+55+110 = 284
Divisors of 284 = 1,2,4,71,142
Sum of divisors of 284 = 1+2+4+71+142 = 220
Here 284 is not equal to 220. And sum of divisors is equal to other number itself.
import java.util.Scanner;
public class AmicableNumber
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter first number: ");
int num1 = sc.nextInt();
System.out.print("Enter second number: ");
int num2 = sc.nextInt();
int sumNum1 = 0, sumNum2 = 0;
for(int i=1;i<num1;i++)
{
if (num1%i==0)
sumNum1 = sumNum1+i;
}
for(int i=1;i<num2;i++)
{
if (num2%i==0)
sumNum2 =sumNum2+i;
}
if ((sumNum1 == num2) && (sumNum2 == num1) && (num1!=num2))
System.out.println("Amicable pair");
else
System.out.println("Not amicable pair");
}
}
Output of the code:
Question 3 : Unique Number
Question 4 : BUZZ Number
Saturday, January 23, 2021
Java program to convert to binary number to decimal number.
Conversion of binary number to decimal number and its vice versa is one of the most important concept in understanding computer logics and it designs.
Binary number is expressed in base 2. It is made up of 0s or 1s.
Example of binary number = 10101
A bit is a single binary digit. The example given above has 5 bits.
Decimal number is expressed in base 10. We can use digits from 0 to 9.
Example of decimal number = 21
Below is the program to do the conversion from Binary to Decimal:
Check whether the word is Special word or Palindrome word.
Special words are those words which starts and ends with the same letter. Examples: EXISTENCE COMIC WINDOW Palindrome words are those words...