0% found this document useful (0 votes)
25 views3 pages

Gengco Lab6

The document contains code for a NumberManipulation class with 4 methods - isNegative, isPositive, Odd, and Even. Each method takes an integer as a parameter and returns or prints a boolean or string depending on whether the number is negative, positive, odd or even. The main method calls each method by passing sample values and prints the output.

Uploaded by

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

Gengco Lab6

The document contains code for a NumberManipulation class with 4 methods - isNegative, isPositive, Odd, and Even. Each method takes an integer as a parameter and returns or prints a boolean or string depending on whether the number is negative, positive, odd or even. The main method calls each method by passing sample values and prints the output.

Uploaded by

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

Activity 6.1.

Create a method that does the following:


Class Name: numberManipulation (50pts)
1. boolean isNegative(int num) - returns 'true' if negative. -1,-5
3. boolean isPositive(int num) - returns 'true' if positive. 3,5
4. String Odd(int num) - returns "Yes" if Odd, 1,2,3,...,99
5. String Even(int num) - returns "Yes" if Even, 2,4,6,...,100
Sample output:
isNegative : false
isPositive : true
Odd : No
Even : Yes

Your source codes:


public class NumberManipulation {
private static final boolean TRUE = true;
private static final boolean FALSE = false;

public static void main(String[] args) {


System.out.println("Dave C. Gengco\n");
NumberManipulation nm = new NumberManipulation();
nm.isNegative(-1); nm.isPositive(-1); nm.Odd(3);
nm.Even(99);
}
public boolean isNegative(int num){
if (num<=0) System.out.println("isNegative\t: " + TRUE);
else
System.out.println("isNegative\t: " + FALSE);
return true;
}
public boolean isPositive(int num){
if (num >=0) System.out.println("isPositive\t: " + TRUE);
else
System.out.println("isPositive\t: " + FALSE);
return true;
}
public String Odd(int num){ String opt7;

if(num%2==1){
opt7="YES";
System.out.println("Odd\t: "+opt7);
} else{
opt7 = "NO"; System.out.println("Odd\t: "+opt7);
}
return opt7;
}
public String Even(int num){ String opt5; {

if(num%2==0){
opt5="YES";
System.out.println("Even\t: "+opt5);
} else{
opt5 = "NO"; System.out.println("Even\t: "+opt5);
}
}

OUTPUT

Activity 6.2

OUTPUT
ACTIVITY 6.3
import java.util.Scanner;
public class Palindrome1 {

public static void main(String[] args) {


System.out.println(" Dave C. Gengco\n");
Scanner scn = new Scanner(System.in);
String text = scn.nextLine(); reverse(text);
isPalindrome(text);
}
public static void reverse(String str){
String reverse = new StringBuffer(str).reverse().toString();
System.out.println(reverse);
}
public static void isPalindrome(String strReverse){
String reverse = new StringBuffer(strReverse).reverse().toString();
if (reverse.toLowerCase().equals(strReverse.toLowerCase()))
{ System.out.println("is a Palindrome");
}else
System.out.println( "is not a Palindrome");
}
}

ACTIVITY 6.4

import java.util.Scanner;
public class Numbers {

public static void main(String[] args) {


{ System.out.println("Dave C. Gengco\n");
Number dn= new Number();
{
dn.Numbers(1,2);
dn.Numbers(3,2);
dn.Numbers(2,2);
}
public void Number (int c, int b){
int sum = c+b;
if (c==b){
sum = (c+b)*2;
}else
sum = c+b;
System.out.println(sum);
}

You might also like