Created
August 21, 2018 08:08
-
-
Save luchtech/ebb825b4ef115fee602261e3d0e67ae1 to your computer and use it in GitHub Desktop.
Laboratory Activity: Methods
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
public class numberManipulation { | |
static String DecToBinary(int num) { | |
if(num <= 0) return ""+num; | |
String hold = ""; | |
while(num!=0) { | |
hold = (num%2)+hold; | |
num/=2; | |
} | |
return hold; | |
} | |
static boolean isNegative(int num) { | |
if (num < 0) return true; | |
else return false; | |
} | |
static boolean isPositive(int num) { | |
if (num > 0) return true; | |
else return false; | |
} | |
static String Odd(int num) { | |
if (num%2 == 1) return "Yes"; | |
else return "No"; | |
} | |
static String Even(int num) { | |
if (num%2 == 0) return "Yes"; | |
else return "No"; | |
} | |
public static void main(String[] args) { | |
Scanner sc = new Scanner (System.in); | |
System.out.print("Enter number: "); | |
int num = sc.nextInt(); | |
sc.close(); | |
System.out.println("Binary Value\t: "+DecToBinary(num)); | |
System.out.println("isNegative\t: "+isNegative(num)); | |
System.out.println("isPositive\t: "+isPositive(num)); | |
System.out.println("Odd\t\t\t: "+Odd(num)); | |
System.out.println("Even\t\t: "+Even(num)); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
public class powerOfANumber { | |
public static double boomboomPow(double num,double exp){ | |
double total=1; | |
for(int i=1;i<=exp;i++){ | |
total*=num; | |
} | |
return total; | |
} | |
public static void main(String[] args) { | |
Scanner sc = new Scanner(System.in); | |
double num, exp; | |
System.out.print("Enter num: "); | |
num = sc.nextDouble(); | |
System.out.print("Enter exponent: "); | |
exp = sc.nextDouble(); | |
System.out.println("Result: "+(int)boomboomPow(num,exp)+"."); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment