
Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!

------------- Count.java ------------- import
java.io.; _/************************************** Counts from a to b. If (a <= b), it counts up from a to b* Otherwise, it counts down from a to b*************************************/_ public
class
Count {
public
static
void
main(String[] args) {
System.out.println(
"Please enter a start integer"
int
a = Keyboard.inputInteger(); System.out.println(
"Please enter an end integer"
int
b = Keyboard.inputInteger(); if (a <= b) { System.out.println(
"Counting up from "
" to "
while
(a <= b) {System.out.println(a);a++; } }^ else
System.out.println(
"Counting up from "
" to "
while
(a >= b) {System.out.println(a);a--; } } } } ------------- Factorial.java ------------- import
java.io.; _/************************************** Computes the Factorial of an inputted integer (n) n! = n * (n-1) * (n-2) * ... * 1*************************************/_ public
class
Factorial {
public
static
void
main(String[] args) {
System.out.println(
"Please enter an integer (n)."
int
n = Keyboard.inputInteger(); int
fact = 1; int
count = n; while
(count > 0) {fact *= count;count--; }System.out.println(
"The value of "
} ------------- SubstringTesterLong.java ------------- import
java.io.; _/************************************** The long solution to Problem 10c This goes through the first string and compares* all the substrings of first string with second string*************************************/_ public
class
SubstringTesterLong {
public
static
void
main(String[] args) {
System.out.println(
"Please enter first string"
String first = Keyboard.inputString();System.out.println(
"Please enter second string"
String second = Keyboard.inputString(); int
i = 0; boolean
isFound =
false
while
((i <= (first.length() - second.length())) &&
(isFound ==
false
String sub = first.substring(i,i+second.length()); if (sub.equals(second)) { isFound =
true
}i++; } if (isFound) { System.out.println(
"Yes, "
" is a substring of "
first);
else
System.out.println(
"No, "
first);
} ------------- SubstringTester.java ------------- import
java.io.; _/************************************** The shorter, easier version of Problem 10c. Here we use a method from String class* which finds the first occurrence of* second string in first string.* Returning -1 if not found...*************************************/_ public
class
SubstringTester {
public
static
void
main(String[] args) {
System.out.println(
"Please enter first string"
String first = Keyboard.inputString();System.out.println(
"Please enter second string"
String second = Keyboard.inputString(); if (first.indexOf(second) != -1) { System.out.println(
"Yes, "
" is a substring of "
first);
else
System.out.println(
"No, "
first);