This commit is contained in:
HeshamTB 2019-01-27 21:45:40 +03:00
parent 6e8d42ffbd
commit 4abc213b6e
3 changed files with 96 additions and 0 deletions

31
src/lab/two/One.java Normal file
View File

@ -0,0 +1,31 @@
package lab.two;
import java.util.Scanner;
public class One {
public static void main(String[] args) {
Scanner input = new Scanner( System.in );
int num1;
int num2;
int num3;
int sum;
int product;
int average;
System.out.println( "Enter first integer:" );
num1 = input.nextInt();
System.out.println( "Enter second integer:" );
num2 = input.nextInt();
System.out.println( "Enter third integer: ");
num3 = input.nextInt();
input.close();
sum = num1 + num2 + num3;
product = num1 * num2 * num3;
average = ( num1 + num2 + num3 ) / 3;
System.out.printf( "The sum is %d\nThe product is %d\nThe average is %d\n", sum,
product, average );
}
}

31
src/lab/two/Three.java Normal file
View File

@ -0,0 +1,31 @@
package lab.two;
import java.util.Scanner;
public class Three {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.print("Enter integer: ");
int number = 0;
try {
number = in.nextInt();
}
catch (Exception e) {
System.out.println("incorrect input.");
System.exit(1);
}
if (isEven(number)) {
System.out.println("Number is Even");
}
else System.out.println("Number is Odd");
}
public static boolean isEven(int number) {
if (number % 2 == 0) {
return true;
}
else return false;
}
}

34
src/lab/two/Two.java Normal file
View File

@ -0,0 +1,34 @@
package lab.two;
import java.util.Scanner;
public class Two {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int r = 0;
double circumference, area, diameter;
System.out.print("Enter the radius: ");
try
{
r = in.nextInt();
}
catch (Exception e)
{
System.out.println("incorrect input.");
System.exit(1);
}
diameter = 2*r;
circumference = 2*Math.PI*r;
area = Math.PI*r*r;
String format = "Diameter is %.0f%n"
+ "Area is %f%n"
+ "Circimfrance is %f%n";
System.out.printf(format, diameter, area, circumference);
}
}