Будь умным!


У вас вопросы?
У нас ответы:) SamZan.net

модуль комплексного числа return flot Mth

Работа добавлена на сайт samzan.net: 2016-03-30

Поможем написать учебную работу

Если у вас возникли сложности с курсовой, контрольной, дипломной, рефератом, отчетом по практике, научно-исследовательской и любой другой работой - мы готовы помочь.

Предоплата всего

от 25%

Подписываем

договор

Выберите тип работы:

Скидка 25% при заказе до 22.5.2024

№1

package complexNumber;

public class ComplexNumber {

float real, img; // опис змінних комплексного числа

 

public ComplexNumber(){ // конструктор за замовчуванням

 this.img = 0;

 this.real = 0;

}

public ComplexNumber(float real, float img){ // конструктор з 2 параметрами

 this.real = real;

 this.img = img;

}

public String toString (){// метод для виведення комплексного числа  

 return new String(this.real+" + "+this.img+"i");

}

 

public float abs (ComplexNumber a){ //модуль комплексного числа

 return (float) Math.sqrt( a.real*a.real + a.img*a.img );

}

 

public ComplexNumber add(ComplexNumber a, ComplexNumber b){ // сума

 return new ComplexNumber(a.real+b.real,a.img+b.img);

}

public ComplexNumber sub(ComplexNumber a, ComplexNumber b){ // різниця

 return new ComplexNumber(a.real-b.real,a.img-b.img);

}

 

public ComplexNumber multipication(ComplexNumber a, ComplexNumber b){ // множення

 ComplexNumber c = new ComplexNumber();

 c.real = a.real*b.real - a.img*b.img ;

 c.img = b.real*a.img + a.real*b.img;

 return c;

}

 

public static void main(String args[]){

 

 

}

}

№2

package Vector;

public class Vector3D {

float x,y,z;

public Vector3D() {

 this.x = 0;

 this.y = 0;

 this.z = 0;

}

public Vector3D(float x, float y, float z){

 this.x = x;

 this.y = y;

 this.z = z;

}

public String toString (){

 return new String("x = "+this.x+" y =  "+this.y+" z = "+this.z );

}

public static Vector3D multK (Vector3D v , int k){

 return new Vector3D(v.x*k, v.y*k, v.z*k);

}

public static Vector3D add (Vector3D a, Vector3D b){

 return new Vector3D( a.x+b.x, a.y+b.y, a.z+b.z);

}

 

public static float sklMult(Vector3D a, Vector3D b){

 return (float) (a.x*b.x+a.y*b.y+a.z*b.z);

}

public static Vector3D vecMult (Vector3D a, Vector3D b){

 //v/a × b = {y1 z2 - z1 y2; z1 x2 - x1 z2; x1 y2 - y1 x2}

 float x = a.y*b.z - a.z*b.y;

 float y = a.z*b.x - a.x*b.z;

 float z = a.x*b.y - a.y*b.x;

 return new Vector3D(x,y,z);  

}

 

public static float abs(Vector3D a){

 return (float) Math.sqrt(a.x*a.x+a.y*a.y+a.z*a.z);

}

 

public static void main (String args[]){

 

}

 

}

№3

public class Matrix {

int matrinx[][] = new int [2][2];

 

public Matrix(){

 for (int i = 0; i < 2; i++)

  for (int j = 0; j < 2; j++) {

   matrinx[i][j] = 0;

  }

}

public Matrix (int matr[][]) {

 for (int i = 0; i < 2; i++)

  for (int j = 0; j < 2; j++) {

   matrinx[i][j] = matr[i][j];    

  }  

}

public static Matrix add(Matrix a, Matrix b){

 Matrix c = new Matrix();

 for (int i = 0; i < 2; i++)

  for (int j = 0; j < 2; j++) {

   c.matrinx[i][j] = a.matrinx[i][j]+b.matrinx[i][j];  

  }

 return c;

}

public static Matrix multK (Matrix a, int k){

 Matrix c = new Matrix();

 for (int i = 0; i < 2; i++)

  for (int j = 0; j < 2; j++) {

   c.matrinx[i][j] = a.matrinx[i][j]*k;    

  }

 return c;

}

public static Matrix mult (Matrix a, Matrix b){

  Matrix c = new Matrix();

  for (int i = 0; i < 2 ; i++)

  for (int j = 0; j < 2 ;  j++)

  for (int k = 0; k < 2 ; k++)

  c.matrinx[i][j] +=  a.matrinx[i][k] * b.matrinx[k][j];

  return c;

}

public static float determinant (Matrix a){

 return (a.matrinx[0][0]*a.matrinx[1][1]-a.matrinx[0][1]*a.matrinx[1][0]);

}

 

public static void main (String args[]){

}

}

№4

package triangle_4;

public class Triangle {

float a,b,c;

public Triangle(float a,float b, float c){

 if ((a > 0) && (b>0) && (c>0)){

  this.a = a;

  this.b = b;

  this.c = c;

 } else System.out.println("error create triangle !");

}

 

public static float perimetr(Triangle t){

 return (t.a+t.b+t.c);

}

 

public static float pl (Triangle t){

 return (float) Math.sqrt(perimetr(t)*(perimetr(t)-t.a)*(perimetr(t)-t.b)*(perimetr(t)-t.c));

}

public static void main (String args []){

}

}

