if (b> d) {
for(inti = d;i >= 1; i--) {
if (b % i == 0 && d % i == 0) {
return i;
}
}
} else {
for(intj = b; j >= 1; j--) {
if (b % j == 0 && d % j == 0) {
return j;
}
}
}
returngcd;
}
}
//OUT PUTS
// run:
//Please enterthe firstinteger:
//6
//Please enterthe secondinteger:
//4
//The GCD of 6 and4 is2.
//BUILD SUCCESSFUL (total time:9 seconds)
importjava.util.Scanner;
publicclassODDEVEN {
}
classOddOrEven{
publicstaticvoidmain(Stringargs[]) {
intx;
System.out.println("Enteranintegertocheckif itis oddor even");
Scannerin= newScanner(System.in);
x = in.nextInt();
if (x % 2 == 0) {
System.out.println("Youenteredanevennumber.");
} else {
System.out.println("Youenteredanoddnumber.");
}
}
}
//OUTPUT
// run:
//Enteran integertocheckif it isodd or even
//3
//Youenteredanoddnumber.
//BUILD SUCCESSFUL (total time:8 seconds
importjava.util.Scanner;
classTrignometricFunctionsDemo{
publicstaticvoidmain(String[] args) {
//Create a Scannerobjectwhichwill read
//valuesfromthe console whichuserenters
Scannerscanner= newScanner(System.in);
//Gettinginputfromuserfrom the console
System.out.println("Entervalueof angle indegrees");
//CallingnextDouble methodof scannerfor
//takinga double value fromuserandstoring
//it indegreesvariable
double degrees=scanner.nextDouble();
System.out.println("Letscalculatethe sine,cosineandtanof angle ...");
//In orderto calculate sine ,cosine andtan of angle we
//use the Math classthree static methodsbyname as :
//1. Math.sin(a) -- Sine of a
//2. Math.cos(a) -- Cosine of a
//3. Math.tan(a) -- Tangentof a
double sineOfAngle =Math.sin(degrees);
double cosOfAngle=Math.cos(degrees);
double tanOfAngle=Math.tan(degrees);
System.out.println();
System.out.println("The Sine of "+ degrees+" degreesis: "
+ sineOfAngle);
System.out.println("The Cosine of "+ degrees+ " degreesis:"
+ cosOfAngle);
System.out.println("The Tangentof "+ degrees+ " degreesis:"
+ tanOfAngle);
System.out.println();
System.out.println("Lets calculatethe sec,cosecandcot of angle ...");
//In orderto calculate sec,cosecand cot of angle we
//justinverse the value of sin,cos and tan calculatedabove :
//4. Secof a -- 1 / Sine of a
//5. Cosecof a -- 1/ Cosine of a
//6. Cotof a -- 1 / Tangentof a
double secOfAngle =1 / Math.sin(degrees);
double cosecOfAngle =1 / Math.cos(degrees);
double cotOfAngle =1 / Math.tan(degrees);
importjava.util.Scanner;
classdecimal {
}
classDecimalBinaryProgram{
publicstaticvoidmain(String[] args) {
Scannerin= newScanner(System.in);
while (true){
System.out.println("Enterintegerindecimal form(or#to quit):");
Strings1 = in.nextLine();
if ("#".equalsIgnoreCase(s1.trim())) {
break;
}
System.out.println(decimalToBinary(s1));
System.out.println("Enterintegerinbinaryform (or# to quit):");
Strings2 = in.nextLine();
if ("#".equalsIgnoreCase(s2.trim())) {
break;
}
System.out.println(binaryToDecimal(s2));
}
}
private staticStringdecimalToBinary(Strings) {
intn = Integer.parseInt(s,10);
StringBuildersb= newStringBuilder();
if (n== 0) {
return"0";
}
intd = 0;
while (n>0) {
d = n % 2;
n /= 2;
sb.append(d);
}
sb= sb.reverse();
returnsb.toString();
}
private staticStringbinaryToDecimal(Strings) {
intdegree =1;
intn = 0;
for(intk = s.length() - 1; k >= 0; k--) {
n += degree *(s.charAt(k) - '0');
degree *= 2;
}
returnn + "";
}
}
//OUTPUT
//run:
//Enterintegerindecimal form(or# to quit):
//2
//10
//Enterintegerinbinaryform (or# to quit):
//3
//3
//Enterintegerindecimal form(or# to quit):
//3
//11
//Enterintegerinbinaryform (or# to quit):
//4
//4
//Enterintegerindecimal form(or# to quit):
//4
//100
//Enterintegerinbinaryform (or# to quit):
//5
//5
//Enterintegerindecimal form(or# to quit):
//5
//101
importjava.io.*;
publicclassbetriangle {
}
// CSC108 Chapter4, Question19
// Name: Iam Me StudentID:555555555
// Tutor: AndriaHunter Prof:KenJackson
//
// ProgramDescription:Thisprogramusesthe Triangle class
// to create a triangle object. Itthenusesthe is_right,
// is_scalene,is_isosceles,andis_equilateral methods
// to testwhat type of triangle itis.
// The Triangle classcontainsthree variablestostore the length
// of each side of the triange,andmethodsthatcan be usedtodetermine
// determineif atriange isright,scalene,isoscelese,andequilateral.
classTriangle {
// Storesthe lengthof eachside of the Triangle object.
private intside1,side2,side3;
// Constructorto initialize the sidesof the triangle.
publicTriangle(ints1,ints2, ints3) {
//(type 'y'for yesor 'n' for no)
/*
* Sum five numbers and print the result
*/
public class FiveNumberSum { // Save as "FiveNumberSum.java"
public static void main(String[] args) {
int number1 = 11; // Declare 5 int variables to hold 5 integers
int number2 = 22;
int number3 = 33;
int number4 = 44;
int number5 = 55;
int sum; // Declare an int variable called sum to hold the sum
sum = number1 + number2 + number3 + number4 + number5;
System.out.print("The sum is "); // Print a descriptive string
System.out.println(sum); // Print the value stored in sum
}
}
publicclassARTIMATIC{
}
classArithmeticTest{ // Save as "ArithmeticTest.java"
publicstaticvoidmain(String[] args) {
intnumber1= 98; // Declare anint variable number1andinitializeitto98
intnumber2= 5; //Declare an intvariable number2andinitialize itto5
intsum,difference,product,quotient,remainder; //Declare five intvariablestoholdresults
//PerformarithmeticOperations
sum= number1+ number2;
difference =number1- number2;
product= number1* number2;
quotient=number1/ number2;
remainder=number1% number2;
//Printresults
System.out.print("The sum,difference,product,quotientandremainderof "); //Printdescription
System.out.print(number1); //Printthe value of the variable
System.out.print("and");
System.out.print(number2);
System.out.print("are ");
System.out.print(sum);
System.out.print(",");
System.out.print(difference);
System.out.print(",");
System.out.print(product);
System.out.print(",");
System.out.print(quotient);
System.out.print(",and");
System.out.println(remainder);
++number1; // Incrementthe value storedinthe variable "number1"by1
//Same as "number1= number1+ 1"
--number2; //Decrementthe value storedinthe variable"number2"by1
//Same as "number2= number2- 1"