Untitled
Untitled
Untitled
//20MT1043
//SHARMA
import java.util.Scanner;
public class main {
public static void main(String[] args) {
double r1,r2;{
Scanner input = new Scanner (System.in);
System.out.println("Enter the value of a:");
double a = input.nextDouble();
System.out.println("Enter the value of b:");
double b = input.nextDouble();
System.out.println("Enter the value of c:");
double c = input.nextDouble();
double d = b*b-4.0*a*c;
if (d>0.0) {
r1 = (-b+Math.pow(d, 0.5))/(2.0*a);
r2 = (-b-Math.pow(d, 0.5))/(2.0*a);
System.out.println("The roots are "+r1+"and"+r2);
System.out.println("The roots are real and distinct");
}
else if (d== 0.0) {
r1=r2=b/(2.0*a);
System.out.println("The root is"+r1);
System.out.println("The root is"+r2);
System.out.println("The roots are real and equal");
}
else {
System.out.println("Roots are not real and no real solution");
double x = -b/(2*a);
double y = Math.sqrt (-d)/(2*a);
System.out.println("r1 = "+x+"+i"+y);
System.out.println("r2 = "+x+"+i"+y);
}
}
}
}
package SHARMA;
//20MT1043
//SHARMA
import java.util.*;
public class fibonacciexamle {
static int fibRecursive(int n)
{
if (n <= 1)
return n;
return fibRecursive(n-1) + fibRecursive(n-2);
}
for(int i=2;i<=count;++i)
{
n3=n1+n2;
n1=n2;
n2=n3;
}
return n3;
}
package SHARMA;
//20MT1043
//SHARMA
import java.util.Scanner;
public class primeno {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter the limit: ");
int limit = input.nextInt();
System.out.print("Prime numbers up to " + limit + " are: ");
for (int i = 2; i <= limit; i++) {
boolean isPrime = true;
for (int j = 2; j < i; j++) {
if (i % j == 0) {
isPrime = false;
break;
}
}
if (isPrime) {
System.out.print(i + " ");
}
}
}
}
package SHARMA;
//20MT1043
//SHARMA
import java.util.Scanner;
public class classmatrix {
public static void main(String args[])
{
int m, n, p, q, sum = 0, c, d, k;
Scanner in = new Scanner(System.in);
System.out.println("Enter the number of rows and columns of first matrix");
m = in.nextInt();
n = in.nextInt();
int first[][] = new int[m][n];
System.out.println("Enter elements of first matrix");
for (c = 0; c < m; c++)
for (d = 0; d < n; d++)
first[c][d] = in.nextInt();
System.out.println("Enter the number of rows and columns of second matrix");
p = in.nextInt();
q = in.nextInt();
if (n != p)
System.out.println("The matrices can't be multiplied with each other.");
else
{
int second[][] = new int[p][q];
int multiply[][] = new int[m][q];
System.out.println("Enter elements of second matrix");
for (c = 0; c < p; c++)
for (d = 0; d < q; d++)
second[c][d] = in.nextInt();
for (c = 0; c < m; c++)
{
for (d = 0; d < q; d++)
{
for (k = 0; k < p; k++)
{
sum = sum + first[c][k]*second[k][d];
}
multiply[c][d] = sum;
sum = 0;
}
}
System.out.println("Product of the matrices:");
for (c = 0; c < m; c++)
{
for (d = 0; d < q; d++)
System.out.print(multiply[c][d]+"\t");
System.out.print("\n");
}
}
}
package SHARMA;
//20MT1043
//SHARMA
import java.util.Scanner;
public class palind {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter a string: ");
String inputString = scanner.nextLine();
if (isPalindrome(inputString)) {
System.out.println(inputString + " is a palindrome.");
} else {
System.out.println(inputString + " is not a palindrome.");
}
}
public static boolean isPalindrome(String inputString) {
int length = inputString.length();
for (int i = 0; i < length / 2; i++) {
if (inputString.charAt(i) != inputString.charAt(length - i - 1)) {
return false;
}
}
return true;
}
}
package SHARMA;
//20MT1043
//SHARMA
import java.util.Scanner;
public class Exp_07 {
String usn,name,department;
void insertstudent(String num,String nm,String dept)
{
usn=num;
name=nm;
department=dept;
}
void displayStudent()
{
System.out.println("-------------------");
System.out.println("Hall Ticket number:"+usn);
System.out.println("Name:"+name);
System.out.println("Department:"+department);
System.out.println("--------------------");
}
public static void main(String[] args)
{
Exp_07 st[]=new Exp_07[100];
Scanner ip=new Scanner(System.in);
System.out.println("Enter the number of Student:");
int n=ip.nextInt();
for(int i=0;i<n;i++)
st[i]=new Exp_07();
for(int j=0;j<n;j++)
{
System.out.println("Enter the Hall Ticket Numder,Name,
Department:");
String usn=ip.next();
String name=ip.next();
String department=ip.next();
st[j].insertstudent(usn,name,department);
}
for(int m=0;m<n;m++)
{
System.out.println("Student Detail are\n"+m+1);
st[m].displayStudent();
}
}
}
package SHARMA;
//20MT1043
//SHARMA
import java.util.Arrays;
import java.util.Scanner;
public class classsort {
public static void main(String[] args)
{
Scanner sc = new Scanner ( System.in);
int n;
System.out.println("Enter the number of elements:");
n = sc.nextInt();
String names[]= new String[n];
System.out.println("Enter the string:");
Scanner sc1 = new Scanner (System.in);
for(int i=0;i<n;i++) {
names[i]=sc1.nextLine();}
{
for(int i=0;i<n;i++)
{
for(int j =i+1;j<n;j++) {
if(names[i].compareTo(names[j])>0){
String temp = names[i];
names[i] = names[j];
names[j]=temp;
}
}
}
System.out.println(Arrays.toString(names));
}
}
}
package SHARMA;
//20MT1043
//SHARMA
import java.io.*;
public class filecopy {
input.close();
output.close();
package SHARMA;
//20MT1043
//SHARMA
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
String line;
int lineNumber = 1;
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
package SHARMA;
//20MT1043
//SHARMA
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
String line;
while ((line = br.readLine()) != null) {
lineCount++;
String[] words = line.split("\\s+");
wordCount += words.length;
for (String word : words) {
charCount += word.length();
}
}
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
package SHARMA;
//20MT1043
//SHARMA
import java.awt.*;
import java.awt.event.*;
public class MouseEventExample extends Frame implements MouseListener {
public MouseEventExample() {
addMouseListener(this);
setTitle("MOUSE EVENTS ");
setSize(800, 600);
setVisible(true);
}
//20MT1043
//SHARMA
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.Label;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
public KeyEventExample() {
setTitle("Key Event ");
setSize(300, 200);
setLayout(new FlowLayout());
setVisible(true);
}
package SHARMA;
//20MT1043
//SHARMA
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import javax.swing.JFrame;
//20MT1043
//SHARMA
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public CalculatorPanel() {
setLayout(new BorderLayout());
result = 0;
lastOperator = "=";
start = true;
addButton(buttonPanel, "7");
addButton(buttonPanel, "8");
addButton(buttonPanel, "9");
addButton(buttonPanel, "/");
addButton(buttonPanel, "4");
addButton(buttonPanel, "5");
addButton(buttonPanel, "6");
addButton(buttonPanel, "*");
addButton(buttonPanel, "1");
addButton(buttonPanel, "2");
addButton(buttonPanel, "3");
addButton(buttonPanel, "-");
addButton(buttonPanel, "0");
addButton(buttonPanel, ".");
addButton(buttonPanel, "=");
addButton(buttonPanel, "+");
add(buttonPanel, BorderLayout.CENTER);
}
if (start) {
if (input.equals("-")) {
display.setText(input);
start = false;
}
else {
lastOperator = input;
}
}
else {
if (input.equals("+") || input.equals("-") || input.equals("*") || input.equals("/")) {
calculate(Double.parseDouble(display.getText()));
lastOperator = input;
start = true;
}
else if (input.equals("=")) {
calculate(Double.parseDouble(display.getText()));
lastOperator = "=";
start = true;
}
else {
display.setText(display.getText() + input);
}
}
}
package SHARMA;
//20MT1043
//SHARMA
import java.awt.*;
import javax.swing.*;
public class Display_15 extends JFrame
{
public Display_15()
{
setTitle("Centered Message");
setSize(400, 300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
setLocationRelativeTo(null);
}
public static void main(String[] args)
{
new Display_15();
}
}
package SHARMA;
//20MT1043
//SHARMA
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Calculator extends JFrame implements ActionListener {
private JTextField display;
private String operator = "";
private int result = 0;
private boolean start = true;
public Calculator() {
setTitle("Calculator");
setSize(250, 250);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
add(panel);
setVisible(true);
}
public void actionPerformed(ActionEvent event) {
String command = event.getActionCommand();