Text Blocks in Java with Examples

Get Job-ready: Java Course with 45+ Real-time Projects! - Learn Java

Program 1

// Program TextBlock
import java.util.*;
public class TestTextBlock 
{
    public static void main(String[] args) 
    {
        //  String str=" Item Id\t Item Name \t Qty\t amount \n"
        //  + "     101\tFrooti\t10\t200" +"\n102\t Pepsi\t30\t3400"; 

        // Scanner scan=new Scanner(System.in);
        // int id;
        // String name;
        // System.out.println("Enter Product id");
        // id=scan.nextInt();
        // System.out.println("Enter Product Name");
        // name=scan.next();
        // String str="""
        //           Item id       Name         
        //           --------------------
        //           %d           %s   
        //          ---------------------  
        //         """;
        // System.out.println(String.format(str, id,name));    
          Scanner scan=new Scanner(System.in);
          System.out.println("Enter  a String");
          String S;
          S=scan.next();
        String htmlstr;
        htmlstr="""
                  <html>
                     <head><title> This is a text block </title></head>
                     <body>
                       <h1>%s</h1>
                     </body>
                  </html>   
                """;
           System.out.println(String.format(htmlstr, S));
    }    
}

 

If you are Happy with DataFlair, do not forget to make us happy with your positive feedback on Google

courses

DataFlair Team

DataFlair Team provides high-impact content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. We make complex concepts easy to grasp, helping learners of all levels succeed in their tech careers.

Leave a Reply

Your email address will not be published. Required fields are marked *