0% found this document useful (0 votes)
56 views12 pages

Java ISC Class 12 Scanner

Uploaded by

Jai Ratan Mishra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
56 views12 pages

Java ISC Class 12 Scanner

Uploaded by

Jai Ratan Mishra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Java ISC Class 12 Scanner

2025-09-03
Contents

1 Sum of Two Numbers 3

2 Calculate Simple Interest 4

3 Find Largest of Three Numbers 5

4 Check Even or Odd 7

5 Calculate Area of Circle 8

6 Convert Celsius to Fahrenheit 9

7 Calculate Factorial of a Number 10

8 Check Leap Year 11


Java ISC Class 12 Practical Programs Using Scanner

1 Sum of Two Numbers

Algorithm:

1. Start

2. Input two integers using Scanner

3. Add the two numbers

4. Display the sum

5. End

Java Program:

import java.util.Scanner;
public class SumTwoNumbers {
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 sum = num1 + num2;
System.out.println(”Sum = ” + sum);
}
}

Sample Output:

Enter first number: 10


Enter second number: 20
Sum = 30

Variable Description:

3
Java ISC Class 12 Practical Programs Using Scanner

Variable Description Data Type

sc Scanner object to read input from Scanner


console

num1 First integer input from user int

num2 Second integer input from user int

sum Sum of num1 and num2 int

2 Calculate Simple Interest

Algorithm:

1. Start

2. Input principal, rate, and time using Scanner

3. Calculate simple interest = (principal * rate * time) / 100

4. Display the simple interest

5. End

Java Program:

import java.util.Scanner;
public class SimpleInterest {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print(”Enter principal: ”);
double principal = sc.nextDouble();
System.out.print(”Enter rate of interest: ”);
double rate = sc.nextDouble();
System.out.print(”Enter time in years: ”);
double time = sc.nextDouble();

4
Java ISC Class 12 Practical Programs Using Scanner

double interest = (principal * rate * time) / 100;


System.out.println(”Simple Interest = ” + interest);
}
}

Sample Output:

Enter principal: 10000


Enter rate of interest: 5
Enter time in years: 2
Simple Interest = 1000.0

Variable Description:

Variable Description Data Type

sc Scanner object for input Scanner

principal Principal amount double

rate Rate of interest per annum double

time Time in years double

interest Calculated simple interest double

3 Find Largest of Three Numbers

Algorithm:

1. Start

2. Input three integers using Scanner

3. Compare numbers to find the largest

4. Display the largest number

5. End

5
Java ISC Class 12 Practical Programs Using Scanner

Java Program:

import java.util.Scanner;
public class LargestOfThree {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print(”Enter first number: ”);
int a = sc.nextInt();
System.out.print(”Enter second number: ”);
int b = sc.nextInt();
System.out.print(”Enter third number: ”);
int c = sc.nextInt();
int largest = a;
if(b > largest) {
largest = b;
}
if(c > largest) {
largest = c;
}
System.out.println(”Largest number is ” + largest);
}
}

Sample Output:

Enter first number: 10


Enter second number: 30
Enter third number: 20
Largest number is 30

Variable Description:

6
Java ISC Class 12 Practical Programs Using Scanner

Variable Description Data Type

sc Scanner object for input Scanner

a First integer input int

b Second integer input int

c Third integer input int

largest Holds the largest number among a, b, c int

4 Check Even or Odd

Algorithm:

1. Start

2. Input an integer using Scanner

3. Check if number % 2 equals 0

4. If yes, print ”Even”, else print ”Odd”

5. End

Java Program:

import java.util.Scanner;
public class EvenOdd {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print(”Enter a number: ”);
int num = sc.nextInt();
if(num % 2 == 0) {
System.out.println(num + ” is Even”);
} else {

7
Java ISC Class 12 Practical Programs Using Scanner

System.out.println(num + ” is Odd”);
}
}
}

Sample Output:

Enter a number: 15
15 is Odd

Variable Description:

Variable Description Data Type

sc Scanner object for input Scanner

num Integer input to check parity int

5 Calculate Area of Circle

Algorithm:

1. Input radius

2. Calculate area = 3.1416 * radius * radius

3. Display area

Java Program:

import java.util.Scanner;
public class AreaCircle {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print(”Enter radius: ”);
double r = sc.nextDouble();
double area = 3.1416 * r * r;

8
Java ISC Class 12 Practical Programs Using Scanner

System.out.println(”Area = ” + area);
}
}

Sample Output:

Enter radius: 7
Area = 153.9384

Variable Description:

r radius of circle double

area calculated area double

6 Convert Celsius to Fahrenheit

Algorithm:

1. Input temperature in Celsius

2. Calculate Fahrenheit = (Celsius * 9/5) + 32

3. Display Fahrenheit

Java Program:

import java.util.Scanner;
public class CelsiusToFahrenheit {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print(”Enter Celsius: ”);
double c = sc.nextDouble();
double f = (c * 9 / 5) + 32;
System.out.println(”Fahrenheit = ” + f);
}
}

9
Java ISC Class 12 Practical Programs Using Scanner

Sample Output:

Enter Celsius: 25
Fahrenheit = 77.0

Variable Description:

c temperature in Celsius double

f temperature in Fahrenheit double

7 Calculate Factorial of a Number

Algorithm:

1. Input integer n

2. Initialize fact = 1

3. Multiply fact by every number from 1 to n

4. Display factorial

Java Program:

import java.util.Scanner;
public class Factorial {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print(”Enter a number: ”);
int n = sc.nextInt();
int fact = 1;
for(int i=1; i<=n; i++) {
fact *= i;
}
System.out.println(”Factorial = ” + fact);
}
}

10
Java ISC Class 12 Practical Programs Using Scanner

Sample Output:

Enter a number: 5
Factorial = 120

Variable Description:

n input integer int

fact factorial result int

i loop counter int

8 Check Leap Year

Algorithm:

1. Input year

2. If year divisible by 400, print leap year

3. Else if year divisible by 100, not leap year

4. Else if year divisible by 4, leap year

5. Else not leap year

Java Program:

import java.util.Scanner;
public class LeapYear {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print(”Enter year: ”);
int year = sc.nextInt();
if(year % 400 == 0) {
System.out.println(year + ” is a leap year.”);

11
Java ISC Class 12 Practical Programs Using Scanner

} else if(year % 100 == 0) {


System.out.println(year + ” is not a leap year.”);
} else if(year % 4 == 0) {
System.out.println(year + ” is a leap year.”);
} else {
System.out.println(year + ” is not a leap year.”);
}
}
}

Sample Output:

Enter year: 2024


2024 is a leap year.

Variable Description:

year input year to check int

12

You might also like