java code table code example

Example 1: Multiplication table for number Java

public static String multiTable(int num) {
        StringBuilder sb = new StringBuilder();

        for (int i = 1; i <= 10; i++) {
            int result = i * num;
            sb.append(i + " * " + num + " = " + result + "\n");
        }
        return sb.toString().trim();
    }

Example 2: Java table

import javax.swing.*;

public class keywords {
    JFrame f;
    keywords(){
        f=new JFrame();
        String data[][]={ {"abstract","assert","boolean","break"},
                {"byte","case","catch","char"},
                {"class","const","continue","default"},
                {"do","double","else","enum"},
                {"extends","final","finally","float"}};
        String column[]={"Keywords","","",""};
        JTable jt=new JTable(data,column);
        jt.setBounds(30,40,200,300);
        JScrollPane sp=new JScrollPane(jt);
        f.add(sp);
        f.setSize(300,400);
        f.setVisible(true);
    }
    public static void main(String[] args) {
        new keywords();
    }

Tags:

Java Example