Class 10 ICSE - Java

Class 10th Java aims to empower students by enabling them to build their own applications introducing some effective tools to enable them to enhance their knowledge, broaden horizons, foster creativity, improve the quality of work and increase efficiency.
It also develops logical and analytical thinking so that they can easily solve interactive programs. Students learn fundamental concepts of computing using object oriented approach in one computer language with a clear idea of ethical issues involved in the field of computing
Class 10th java topics includes revision of class 9th, constructors, user-defined methods, objects and classes, library classes , etc.

Conditional Constructor Programs

Program 1: Write a program to print the largest number out of three numbers
Solution:

import java.util.*;
class largest
{
public static void main(String args[])
{
int a,b,c;
Scanner sc=new Scanner(System.in);
System.out.println("Enter the three numbers:");
a=sc.nextInt();
b=sc.nextInt();
c=sc.nextInt();

    if(a>b && a>c)
	 {
	  	System.out.println("Largest number out of three numbers is="+a);
	 }
	 else if(b>a && b>c)
	 {
	  	System.out.println("Largest number out of three numbers is="+ b);
	 }
	 else
	 {
	  	System.out.println("Largest number out of three numbers is="+c);
	 }
}
}
                        

Program 2: Write a program to enter cost price and selling price and print profit or loss
Solution:
import java.util.*;
class price
{
public static void main(String args[])
{
int sp,cp;
Scanner sc=new Scanner(System.in);
System.out.println("Enter the selling price:");
sp=sc.nextInt();
System.out.println("Enter the cost price:");
cp=sc.nextInt();
if(cp>sp)
{
int loss=cp-sp;
System.out.println("Loss is="+loss);
}
else if (cp< sp)
{
    int profit=sp-cp;
System.out.println("profit is="+profit);
}
else
{
    System.out.println("No profit no loss");
}

}

}


                        

Program 3: Write a program to print day name on the basis of daynumber of the week inputed using switch case.
Solution:
import java.util.*;
class dayname
{
public static void main(String args[])
{
    int day;
    Scanner sc=new Scanner(System.in);
System.out.println("Enter the daynumber (from 1 to 7)");
day=sc.nextInt();
switch(day)
{
case 1:
{
System.out.println("This is monday");
break;
}
case 2:
{
System.out.println("This is tuesday");
break;
}
case 3:
{
System.out.println("This is wednesday");
break;
}
case 4:
{
System.out.println("This is thursday");
break;
}
case 5:
{
System.out.println("This is Friday");
break;
}
case 6:
{
System.out.println("This is saturday");
break;
}
case 7:
{
System.out.println("This is sunday");
break;
}
default:
{
System.out.println("Invalid daynumber");
break;
}
}
}
}
                        

Program 4: Write a program to check whether the alphabet entered is a vowel or consonant using switch fall through
Solution:
import java.util.*;
class vowel
{
public static void main(String args[])
{
    int  ch;
    Scanner sc=new Scanner(System.in);
System.out.println("Enter the word to check for vowel");
ch=sc.nextLine().charAt(0);
switch(ch)
{
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
System.out.println("It is a vowel");
break;
default:
System.out.println("It is a consonant");
}
}
}
                        

Program 5: Write a program to perform Arithmetic operations using switch-case
Solution:
import java.util.*;
class user
{
public static void main(String args[])
{     int a,b,result;
    boolean check=true;
      Scanner sc=new Scanner(System.in);
         System.out.println("Enter the first value:");
        a=sc.nextInt();
        System.out.println("Enter the second value");
        b=sc.nextInt();
        while(check){
         System.out.println("\nPress 1 for Addition \nPress 2 for Subtraction \nPress 3 for Multiplication \nPress 4 for Division\nPress 5 to end");
        int choice=sc.nextInt();
        switch(choice)
        {
        case 1:
        {
        result=a+b;
        System.out.println("Addition of "+a+" and "+b+" is="+result);
        break;
        }
         case 2:
        {
        result=a-b;
        System.out.println("Subtraction of "+a+" and "+b+" is="+result);
        break;
        }
         case 3:
        {
        result=a*b;
        System.out.println("Multiplication of "+a+" and "+b+" is="+result);
        break;
        }
         case 4:
        {
        result=a/b;
        System.out.println("Division of "+a+" and "+b+" is="+result);
        break;
        }
          case 5:
        {
           check=false;
           break;
        }
          default:
        {
        System.out.println("Invalid choice");
        }
        }
    }
        }
}
                        

Contact Us

REACH US

SERVICES

  • CODING
  • ON-LINE PREPARATION
  • JAVA & PYTHON

ADDRESS

B-54, Krishna Bhawan, Parag Narain Road, Near Butler Palace Colony Lucknow
Contact:+ 919839520987
Email:info@alexsir.com