Click here to Skip to main content
15,908,768 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Java
    import java.io.*;
    import java.util.Scanner;
    import java.lang.String;
public class Amma {
public static void main(String[] args) {
  
           Scanner sc = new Scanner(System.in);
           System.out.println("Enter the String : ");
           String s = sc.nextLine();
          
           for(int i=0; i< s.length();i++)
           {

               for(int j=0;j<i;j++)
               {
            	   
                   System.out.printf("%c ",s.charAt(j));
               }
               System.out.printf("%c\n",s.charAt(i));
               }         

           
       }
          
    }


What I have tried:

also i want to print this in left also how?
a
am
amm
amma
Posted
Updated 27-Sep-22 20:01pm
v3

All it does is read a string from the user and print it. It print the same number of lines as the user entered characters, and each line is one character longer than the one before it.

Basically, it does what you say you want it to do, assuming you enter "amma" as your input.
 
Share this answer
 
Comments
Member 13341845 2-Aug-17 10:54am    
how to run the loop please explain clearly
Member 13341845 2-Aug-17 10:57am    
explain it clearly
OriginalGriff 2-Aug-17 11:03am    
What part of the explanation do you not understand? You wrote the code, after all...
There is a tool that allow you to see what your code is doing, its name is debugger. It is also a great learning tool because it show you reality and you can see which expectation match reality.
When you don't understand what your code is doing or why it does what it does, the answer is debugger.
Use the debugger to see what your code is doing. Just set a breakpoint and see your code performing, the debugger allow you to execute lines 1 by 1 and to inspect variables as it execute.

Debugger - Wikipedia, the free encyclopedia[^]
http://docs.oracle.com/javase/7/docs/technotes/tools/windows/jdb.html[^]
https://www.jetbrains.com/idea/help/debugging-your-first-java-application.html[^]
The debugger is here to show you what your code is doing and your task is to compare with what it should do.
There is no magic in the debugger, it don't find bugs, it just help you to. When the code don't do what is expected, you are close to a bug.
 
Share this answer
 

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