0% found this document useful (0 votes)
246 views

Com 121

This document contains summaries of 6 Java programs: 1) A program that sums three integers and prints the result. 2) A program that produces the 3 times multiplication table from 1 to 10. 3) A program that calculates the area of a triangle given the base and height. 4) A statement that converts a string value to an integer. 5) A program that solves quadratic equations by taking in coefficients and calculating the roots. 6) Continued description of the quadratic equation program.

Uploaded by

marmetus
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
246 views

Com 121

This document contains summaries of 6 Java programs: 1) A program that sums three integers and prints the result. 2) A program that produces the 3 times multiplication table from 1 to 10. 3) A program that calculates the area of a triangle given the base and height. 4) A statement that converts a string value to an integer. 5) A program that solves quadratic equations by taking in coefficients and calculating the roots. 6) Continued description of the quadratic equation program.

Uploaded by

marmetus
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 8

COM 121

Onochie Emmanuel
Add three integers
// this program sums three integers and prints the result.
package javaapplication1;
import java.util.Scanner;
public class IO {
public static void main(String[] args) {
int num1;
int num2;
int num3;
int Sum;
Scanner input = new Scanner(System.in);
num1 = input.nextInt();
num2 = input.nextInt();
num3 = input.nextInt();
Sum = num1+num2+num3;
System.out.println(" The numbers are " + num1 + " ," + num2 + " , and" + num3);
System.out.println(" The Sum is " + Sum);
}
}

4/15/2014 2 Property of Projectcorp Nigeria
Three timestable
// this program produces the three times table
package javaapplication1;
import java.util.Scanner;
class MultiplicationTable
{
public static void main(String args[])
{
int c;
System.out.println("Multiplication table of 3 is :-");
for ( c = 1 ; c <= 10 ; c++ )
System.out.println("3 * "+c+" = "+(3*c));
}
}


4/15/2014 3 Property of Projectcorp Nigeria
Area of triangle
//This program calculates the area of a triangle
package javaapplication1;
import java.util.Scanner;
public class IO {
public static void main(String[] args) {
int h;
int b;
int h;
Scanner input = new Scanner(System.in);
h = input.nextInt();
b = input.nextInt();
a = 1/2 * b * h;
System.out.println(" The numbers are " + h + ", and" + b);
System.out.println(" The Area is " + a);
}
}

4/15/2014 4 Property of Projectcorp Nigeria
Convert a string to integer
//This java statement converts a string value to an
integer value to be stored in x

int x =Integer.parseInt("9")
4/15/2014 5 Property of Projectcorp Nigeria
Quadratic equation
The java program below solve quadratic equation
import java.util.Scanner;
public class Project4 {
public static void main(String[]args){
// Create a Scanner
Scanner input = new Scanner (System.in);
// Prompt the user to enter three double intergers.
System.out.print("Enter a:");
double a = input.nextDouble();

System.out.println("Enter b:");
double b = input.nextDouble ();

System.out.println("Enter c:");
double c = input.nextDouble();

4/15/2014 6 Property of Projectcorp Nigeria
Quadratic equation cntd.
double discriminat = Math.pow(b,2) - 4*a*c;
double x1 = (-b + Math.sqrt(discriminat))/(2*a);
double x2 = (-b - Math.sqrt(discriminat))/(2*a);
double i=Math.sqrt(-1);
double x3 = (-b + (Math.sqrt(discriminat))*i)/(2*a);
double x4 = (-b + (Math.sqrt(discriminat))*i)/(2*a);

if (discriminat > 0 ){
System.out.println("there are two solutions:" +x1+"and"+x2);
}
else if (discriminat == 0){
System.out.println("The solutions is:"+x1);
}
else if (discriminat < 0){
System.out.println("The solutions are"+x3+"and"+x4);
}
}

}

4/15/2014 7 Property of Projectcorp Nigeria




THE END
4/15/2014 Property of Projectcorp Nigeria 8

You might also like