0% found this document useful (0 votes)
37 views

Section A: 21 October 2015 3:00 To 5:00 PM: Class Notes by DR B P Sharma - 8800600025

This document contains class notes on Java input/output operations, wrapper classes, and examples of programs that take user input and perform operations like converting cases, data types, and calculating employee salary. It discusses using BufferedReader to take string input, Scanner to take numeric input, and wrapper classes for primitive types. Examples include a program to convert a string to uppercase, convert a number between binary, octal, and hexadecimal representations, and check if a character is a letter, digit or symbol. It also includes a sample payroll program that calculates DA, HRA, PF, gross and net salary based on user input basic salary.

Uploaded by

Lavi Sharma
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views

Section A: 21 October 2015 3:00 To 5:00 PM: Class Notes by DR B P Sharma - 8800600025

This document contains class notes on Java input/output operations, wrapper classes, and examples of programs that take user input and perform operations like converting cases, data types, and calculating employee salary. It discusses using BufferedReader to take string input, Scanner to take numeric input, and wrapper classes for primitive types. Examples include a program to convert a string to uppercase, convert a number between binary, octal, and hexadecimal representations, and check if a character is a letter, digit or symbol. It also includes a sample payroll program that calculates DA, HRA, PF, gross and net salary based on user input basic salary.

Uploaded by

Lavi Sharma
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Class Notes by Dr B P Sharma | http://fb.com/bpsharma.in | http://bpsharma.

in | 8800600025

Section A: 21st October 2015 3:00 to 5:00 pm


System.in  InputStreamReader  BufferedReader
BufferedReader br=new BufferedReader(new
InputStreamReader(System.in));
String readLine() throws IOException
Example
WAP to input a name and convert into capital.
import java.io.*;
public class Caps
{
public static void main(String args[]) throws IOException
{
BufferedReader br=new BufferedReader(new
InputStreamReader(System.in));
System.out.print("Enter a string : ");
String str=br.readLine();

System.out.println(str.toUpperCase());

WhatsApp 8800360849 | 2nd Floor, SE-387A, Shastri Nagar Petrol Pump, Ghaziabad | @drbpsharma
Class Notes by Dr B P Sharma | http://fb.com/bpsharma.in | http://bpsharma.in | 8800600025

}
}

What are wrapper classes? [Interview Question]


Special classes corresponding to the data types to provide
advance functionality to support the data types are called as
wrapper classes.
Data type Wrapper Class
byte Byte
short Short
int Integer
long Long
float Float
double Double
char Character
boolean Boolean

All such classes are provided in java.lang package

Example
WAP to input a number and convert that number into binary,
octal and hexa decimal.

WhatsApp 8800360849 | 2nd Floor, SE-387A, Shastri Nagar Petrol Pump, Ghaziabad | @drbpsharma
Class Notes by Dr B P Sharma | http://fb.com/bpsharma.in | http://bpsharma.in | 8800600025

Data type  int


Wrapper Class  Integer
Number Input  Scanner class
import java.util.Scanner;
public class DataConversion
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.print("Enter a number : ");
int num=sc.nextInt();

System.out.println(Integer.toBinaryString(num));
System.out.println(Integer.toOctalString(num));
System.out.println(Integer.toHexString(num));
}
}
WAP to input a character and check it to be alphabet, digit and
special character.

WhatsApp 8800360849 | 2nd Floor, SE-387A, Shastri Nagar Petrol Pump, Ghaziabad | @drbpsharma
Class Notes by Dr B P Sharma | http://fb.com/bpsharma.in | http://bpsharma.in | 8800600025

Solution in C
#include<ctype.h>
main()
{
char ch;
printf("Enter a charater : ");
ch=getchar();

if(isdigit(ch))
printf("%c is a digit",ch);
else if(isalpha(ch))
printf("%c is an alphabet",ch);
else
printf("%c is special character",ch);

getch();
}

WhatsApp 8800360849 | 2nd Floor, SE-387A, Shastri Nagar Petrol Pump, Ghaziabad | @drbpsharma
Class Notes by Dr B P Sharma | http://fb.com/bpsharma.in | http://bpsharma.in | 8800600025

Solution in Java
- First read a character using read() method of System.in
o int read() throws IOException
import java.io.IOException;
public class CheckCharacter
{
public static void main(String args[]) throws IOException
{
System.out.print("Enter a character : ");
char ch=(char)System.in.read();

if(Character.isDigit(ch))
System.out.printf("%c is a digit",ch);
else if(Character.isLetter(ch))
System.out.printf("%c is an alphabet", ch);
else
System.out.printf("%c is special character",ch);
}
}

WhatsApp 8800360849 | 2nd Floor, SE-387A, Shastri Nagar Petrol Pump, Ghaziabad | @drbpsharma
Class Notes by Dr B P Sharma | http://fb.com/bpsharma.in | http://bpsharma.in | 8800600025

WAP to input name and basic salary of an employee.


Calculate DA as 78% of basic
Calculate HRA as 35% of basic
Calculate PF as 12% of basic
Calculate gross salary as basic+da+hra
Calculate net salary as gross-pf
Show the Salary Sheet
Name :
Basic : 23456.00
DA : 8988.00
HRA :
PF :
Gross :
Net :

WhatsApp 8800360849 | 2nd Floor, SE-387A, Shastri Nagar Petrol Pump, Ghaziabad | @drbpsharma
Class Notes by Dr B P Sharma | http://fb.com/bpsharma.in | http://bpsharma.in | 8800600025

WhatsApp 8800360849 | 2nd Floor, SE-387A, Shastri Nagar Petrol Pump, Ghaziabad | @drbpsharma

You might also like