This is a mess. What I want to do is make 1 program with the 3 loops in it do something different and produce an output of what each loop does.
Do loop: print out every other character
For loop: print out the string reversed
While loop: print out in reverse every other character
Example:
I enter something stupid like: now is the time
I get as a result: Do - nwi h ie
For - emit eht si won
While - ei h iwn
Now, I have no problem doing this in their own separate programs and using an array, but I am not allowed to do that this time. Also, I cannot use any reverse methods or arrays.
This is a mess, and as of posting this, I am still working with my partner trying to figure this out. I do realize I am missing a substantiate amount of code, but we are at a road block.
/*
January 19, 2012
Lab 2 Part B
Part B Program: Loops.java
*/
import java.util.Scanner;
public class Loops
{
public static void main(String[] args)
{
String input, output;
int i = 0;
Scanner scan = new Scanner(System.in);
System.out.println("Enter something: ");
input = scan.nextLine();
output = "";
do
{
i = input.length() - 1;
output = output + input.charAt(i);
i--;
}
while (i <= 0);
System.out.println("Every other character: " + output);
for (i = input.length() - 1; i != -1; i--);
{
output += input.charAt(i);
}
while (i >= 0)
{
output = output + input.charAt(i);
i--;
}
System.out.println("Reversed every other character: " + output);
}
}