第三章编程练习题3.1

package exercise3;

import java.util.Scanner;

public class Main1 {

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        double a = input.nextDouble();
        double b = input.nextDouble();
        double c = input.nextDouble();
        double panbieshi = b*b-4*a*c;
        if(panbieshi < 0)
        {
            System.out.println("没有值");
        }
        else if(panbieshi == 0)
        {
            double r1 = -b/(2*a);
            System.out.println(r1);
        }else{
             double r1 = (-b + Math.pow(panbieshi, 0.5)) / (2 * a);
               double r2 = (-b - Math.pow(panbieshi, 0.5)) / (2 * a);
               System.out.println("The roots are " + r1 + " and " + r2);
        }
    }

}
时间: 2024-08-04 15:23:18

第三章编程练习题3.1的相关文章

C Primer Plus (第五版) 第三章 编程练习

第三章    数据和C 编程练习: 通过实验的方法(即编写带有此类问题的程序)观察系统如何处理整数上溢.浮点数上溢和浮点数下溢的的情况. #include <stdio.h> int main(void) { /* 16位短整形 */ short int a = 32767; printf("a + 1 = %d\n", (short)(a + 1)); /* 32位整形 */ int b = 2147483647; printf("b + 1 = %d\n&qu

第三章课后练习题

1.画出流程图编程实现,如果用户名等于字符 ' 青 ',且密码等于数字 123,则输出" 欢迎你,青 ":否则输出 " 对不起,你不是青 ". 2.画出流程图并编程实现,如果年龄满 7 岁,或者年龄满 5 岁并且性别是"男",就可以搬动桌子.          3.从键盘上输入一个整数,分别赋给整形变量a.b.c,然后将输入的整数从小到大的顺序放在变量a.b.c中,并输出三个变量的值. 4.从键盘上输入一个整数,判断是否能被 3 或者 5 整除.

第三章 函数练习题

文件处理相关 1,编码问题 (1)请问python2与python3中的默认编码是什么? 1 2 python 2.x默认的字符编码是ASCII,默认的文件编码也是ASCII python 3.x默认的字符编码是unicode,默认的文件编码也是utf-8 (2)为什么会出现中文乱码,你能举例说明乱码的情况有哪几种? 1 2 3 4 5 6 7 8 9 无论以什么编码在内存里显示字符,存到硬盘上都是2进制,所以编码不对,程序就会出错了. (ascii编码(美国),GBK编码(中国),shift_

《Linux程序设计 第四版》之第三章的练习题

1.P103 一个目录扫描程序. #include<stdio.h> #include<dirent.h> #include<sys/stat.h> int isAdir(char* path); //判断路径是否是目录类型 void printdirs(char* path,int depth) //递归遍历打印文件与目录名 { DIR* dir=opendir(path); struct dirent* dirents; chdir(path); while(dir

第二章编程练习题2.8

import java.util.Scanner; public class Main7 { public static void main(String[] args) { Scanner input = new Scanner(System.in); int number = input.nextInt(); System.out.println((char)number); } }

第二章编程练习题2.6

import java.util.Scanner; public class Main5 { public static void main(String[] args) { Scanner input = new Scanner(System.in); int number = input.nextInt(); int last = number % 10; int shengxia = number/10; int second = shengxia%10; shengxia = sheng

第二章编程练习题2.9

public class Main8 { public static void main(String[] args) { java.util.Scanner input = new java.util.Scanner(System.in); int amount = input.nextInt(); int re = amount; int number1 = re/100; re = re%100; int number2 = re/25; re = re%25; int number3 =

第二章编程练习题2.7

import java.util.Scanner; /** * 给一个分钟的数字,算出来这些分钟代表多少年和多少天 * @author Administrator * */ public class Main6 { public static void main(String[] args) { Scanner input = new Scanner(System.in); long minuts = input.nextLong(); long numberOfDays = minuts/(2

c++primer 第三章编程练习答案

3.7.1 #include<iostream> int main() { using namespace std; const int unit = 12; int height,inch,foot; cout << "please input your height __ inch\b\b\b\b\b\b\b"; cin >> height; inch = height % unit; foot = height / unit; cin.get(