If ud = u , du = d , uu = d , dd = u
And if i get the output “uu du ud” is there a way to get output like this
uu du ud ---Output already got
d d u ---Because uu=d du=d ud=u
u u ---Because dd=u and the other u comes down
d ---finally uu=d so the output is d.
I have have problems with getting this kind of output ,coz i dont know java much.
The code I had written is
public class Test
{
public static void main(String[] args)
{
int count = 0;
int index = 0;
Scanner scan = new Scanner(System.in);
System.out.print("How many Line Paremeters?");
int amount = scan.nextInt();
// One array to hold all the names
String[] name = new String[amount];
System.out.print("You entered "
+ amount + " as the size of your name list.");
System.out.println(" ");
// Ask for all the names
for (index = 0; index < amount; index++)
{
System.out.print("Enter Line Paremeters: ");
name[index] = scan.next();
}
System.out.println(" ");
System.out.println("The order: ");
System.out.println(" ");
System.out.println();
for (String names1 : name)
{
System.out.print(names1 + " ");
}
}
}
If I understand correctly you already have the string “uu du ud” and you want to “reduce” it based on the rule: ud = u , du = d , uu = d , dd = u and any left over characters will “come down” as you put it. To do that you need to write a recursive function or an iterating loop ( as per comments) that examines the string in chunks of 2 character long substrings and replace as you go according to your rule. I am reluctant to help any further as this does seem to be homework as @DuncanJones asked.