PROJ
PROJ
Write a program to perform following operations on two numbers input by the user:
1) Addition 2) subtraction 3) multiplication 4) division
PROGRAM-1
Write a program to perform following operations on two numbers input by the user:
1) Addition 2) subtraction 3) multiplication 4) division
import java.util.Scanner;
public class prg1 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Simple Calculator");
System.out.print("Enter the first number: ");
int num1 = scanner.nextInt();
System.out.print("Enter the second number: ");
int num2 = scanner.nextInt();
int sum = num1 + num2;
System.out.println("Addition: " + sum);
int difference = num1 - num2;
System.out.println("Subtraction: " + difference);
int product = num1 * num2;
System.out.println("Multiplication: " + product);
if (num2 != 0) {
double quotient = (double) num1 / num2;
System.out.println("Division: " + quotient);
} else {
System.out.println("Division by zero is not allowed.");
}
}
}
PROGRAM-2
Write a Java program to print result of the following operations.
1. -15 +58 * 45
2. (35+8) % 6
3. 24 + -5*3 / 7
4. 15 + 18 / 3 * 2 - 9 % 3
PROGRAM-2
Write a Java program to print result of the following operations.
1. -15 +58 * 45
2. (35+8) % 6
3. 24 + -5*3 / 7
4. 15 + 18 / 3 * 2 - 9 % 3
import java.util.Scanner;
import java.util.Scanner;
import java.util.Scanner;
import java.io.*;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;
class prg7 {
public static void main(String[] args) {
Date localTime = new Date();
DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
System.out.println("Local Time: " + localTime);
System.out.println("Time in GMT: " + dateFormat.format(localTime));
}
}
PROGRAM-8
import java.util.Scanner;
public class prg8
{
public static void main(String[] args)
{
int a,b,c,temp,greater;
Scanner n =new Scanner(System.in);
System.out.println("Enter the first number:");
a=n.nextInt();
System.out.println("Enter the Second number:");
b=n.nextInt();
System.out.println("Enter the Third number:");
c=n.nextInt();
temp=a>b?a:b;
greater=c>temp?c:temp;
System.out.println("The Greatest number is:"+greater);
}
}
PROGRAM-9
import java.util.Scanner;
System.out.print(" Please Enter Month Number from 1 to 12 (1 = Jan, and 12 = Dec) : ");
month = sc.nextInt();
import java.util.Scanner;
public class prg10
{
public static void main(String[] args)
{
int sum=0,n,j;
Scanner sc=new Scanner(System.in);
System.out.print("Enter the number of elements you want to store: ");
n=sc.nextInt();
int[] array = new int[n];
System.out.println("Enter the elements of the array: ");
for(int i=0; i<n; i++)
{
array[i]=sc.nextInt();
}
for(j=0;j<array.length;j++)
{
sum=sum+array[j];
}
System.out.println("Sum of array element:"+sum);
}
}
PROGRAM-11
Calculate the average value of array elements through Java Program.
PROGRAM-11
Calculate the average value of array elements through Java Program.
import java.util.Scanner;
public class prg11
{
public static void main(String[] args)
{
float sum=0,avg;
int n,j;
Scanner sc=new Scanner(System.in);
System.out.print("Enter the number of elements you want to store: ");
n=sc.nextInt();
int[] array = new int[n];
System.out.println("Enter the elements of the array: ");
for(int i=0; i<n; i++)
{
array[i]=sc.nextInt();
}
for(j=0;j<array.length;j++)
{
sum=sum+array[j];
}
System.out.println("Sum of array element:"+sum);
avg=(sum)/n;
System.out.println("Average of array element:"+avg);
}
}
PROGRAM-12
Find the index of an array element by writing a program in Java.
PROGRAM-12
Find the index of an array element by writing a program in Java.
import java.util.Arrays;
public class prg14 {
int removeIndex = 1;
class prg14a{
public static void main(String args[]){
String s1="jack";
String s2="JACK";
System.out.println(s1.equals(s2)); //false
System.out.println(s1.equalsIgnoreCase(s2)); //true
}
}
6) Print a substring
5) Concatenate two strings
public class prg14e{
public static void main(String[] args){
String str1 = "Java";
String str2 = "Programming";
String str3 = str1.concat(str2);
System.out.println(str3);
}
}
6) Print a substring
import java.io.*;
class Smallest {
public static void main(String[] args) {
int a = 3, b = 5, c = 7;
if (a <= b && a <= c)
System.out.println(a + " is the smallest");
else if (b <= a && b <= c)
System.out.println(b + " is the smallest");
else
System.out.println(c + " is the smallest");
}
}
PROGRAM-16
import java.util.Scanner;
int a, b, c;
a = n.nextInt();
b = n.nextInt();
c = n.nextInt();
sum = a + b + c;
average = (sum) / 3;
}
PROGRAM-17
import java.util.Scanner;
int count = 0;
count++;
return count;
}
PROGRAM-18
To represent the concept of all types of inheritance supported by Java, design a program.
PROGRAM-18
To represent the concept of all types of inheritance supported by Java, design a program.
class Doctor {
void Doctor_Details() {
System.out.println("Doctor Details...");
}
}