Download as rtf, pdf, or txt
Download as rtf, pdf, or txt
You are on page 1of 6

Okegbe Akpofure KElvin-FAith

BU/17C/IT/2684

package ng.edu.baze.com.com3131_2021Q2;

import java.util.Scanner;

public class Main {

public static void main(String[] args) {

//1. Write a program to find the roots of quadratic equation using the formula: Equation: ax^2+bx+c
//Discriminant: b^2-4ac
//Root1 = (-b+√d/2a
//Root2 = (-b-√d/2a
Scanner sc = new Scanner(System.in);
System.out.println("Enter the value of a ::");
double a = sc.nextDouble();

System.out.println("Enter the value of b ::");


double b = sc.nextDouble();

System.out.println("Enter the value of c ::");


double c = sc.nextDouble();

double discriminant = b * b - (4 * a * c);


System.out.println("The discriminant of the equation is " + discriminant);

double sqrt = Math.sqrt(discriminant);


double Root1 = (-b + sqrt)/(2*a);
System.out.println("The first or negative root is " + Root1);

double Root2 = (-b - sqrt)/(2*a);


System.out.println("The second or positive root is " + Root2);

//2.(a) Write a program that calculates the remainder of two numbers.


System.out.println("Enter the value of the dividend ::");
int dividend = sc.nextInt();

System.out.println("Enter the value of the divisor ::");


int divisor = sc.nextInt();
int remainder = dividend % divisor;
System.out.println("The Remainder is = " + remainder);

2b)package ng.edu.baze.com.com3131_2021Q2;

import java.util.Scanner;

public class Main {

public static void main(String[] args) {

//2.(b) Write a program that calculates the average of five numbers.


Scanner sc = new Scanner(System.in);
System.out.println("Enter the first number ::");
int number1 = sc.nextInt();

System.out.println("Enter the second number ::");


int number2 = sc.nextInt();

System.out.println("Enter the third number ::");


int number3 = sc.nextInt();

System.out.println("Enter the fourth number ::");


int number4 = sc.nextInt();

System.out.println("Enter the fifth number ::");


int number5 = sc.nextInt();

int average = (number1 + number2 + number3 + number4 + number5)/5;

System.out.println("The average of the 5 numbers is ::" + average);

}
}

3)
}
(i)I am tabbed
(ii) new

line

(iii)backslash \

(iv)single quote '

(v)backspace

4)a

package ng.edu.baze.com.com3131_2021Q2;

import java.util.Scanner;

public class Main {

public static void main(String[] args) {

//4(a) Write a program that converts minutes to seconds.

Scanner input = new Scanner (System.in);


int seconds;
int minutes;
System.out.print("Enter the number of minutes : ");
minutes = input.nextInt();
seconds = minutes * 60;
System.out.print("Number of seconds is: "+ seconds);

}
}\

4)b

package ng.edu.baze.com.com3131_2021Q2;

import java.util.Scanner;

public class Main {

public static void main(String[] args) {

//4. (b) Write a program that converts hours to seconds


Scanner input = new Scanner (System.in);
int seconds;
int hours;
System.out.print("Enter the number of hours : ");
hours = input.nextInt();
seconds = hours * 3600;
System.out.print("Number of seconds is: "+ seconds);

}
}
5)package ng.edu.baze.com.com3131_2021Q2;

import java.util.Scanner;

public class Main {

public static void main(String[] args) {

//Declare three variables of type String (str1, str2, str3), one should be an empty string and
// concatenate the three strings.
String str1;
String str2;
String str3;

str1 = "Okegbe ";


str2 = "Akpofure ";
str3 = "";
System.out.println("The concatenation of the 3 strings are:" + str1 + str2 + str3 );

6a) }package ng.edu.baze.com.com3131_2021Q2;

import java.util.Scanner;

public class Main {

public static void main(String[] args) {

//6.(a) What does the following program do. Run and write comments about the program.
//x = 1;
//y = ++x
int x = 1;
int y = ++x;
System.out.println(y);
//The following program incrememts x by 1
}
}
6 6b) package ng.edu.baze.com.com3131_2021Q2;

import java.util.Scanner;

public class Main {

public static void main(String[] args) {

//6.(a) What does the following program do. Run and write comments about the program.
//x = 1;
//y = x++
int x = 1;
int y = x++;
System.out.println(y);
//The following program prints 1

}
}

You might also like