Saturday, November 27, 2021

Java MCQs Part-01 | By LearnWithVishalGiri | ICSE Computer Application




1. Name the method that accepts a string without any space _________
2. The wrapper class to which the method parseInt() belongs to _____________
    a)integer
    b)Int 
    c)int
    d)Integer
3. The statement to stop the execution of a construct.
    a)System.exit(0)
    b)break
    c)continue
    d)Stop
4. !(2>1 && 5<7)
    a)true
    b)false
5. The default statement is optional in switch case.
    a)True
    b)False
6. The shorthand operator is left to right associative.
    a)True
    b)False
7. Tell the output:

8. Give the output: (X = 5)
X+ = X++ + ++X + --X +X
    a)29
    b)28
    c)26
    d)25
9. Give the output and convert into if else statement.




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


  1. import java.util.Scanner;
  2. public class ParkingLot 
  3. {
  4. int vno;
  5. int hours;
  6. double bill;
  7. public static void main(String args[])
  8. {
  9. ParkingLot ob = new ParkingLot();
  10. ob.input();
  11. ob.calculate();
  12. ob.display();
  13. }
  14. void input()
  15. {
  16. Scanner sc = new Scanner(System.in);
  17. System.out.print("Enter the vehicle number: ");
  18. vno = sc.nextInt();
  19. System.out.print("Enter the hours vehicle is parked: ");
  20. hours = sc.nextInt();
  21. }
  22. void calculate()
  23. {
  24. if(hours<=1)
  25. bill = 3;
  26. else
  27. bill = 3+(hours-1)*1.5;
  28. }
  29. void display()
  30. {
  31. System.out.println("Vehicle Number = "+vno);
  32. System.out.println("Hours Parked = "+hours);
  33. System.out.println("Bill Amount = "+bill);
  34. }
  35. }

-------------------------------------------------------------------------------------------

Code 02:

  1. import java.util.Scanner;
  2. public class FunctionOverload 
  3. {
  4. void compare(int a,int b)
  5. {
  6. if(a>b)
  7. System.out.println(a+" is greater.");
  8. else if(a<b)
  9. System.out.println(b+" is greater.");
  10. else
  11. System.out.println("Both are equal.");
  12. }
  13. void compare(char a,char b)
  14. {
  15. if((int)a>(int)b)
  16. System.out.println(a+" is greater.");
  17. else if((int)a<(int)b)
  18. System.out.println(b+" is greater.");
  19. else
  20. System.out.println("Both are equal.");
  21. }
  22. void compare(String a,String b)
  23. {
  24. int l1 = a.length();//6
  25. int l2 = b.length();//7
  26. if(l1>l2)
  27. System.out.println(a+" is greater in length");
  28. else if(l1<l2)
  29. System.out.println(b+" is greater in length");
  30. else
  31. System.out.println("Both are equal");
  32. }
  33. public static void main(String args[])
  34. {
  35. FunctionOverload ob = new FunctionOverload();
  36. Scanner sc = new Scanner(System.in);
  37. int p,q;
  38. p = sc.nextInt();
  39. q = sc.nextInt();
  40. ob.compare(p,q);
  41. char ch1,ch2;
  42. ch1 = sc.next().charAt(0);
  43. ch2 = sc.next().charAt(0);
  44. ob.compare(ch1,ch2);
  45. String s1,s2;
  46. s1 = sc.next();
  47. s2 = sc.next();
  48. ob.compare(s1,s2);
  49. }
  50. }






Saturday, February 13, 2021

Previous Year Questions on Strings

ICSE Class 10 Computer Applications 
Previous Year Questions on String




Year 2023
Question 1
Define a class to accept a string and print number of digits, alphabets and special characters in the string.

Example:      
INPUT:        S = KAPILDEV@83

OUTPUT:    Number of Digits - 2
                    Number of Alphabets - 8
                    Number of Special Characters - 1


Year 2022
Question 2
Define a class to accept a string, and print the characters with the uppercase and lowercase reversed, but all the other characters should remain the same as before

EXAMPLE:
INPUT: WelCoMe_2022
OUTPUT: wELcOmE_2022

Question 3
Define a class to declare an array to accept and store ten words. Display only those words which begin with the letter 'A' or 'a' and also end with the letter 'A' or 'a'

EXAMPLE:
Input: Hari, Anita. Akash, Amrita, Alina, Devi, Rishab, Jolin, Farha, AMITHA
Output:
Anita
Amrita
Alina
AMITHA

Question 4
Define a class to accept two strings of same length and form a new word in such a way that, the first character of the first word is followed by the first character of the second word and so on.
Example:
Input string 1-BALL
Input String 2- WORD
OUTPUT: BWAOLRLD

Year 2019
Question 5
Write a program to input a sentence and convert it into uppercase and count and display the total number of words starting with a letter 'A'.
Example:
Sample Input: ADVANCEMENT AND APPLICATION OF INFORMATION TECHNOLOGY ARE EVER CHANGING.
Sample Output : Total number of words starting with letter 'A' = 4.

Year 2018
Question 6
Write a program in Java to accept a string in lower case and change the first letter of every word to upper case. Display the new string. 
Sample input: we are in cyber world
Sample output : We Are In Cyber World

Year 2017
Question 7
Design a class to overload a function check ( ) as follows : 
(i) void check (String str, char ch) – to find and print the frequency of a character in a string.
Example : *
Input:
str = “success”
ch = ‘s’ .
Output:
number of s present is = 3

(ii) void check(String si) – to display only vowels from string si, after converting it to lower case.
Example:
Input:
s1 = “computer”
Output:
o u e

Year 2016
Question 8
Special words are those words which starts and ends with the same letter. 
Examples:
EXISTENCE
COMIC
WINDOW
Palindrome words are those words which read the same from left to right and vice versa
Examples:
MALAYALAM
MADAM
LEVEL
ROTATOR
CIVIC
All palindromes are special words, but all special words are not palindromes. Write a program to accept a word check and print Whether the word is a palindrome or only special word.

Year 2015
Question 9
Design a class to overload a function Joystring( ) as follows :
(i) void Joystring (String s, char ch1 char ch2) with one string argument and two character arguments that replaces the character argument ch1 with the character argument ch2 in the given string s and prints the new string.

Example:
Input value of s = “TECHNALAGY”
ch1=‘A’,
ch2=‘O’
Output: TECHNOLOGY

(ii) void Joystring (String s) with one string argument that prints the position of the first space and the last space of the given string s.

Example:
Input value of = “Cloud computing means Internet based computing”
Output: First index : 5
Last index : 36

(iii) void Joystring (String s1, String s2) with two string arguments that combines the two string with a space between them and prints the resultant string. 

Example :
Input value of s1 =“COMMON WEALTH”
Input value of s2 =“GAMES”
Output: COMMON WEALTH GAMES
(use library functions) 

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:

So we can see that there are 5 identifiers in the above program.

There are certain rules to follow while naming identifiers:

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.........................

Question 1 : Disarium Number

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+5= 1+49+125 = 175
Here in this program we will be using Scanner class to take the input from the user.

import java.util.Scanner;
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.");
}
}

Output of the code:

----------------------------------------------------------------------------------------------------------

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

Write a java program to check whether the entered number is a Unique Number or not. A number that does not have any duplicate digit is called Unique Number.
For example: 12345, 3456 are unique numbers.
122323, 2323 are not unique numbers.

import java.util.Scanner;
public class UniqueNumber 
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter a number: ");
int num = sc.nextInt();
boolean flag = false;
String str = Integer.toString(num);
int len = str.length();
for(int i=0;i<len-1;i++)
{
for(int j=i+1;j<len;j++)
{
if(str.charAt(i)==str.charAt(j))
{
flag = true;
break;
}
}
}
if(flag==false)
System.out.println("Unique Number");
else
System.out.println("Not Unique");
}
}
Output of the code:


----------------------------------------------------------------------------------------------------------

Question 4 : BUZZ Number

Write a java program to check whether the entered number is a BUZZ number or not. BUZZ number are those numbers whose last digit is 7 or divisible by 7.

import java.util.Scanner;
public class Buzz 
{
public static void main(String[] args) 
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter a number : ");
int num = sc.nextInt();
if(num%7==0 || num%10==7)
System.out.println(num+" is BUZZ number.");
else
System.out.println(num+" is not BUZZ number.");
}
}
Output of the code:



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:

import java.util.Scanner;
public class BinaryToDecimal 
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter a Binary number : ");
int binNum = sc.nextInt();
int temp = binNum;
int sum=0,i=0;
while(temp>0)
{
int rem = temp%10;
sum = sum+rem*(int)Math.pow(2,i);
temp = temp/10;
i++;
}
System.out.println("Decimal conversion of "+binNum+" = "+sum);
sc.close();
}
}



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...