№5

package square__5;

public class Square {

float a;

public Square(){

}

public Square(float a){

 if (a>0) this.a = a;

 else System.out.println("error create square");

}

public static float perymetr(Square t){

 return t.a*4;

}

public static float square (Square t){

 return t.a*t.a;

}

public static float diag (Square t){

 return (float) (Math.sqrt(2)*t.a);

}

public static void main (String args[]){

}

}

№6

public class Circle {

float x,y,r;

public Circle(){

 x = 0;

 y = 0;

 r = 0;

}

public Circle(float x, float y, float r){

 this.x = x;

 this.y = y;

 this.r = r;

}

 

public static float legthCircle(Circle c){

 return  (float) (2*Math.PI*c.r);

}

public static float square (Circle c){

 return  (float) (Math.PI*(c.r*c.r));

}

public static boolean inCircle (Circle c, float x,float y){

 if ( ((x-c.x)*(x-c.x)+(y-c.y)*(y-c.y)<=c.r*c.r)) return true;

 else return false;

}

public static void main(String[] args) {

}

}

№7

public class Cube {

float a;

public Cube() {

 a = 0;

}

public Cube(float a) {

 this.a = a;

}

public static float square (Cube c){

 return c.a*c.a*6;

}

public static float objem (Cube c){

 return c.a*c.a*c.a;

}

public static float diag (Cube c){

 return (float) Math.sqrt(3*(c.a*c.a));

}

public static void main(String[] args) {

}  }

№8

public class Pryzma {

float a, h;

public Pryzma (){

 a = 0;

 h = 0;

}

public Pryzma (float a, float h){

 this.a = a;

 this.h = h;

}

 

public static float pl(Pryzma p){  

 return (float) ((Math.sqrt(3)/4)*(p.a*p.a))*2 * (1/2*(3*p.a)*p.h);

}

public static float objem(Pryzma p){

 return (float)((Math.sqrt(3)/4)*(p.a*p.a)*p.h);

}

public static void main (String args[]){

 

}

}

№10

import java.io.*;

import java.util.Scanner;

public class FileIO {

private static Scanner scanner;

public static int countWordsStr (String str){

 int counter = 0;

 int i=0;

 for (int j = 0; j < str.length(); j++) {

           if ((str.charAt(j) == ' ') ) {

               if (j > i) {

                   counter++;

               }

               i = j + 1;}  }

       if (i < str.length()) {

           counter++;}

 return counter;}

public static int countWordsInFile(String fileName) throws IOException{

 File file = new File(fileName);

 System.out.println("File name : "+file.getName());

 BufferedReader br = new BufferedReader (new InputStreamReader(new FileInputStream(fileName), "UTF-8"));

 String line = null;

 int countWords=0;

       while ((line = br.readLine()) != null) {

           countWords+= countWordsStr(line);

       }        

       br.close();

       return countWords;

}

public static String getFileName() {

 boolean fOpen = false;

 String fileName = null;

 while (!fOpen){

  System.out.print("Write path to file : ");  

  scanner = new Scanner(System.in);

  fileName = new String(scanner.next());

  fOpen = new File(fileName).exists();

  if (!fOpen) {

   System.out.println("Error path to file");   }  }

 return fileName;  }

public static void main(String[] args) throws IOException, FileNotFoundException {  

 String fileName = getFileName();

       System.out.println("In file : "+new File(fileName).getName()+" "+countWordsInFile(fileName)+" words"); }      }

№11

import java.io.*;

import java.util.Scanner;

public class Lab6 {

public static void main(String[] args) {

 String fname = null;

 try {

  Scanner in = new Scanner(System.in);

  System.out.println("задайте файл введення ");

  fname = in.nextLine();

  FileInputStream fin = new FileInputStream(fname);

   //FileInputStream fin = new FileInputStream("D:/in.txt");

  BufferedReader myInput = new BufferedReader

  (new InputStreamReader(fin));

  System.out.println("задайте файл виведення ");

  fname = in.nextLine();

  DataOutputStream fout = new DataOutputStream( new BufferedOutputStream( new FileOutputStream(fname)));

  String c;

  while ((c = myInput.readLine()) != null) {

   if (c==null)

   continue;

   while (c.charAt(0) == ' '){

    c = c.substring(1);

   }

   while (c.charAt(c.length()-1) == ' '){

    c = c.substring(0,c.length()-1);

   }

   boolean next = true;

   while (next){

    next = false;

    for (int i=0;i<c.length()-1;i++)

     if (c.charAt(i)==' ' && c.charAt(i+1)==' '){

      c = c.substring(0, i)+c.substring(i+1);

      next = true;

      break;  }  }

   fout.writeBytes(c);

   String newLine = System.getProperty("line.separator");

   fout.writeBytes(newLine);

   System.out.println(c);  }

  fin.close();

  fout.close();

 } catch (FileNotFoundException ex) {

System.out.println("Файл "+fname+" не знайдено");

}  catch (Exception ex) { }

}

}

