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

Java Program Fort Practice

The document contains 3 Java programs: 1) A program that adds a long and short number and prints the sum. 2) A program that finds and prints the ASCII values of characters 'a' and 'A'. 3) A basic calculator program that takes user input for two numbers and an operator and prints the result.

Uploaded by

shameer khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

Java Program Fort Practice

The document contains 3 Java programs: 1) A program that adds a long and short number and prints the sum. 2) A program that finds and prints the ASCII values of characters 'a' and 'A'. 3) A basic calculator program that takes user input for two numbers and an operator and prints the result.

Uploaded by

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

Shahmeer khan

ID:32571

Object oriented Programing

1.Write a program that add long ans short datatype numbers.

Code:

package com.learn.java;

public class shahmeer {

public static void main(String[] args) {

long a=223634703;

short b=22367;

long sum;

sum=a+b;

System.out.println("sum of numbers ="+sum);

Output:

2. Java Program to Find ASCII Value of a character

CODE:

public class Main

{public static void main(String[] args) {


int ch1,ch2;

ch1='a';

ch2='A';

System.out.println("ch1 and ch2 contains");

System.out.println(ch1 +" and "+ch2);

OUTPUT:

3. simple calculator using java program.

CODE:

package com.learn.java;

import java.util.Scanner;

public class calculator {

public static void main(String[] args) {

double num1, num2;

Scanner scanner = new Scanner(System.in);

System.out.print("Enter first number:");

num1 = scanner.nextDouble();

System.out.print("Enter second number:");

num2 = scanner.nextDouble();

System.out.print("Enter an operator (+, -, *, /): ");


char operator = scanner.next().charAt(0);

scanner.close();

double output;

switch(operator)

case '+':

output = num1 + num2;

break;

case '-':

output = num1 - num2;

break;

case '*':

output = num1 * num2;

break;

case '/':

output = num1 / num2;

break;

default:

System.out.printf("You have entered wrong operator");

return;

System.out.println(num1+" "+operator+" "+num2+": "+output);

OUTPUT:
Display the string using java program.

You might also like