9_10 INTRO BASIC PROGRAMS
9_10 INTRO BASIC PROGRAMS
Define a method which returns the sum of digits of the given two digit number.
Write the method with the following specifications:
Name of the BLC class:TwoDigitsSum
Name of method: getSumOfDigits()
Access Modifier : public, static
Arguments: one argument of type integer
Return type: an integer value
For example,
If the given value is 34, return 7
package sep10;
import java.util.*;
public class p1 {
package sep10;
}
Program-2
Define a method which returns the difference of digits of the given two digit number.
Write the method with the following specifications:
Name of the BLC class:TwoDigitsDifference
Name of method: getDiffOfDigits()
Access Modifier : public, static
Arguments: one argument of type integer
Return type: an integer value
For example,
If the given value is 83, 8 - 3 return 5. If x = 38, 3 - 8 return -5.
package sep10;
import java.util.*;
public class p2 {
TwoDigitsDifference.getDiffOfDigits(n);
sc.close();
package sep10;
System.out.println("Difference: "+(n/10-n%10));
}
Program-3
Define a method which returns the next multiple of 100 for the given number.
Write the method with the following specifications:
Name of the BLC class:NextMultipleOfHundred
Name of method: getNextMultipleOfHundred()
Access Modifier : public, static
Arguments: one argument of type integer
Return type: an integer value
For example,
If the given value is 123, return 200.
package sep10;
import java.util.*;
public class p3 {
System.out.println("Enter a number:");
Scanner sc = new Scanner(System.in);
int n =sc.nextInt();
NextMultipleOfHundred.getNextMultipleOfHundred(n);
sc.close();
}
package sep10;
System.out.println("Result: "+(n/100+1)*100);
}
}
Program-4
Define a method which returns the sum of three rounded numbers. If the right most digit of the
number is less than 5, then round off its value to the previous multiple of 10 otherwise if the right
most digit of the number is greater or equal to 5, and then round off to the next multiple of 10.
Write the method with the following specifications:
Name of the BLC class:RoundedSum
Name of method: sumOfRoundedValues()
Access Modifier : public, static
Arguments: three argument of type integer
Return type: an integer value
For example
If a = 23, b = 34, c = 66
20 + 30 + 70 = 120
Note:Don't use any control statements and looping statements
package sep10;
import java.util.Scanner;
public class p4 {
System.out.println("Enter a number:");
Scanner sc = new Scanner(System.in);
int a =sc.nextInt();
int b =sc.nextInt();
int c =sc.nextInt();
RoundedSum.sumOfRoundedValues(a, b, c);
sc.close();
}
package sep10;