№12

import java.util.Scanner;

import java.util.Stack;

public class MyStack {

public static Scanner in;

public static void main(String[] args) {

 in = new Scanner(System.in);

 int n = in.nextInt();

 String str = String.valueOf(n);

 Stack<Object> stck = new Stack<>();

 

 for (int i=0; i<str.length();i++){

  stck.push(str.charAt(i));

 }

 String str1 = new String();

 while (!stck.empty()){

  str1+=stck.pop();   

 }

 try{

  n = Integer.parseInt(str1);

  System.out.println(n);

 }

 catch (NumberFormatException e){

  e.printStackTrace();

 }

 

}

 

}

№14

import java.util.Stack;

 

public class BracketsValidator {

 

   private Stack<Character> stack = new Stack<Character>();

   

   private boolean isOpeningBracket(char bracket) {

       return "({[".indexOf(bracket) != -1;

   }

   

   private boolean isClosingBracket(char bracket) {

       return ")}]".indexOf(bracket) != -1;

   }

 

   private boolean isPair(char opening, char closing) {

       return opening == '(' && closing == ')' || opening == '['

               && closing == ']' || opening == '{' && closing == '}';

   }

 

   public boolean validate(String input) {

       for (char c : input.toCharArray()) {

           if (isClosingBracket(c) && stack.isEmpty()) {

               return false;

           }

           if (isOpeningBracket(c)) {

               stack.push(c);

           }

           if (isClosingBracket(c)) {

               if (isPair(stack.peek(), c)) {

                   stack.pop();

               } else {

                   return false;

               }

           }

       }

       return stack.isEmpty();

   }

   public static void main(String[] args) {  

       String test = "a + (42 - b) * [wtf(){{}}] / {(2 + 2)}";

    //String test = "a + (42 - b) * [wtf({'}')] / {(2 + 2)}";

    BracketsValidator validator = new BracketsValidator();

       boolean correct = validator.validate(test);

       System.out.println( "скобки розставлено " + (correct ? "" : "не ") + "правильно");

       

   }

}

№15

public class Main_7 {

static Scanner scan = new Scanner(System.in);

public static void main(String[] args) {

LinkedList<Float> Polynom1 = new LinkedList<Float>();

LinkedList<Float> Polynom2 = new LinkedList<Float>();

LinkedList<Float> Result = new LinkedList<Float>();

int step=scan.nextInt();

for (int i = 0; i <= step; i++) {

 float rand1 = (float)(1 + Math.random() * 50);

 float rand2 = (float)(1 + Math.random() * 50);

 Polynom1.add(rand1);

 Polynom2.add(rand2);

}

System.out.print("Pol1=");

for(int i=0;i<step;i++)

 System.out.print(Polynom1.get(i)+"x^"+(step-i)+"+");

 System.out.print(Polynom1.get(step)+"\n");

 System.out.print("Pol2=");

for(int i=0;i<step;i++)

 System.out.print(Polynom2.get(i)+"x^"+(step-i)+"+");

 System.out.print(Polynom2.get(step)+"\n");

for(int i=0;i<=step;i++)

for(int j=0;j<=step;j++)

 Result.add(Polynom1.get(i)*Polynom2.get(j));

System.out.print("Result=");

for(int i=0;i<=step;i++)

 System.out.print(Result.get(i)+"x^"+(2*step-i)+"+");

 //System.out.print(Result.get(step)+"x^"+"+");

for(int i=step+1;i<2*(step+1);i++)

 System.out.print(Result.get(i)+"x^"+(2*(step+1)-i)+"+");

//System.out.print(Result.get(2*step)+"\n");

}

}




1. Дневники Письма
2. обумовлених процесів ускладнюється структура екології з~являються нові підрозділи а сама наука поширює с
3. РЕФЕРАТ дисертації на здобуття наукового ступеня кандидата філологічних наук
4. Двухуровневая банковская система
5. Харлей Дэвидсон и ковбой Мальборо 1991 Ренегат Микки Рурк и невероятно талантливый Дон Джонсон с б
6. углеводородная революция переход от угольной структуры к доминирующей роли углеводородного топлива уде
7. либо Ничто Воображаемое путешествие в начало времени к началу мироздания и к вопросу разумного замысла
8. Тема- Гидромеханизированная технология отработки угольного пласта в условиях проектируемой шахты
9. Анализ стихотворения Брюсова Грядущие гунны
10. Вариант 34 Часть 1 1 Отношения между особями одной стаи волков
11. Вариант 1. Определить полную себестоимость электроэнергии для ДЭС
12. О систематизации и методах исследования фразеологических материалов
13. Балада почата баладно з кін ця
14. Проблемы школьной неуспеваемости
15. реферат дисертації на здобуття наукового ступеня доктора технічних наук Харків 2001
16. Структура волокон поли-бис-трифторэтоксифосфазена
17. Поняття екологічного права
18. М Чорна ldquo
19. Задачи социального страхования
20. Отчет по технологической практике Лит.