Hey everyone, I'm really new to java and i was wondering if someone coudl help me get my output as:
User Enters: canada c-a-n-a-d-a
c-a-n-a-d
c-a-n-a
c-a-n
c-a
c
It would be really awesome if some one could help me out please :mrgreen:
Hey everyone, I'm really new to java and i was wondering if someone coudl help me get my output as:
User Enters: canada c-a-n-a-d-a
c-a-n-a-d
c-a-n-a
c-a-n
c-a
c
It would be really awesome if some one could help me out please :mrgreen:
its supposed to be centered though
User Enters: canada c-a-n-a-d-a
c-a-n-a-d
c-a-n-a
c-a-n
c-a
c
well this is the code i have so far
import hsa.Console;
public class L3Q4
{
//Methods go here
public static void main (String args[])
{
//Creates an object named c from the Console game
Console c = new Console ();
//declare variables
String word;
c.println ("Please Enter a word");
word = c.readLine ();
//this outer loope controlls where the loop starts
for (int ctr = 0 ; ctr < word.length () ; ctr += 1)
{
//this loop controlls where the letter ends
for (int ctr2 = 0 ; ctr2 < ctr ; ctr2 += 1)
{
c.print (" ");
}
for (int ctr3 = ctr ; ctr3 < word.length () ; ctr3 += 1)
{
c.print (word.charAt (ctr3));
if (word.charAt (ctr3) != ' ')
{
c.print ("-");
}
}
c.println ("");
}
}
}
the only part i need help on is that when its prints, the last letter repeats on every line but i want the first letter to repeat, so how would i do that?
good?!!!!!
Loop through the string and create substrings or something:
for (int index=string.length-1; index>=0; --index)
{
System.out.println(string.substring(0,index) + "\n");
}
I have no clue if that will work or not.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.