Click here to Skip to main content
15,905,563 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
Write a program for this output
_ _ SCHO
_ _ _ SCH
_ _ _ _ SC
_ _ _ _ _ S

_ means space

What I have tried:

I have written this program ...but not getting desired result...can u modify..i am writting only the main part

Import java.util.*;
public class Sample
public static void main(String args)
Scanner sc=new Scanner(;
System.out.println("Enter the string ");
String a= sc.nextInt();
Int len=a.length();
for(int i=0;i<=len;i++)
for(int j=0;j
Updated 22-Feb-23 8:07am
CPallini 22-Feb-23 8:25am    
Why are you asking the user for the input string? It is always "SCHOOL", isn't it?
Amandeep Kour 2023 23-Feb-23 2:43am    
No...its not school depends on user what it enters
Amandeep Kour 2023 23-Feb-23 2:52am    
It can be school or bluej ...or anything that user wants to enter

See String (Java SE 11 & JDK 11 )[^] for the things you can do with strings of characters.
Share this answer
Amandeep Kour 2023 23-Feb-23 2:48am    
Thanks for ur advice
While we are more than willing to help those that are stuck, that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.

So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.

Start by thinking about how you would do it on paper: you'd count the number of characters in the string, then loop round that many times.
The first time, you'd print 0 "-" characters and all the ones in the string.
The second time, you'd print 1 "-" character and all but 1 of the ones in the string.
The third time, you'd print 2 "-" characters and all but 2 of the ones in the string.
And so on.
That tells you what you need to write. Me? I'd write a method that takes a string and an integer, prints that number of "-"'s and the right number of string characters. Then I'd call that inside my loop.

If you are having problems getting started at all, then this may help: How to Write Code to Solve a Problem, A Beginner's Guide[^]
Share this answer
Amandeep Kour 2023 23-Feb-23 2:50am    
Oh....sry .... i am new here ... i didnt knew this rule .... that we can ask only easy questions that one can answer.... difficult questions are not asked here..... next time i will try better not to ask..... sorry for this time
OriginalGriff 23-Feb-23 3:13am    
Difficult questions are allowed, easy questions are allowed - but you didn't ask a question, you posted your assignment and a tiny fragment of pretty much irrelevant code. And that looks like a "do my homework" attempt, which we get a lot.
We are here to help, to teach, to learn: but we do none of those things by providing homework answers that can be handed in as that teaches nothing - we as humans learn by doing, not looking! You can watch as much of the Tour de France as you want, but it won't teach you to ride a bicycle!

That's the point of homework: to make you think about what you are being taught and learn how to apply it to new situations. That is how you learn a skill - by applying it!
And Asking questions is a skill[^] as well - so follow the link and think about what you need to do to get a good answer you can use!
No, we're not hear to do your work for you.

If you've got a problem with your code, fine, we can help with a specific problem. But to ask a bunch of people "do my work for me" is insulting to anyone you ask as well as yourself.
Share this answer
Amandeep Kour 2023 23-Feb-23 2:47am    
Sry.... i am new to this platform... i didnt knew that time ..i will not ask.....better!!!
Dave Kreskowiak 23-Feb-23 9:13am    
It's not just "this platform". It's ALL platforms, everywhere on the web.
Dave Kreskowiak 23-Feb-23 9:21am    
The point of the assignment, and what you are trying to avoid, is to think about the problem and break it down into smaller steps. Without developing this skill, you're going to fail at these classes and higher education.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900