Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Chapter 3 Exercises
- PG 190 Number 6
- public class Pg180_6
- {
- public static void main(String[] args)
- {
- int x= Calculate(4,-5);
- System.out.println(x);
- }
- public static int Calculate(int x, int y)
- {
- return(Math.abs(Math.max(x,y)));
- }
- }
- Pg 190 Number 8
- public class Pg190_8
- {
- public static void main(String[] args)
- {
- int a = 1;
- int b = 3;
- int c = 2;
- double xvertex=-(b/(2*a));
- double discr = discrim(a,b,c)/2*a;
- double x1 = xvertex+discr;
- double x2 = xvertex-discr;
- System.out.println(x1);
- System.out.println(x2);
- }
- public static double discrim(int a, int b, int c)
- {
- return(Math.sqrt(b*b-4*a*c));
- }
- }
- Pg 190 Number 10
- public class Pg190_10
- {
- public static void main(String[] args)
- {
- double radius = 2.0;
- double area = Calculate(radius);
- System.out.println("area =" + area );
- }
- public static double Calculate(double x)
- {
- return(Math.PI*(x*x));
- }
- }
- Pg 190 Number 12
- public class Pg190_12
- {
- public static void main(String[] args)
- {
- double a = 6.23;
- double b = 5;
- double notation = Calculate(a, b);
- System.out.println("Scientific Notation form of the number is " + notation);
- }
- public static double Calculate(double a, double b)
- {
- return(a*(Math.pow(10,b)));
- }
- }
- Pg 191 Number 14
- public class Pg191_14
- {
- public static void main(String[] args)
- {
- double radius = 3.0;
- double height = 4.5;
- double surfacearea = cylinderSurfaceArea(radius, height);
- System.out.println("The Surface Area of the Cylinder is " + surfacearea);
- }
- public static double cylinderSurfaceArea(double r, double h)
- {
- return((2*(Math.PI * (r*r))) + (2*r*h*Math.PI));
- }
- }
- Pg 191 Number 16
- public class Pg191_16
- {
- public static void main(String[] args)
- {
- double sideA = 8;
- double sideB = 5.2;
- double sideC = 7.1;
- double area = triangleArea(sideA, sideB, sideC);
- System.out.println("The area of the triangle is " + area);
- }
- public static double triangleArea(double a, double b, double c)
- {
- double s = (a + b + c)/2;
- return(Math.sqrt(s*(s - a)*(s - b)*(s - c)));
- }
- }
- Pg 191 Number 18
- import java.util.*;
- public class Pg191_18
- {
- public static void main(String[] args)
- {
- String str1 = "hey now";
- for(int i; i <= str1.length(); i++)
- {
- System.out.println(str1.charAt(i+1));
- }
- }
- }
- Pg 191 Number 20
- import java.util.*;
- public class Pg191_20
- {
- public static void main(String[] args)
- {
- Scanner console = new Scanner(System.in);
- System.out.println("On what day of the month were you born?");
- int day = console.nextInt();
- System.out.println("What is the name of the month in which you were born?");
- String month = console.next();
- System.out.println("During what year were you born?");
- int year = console.nextInt();
- System.out.println("You were born on "+month +" " + day +"," + year +" You're mighty old!");
- }
- }
- Pg 191 Number 22
- import java.util.*;
- public class Pg192_22
- {
- public static void main(String[] args)
- {
- Scanner console = new Scanner(System.in);
- System.out.println("What is your GPA?");
- double GPA = console.nextDouble();
- System.out.println("What is your SAT score?");
- double SAT = console.nextInt();
- if( GPA >= 1.9)
- {
- System.out.println("You are accepted!");
- }
- else
- {
- System.out.println("You are rejected!");
- }
- if( SAT >= 900)
- {
- System.out.println("You are accepted!");
- }
- else
- {
- System.out.println("You are rejected!");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement