-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddChar.java
More file actions
44 lines (41 loc) · 1.09 KB
/
AddChar.java
File metadata and controls
44 lines (41 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//Program to Add two CHARATCTERS using Class
import java.util.*;
public class AddChar
{
public static void main(String[] args)
{
System.out.print("Program to add two CHARACTERS using Class ---");
Char ch=new Char();
ch.get_char();
ch.simple_add();
ch.arithematic_add();
}
}
class Char
{
char ch1,ch2;
public void get_char()
{
Scanner sc=new Scanner(System.in);
System.out.print("\nEnter the first character :- ");
ch1=sc.next().charAt(0);
System.out.print("\nEnter the second chracter :- ");
ch2=sc.next().charAt(0);
}
public void simple_add()
{
System.out.print("\nSimple addition of two numbers is :- "+ch1 +ch2);
}
public void arithematic_add()
{
Scanner read=new Scanner(System.in);
System.out.print("\nEnter the first number to add :- ");
int n1=read.nextInt();
int temp1=ch1+n1;
System.out.print("\nAdding 2 to ch1 is :- "+(char)temp1);
System.out.print("\nEnter the second number to add :- ");
int n2=read.nextInt();
int temp2=ch1+n2;
System.out.print("\nAdding 2 to ch2 is :- "+(char)temp2);
}
}