HW3.1

 1 import java.util.Scanner;
 2
 3 public class Solution
 4 {
 5     public static void main(String[] args)
 6     {
 7         Scanner input = new Scanner(System.in);
 8
 9         System.out.print("Enter a, b, c: ");
10         double a = input.nextDouble();
11         double b = input.nextDouble();
12         double c = input.nextDouble();
13
14         input.close();
15
16         double delta = b * b - 4 * a * c;
17
18         if(delta > 0)
19         {
20             double root1 = (-b + Math.pow(delta, 0.5)) / (2 * a);
21             double root2 = (-b - Math.pow(delta, 0.5)) / (2 * a);
22             System.out.println("The roots are " + root1 + " and " + root2);
23         }
24         else if(delta == 0)
25         {
26             double root = -b / (2 * a);
27             System.out.println("The root is " + root);
28         }
29         else
30             System.out.println("The equation has no real roots.");
31     }
32 }
时间: 2024-10-04 01:49:07

HW3.1的相关文章

Software Testing -- HW3

Using the following method printPrimes() for questions a-f below Prime.java package net.chenyuhong.junitTest; import java.awt.datatransfer.StringSelection; import java.util.Scanner; /** * @Title: Prime.java * @Package net.chenyuhong.junitTest * @Desc

机器学习及其matlab实现—从基础到实践——HW3

Contents I. 清空环境变量 II. 训练集/测试集产生 III. 数据归一化 IV. BP神经网络创建.训练及仿真测试 V. 性能评价 VI. 画图 I. 清空环境变量 clear all clc II. 训练集/测试集产生 1. 导入数据 load concrete_data.mat 2. 随机产生训练集和测试集 temp = randperm(size(attributes,2)); % 训练集--80个样本 P_train = attributes(:,temp(1:80));

HW3书上习题

测试: 书上习题: a) b)比如循环测试错误:while(numPrimes < 3) c)n=1 d) 节点覆盖: {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14} 边覆盖: {(0,1), (1,2), (1,10), (2,3), (3,4), (3,7), (4,5), (4,6), (6,3), (5,7), (7,8), (7,9), (8,9), (9,1), (10,11), (11,12), (11,14), (12,13), (13,11)} 主路径

HW3.4

1 import java.util.Scanner; 2 3 public class Solution 4 { 5 public static void main(String[] args) 6 { 7 Scanner input = new Scanner(System.in); 8 9 int number1 = (int)(Math.random() * 100); 10 int number2 = (int)(Math.random() * 100); 11 12 System.o

HW3.5

1 import java.util.Scanner; 2 3 public class Solution 4 { 5 public static void main(String[] args) 6 { 7 int n1 = (int)(Math.random() * 10); 8 int n2 = (int)(Math.random() * 10); 9 int n3 = (int)(Math.random() * 10); 10 11 Scanner input = new Scanner

未完成的hw3

新建脚本文件,最後得到的答案是錯的,運行了一個loop就結束了== a=1:14; b=1:3; c=1:148; %代表矩陣維度 T=x(:,1:3);%目標數組 fai=ones(148,14);%輸入 fai(:,2:14)=x(:,4:16); w=zeros(14,3);%w數組 e1=0.1; e2=0.2;%前後兩個error值,方便比較error的變化 while(abs(e1-e2)>0.000001) Ak=fai*w;%計算Ak Ak=exp(Ak); Ak(:,4)=su

hw3

smoosh相对来说比较复杂一些,尤其是最后一个数字向后比较的时候,很容易就丢了一个数,作业上说是用了14行码,我正好也是14行.后面squish开始忘记了比较要用equals不能用==,也是卡了半天,不好好审题.后面加了一些testcode检验这三个method. import java.lang.reflect.Array; /* SList.java */ /** * The SList class is a singly-linked implementation of the link

Software Testing (软件测试作业三) HW3 prin

The source code: 源代码: /******************************************************* * Finds and prints n prime integers * Jeff Offutt, Spring 2003 ******************************************************/ public static void printPrimes (int n) { int curPrim

软件测试-hw3

int curPrime; // Value currently considered for primeness 8. int numPrimes; // Number of primes found so far. 9. boolean isPrime; // Is curPrime prime? 10. int [] primes = new int [MAXPRIMES]; // The list of prime numbers. 11. 12. // Initialize 2 int

HW3.26

1 import java.util.Scanner; 2 3 public class Solution 4 { 5 public static void main(String[] args) 6 { 7 Scanner input = new Scanner(System.in); 8 9 System.out.print("Enter an integer: "); 10 int number = input.nextInt(); 11 12 input.close(); 13