karthikeya Boyini

karthikeya Boyini

1,421 Articles Published

Articles by karthikeya Boyini

Page 117 of 143

How to output colored text to a Linux terminal?

karthikeya Boyini
karthikeya Boyini
Updated on 30-Jul-2019 9K+ Views

Here we will see how to print some lines into the linux terminal with some color. Here we are doing anything special into C++ code. We are just using some linux terminal commands to do this. The command for this kind of output is like below.\033[1;31m Sample Text \033[0mThere are some codes for text styles and colors. These are listed below.ColorForeground CodeBackground CodeBlack3040Red3141Green3242Yellow3343Blue3444Magenta3545Cyan3646White3747Some additional options are like below −OptionCodeDescriptionReset0Back to normal (remove all styles)Bold1Bold the textUnderline4Underline textInverse7Interchange colors of background and foregroundBold off21Normal from boldUnderline off24Normal from UnderlineInverse off27Reverse of the InverseExample#include using namespace std; main() {    cout

Read More

Determine what a MySQL DB's charset is set to

karthikeya Boyini
karthikeya Boyini
Updated on 30-Jul-2019 164 Views

Let’s say we are creating a database “web” −mysql> SHOW CREATE DATABASE web;This will produce the following output displaying the default charset as well −+----------+-----------------------------------------------------------------------------------------+ | Database | Create Database                                                                         | +----------+-----------------------------------------------------------------------------------------+ | web      | CREATE DATABASE `web` /*!40100 DEFAULT CHARACTER SET utf8 COLLATEutf8_unicode_ci */ | +----------+-----------------------------------------------------------------------------------------+ 1 row in set (0.03 sec)If you want to know ...

Read More

Averaging a total from a Score column in MySQL with the count of distinct ids?

karthikeya Boyini
karthikeya Boyini
Updated on 30-Jul-2019 113 Views

You can use DISTINCT along with COUNT(). Let us first create a table −mysql> create table DemoTable    -> (    -> Id int,    -> Score int    -> ); Query OK, 0 rows affected (0.95 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(10, 90); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values(10, 190); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values(11, 230); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values(11, 130); Query OK, 1 row affected (0.17 ...

Read More

How can I clear console using C++?

karthikeya Boyini
karthikeya Boyini
Updated on 30-Jul-2019 13K+ Views

We can clear the console using C++ code. To do this we have to execute some system commands. In Linux systems, the POSIX is used. We can call system() function to execute system command. For clearing the console in linux, we can use “clear” command. This will be passed inside the system() function.Let us see the code to get the better idea.Example#include using namespace std; int main () {    cout

Read More

How to create a high resolution timer with C++ and Linux?

karthikeya Boyini
karthikeya Boyini
Updated on 30-Jul-2019 2K+ Views

To create high resolution timer we can use the chrono library. This library has high resolution clock. This can count in nanoseconds.In this program we will see the execution time in nanoseconds. We will take the time value at first, then another time value at the last, then find the difference to get elapsed time. Here we are using blank loop to pause the effect for sometimes.Example#include #include typedef std::chrono::high_resolution_clock Clock; main(){    auto start_time = Clock::now();    for(int i = 0; i

Read More

Bool to int conversion in C++

karthikeya Boyini
karthikeya Boyini
Updated on 30-Jul-2019 13K+ Views

Here we will see how to convert bool to int equivalent in C++. Bool is a datatype in C++, and we can use true or false keyword for it. If we want to convert bool to int, we can use typecasting. Always true value will be 1, and false value will be 0.Example#include using namespace std; main() {    bool my_bool;    my_bool = true;    cout

Read More

How to change JLabel font in Java

karthikeya Boyini
karthikeya Boyini
Updated on 30-Jul-2019 15K+ Views

To change JLabel font, use the setFont() method −JLabel lable = label.setFont(new Font("Verdana", Font.PLAIN, 18));Examplepackage my; import java.awt.Font; import javax.swing.*; public class SwingDemo {    public static void main(String args[]) {       JFrame frame = new JFrame("Label Example");       JLabel label;       label = new JLabel("First Label");       label.setBounds(50, 50, 100, 30);       label.setFont(new Font("Verdana", Font.PLAIN, 18));       frame.add(label);       frame.setSize(300,300);       frame.setLayout(null);       frame.setVisible(true);    } }Output

Read More

How to add tooltip to JLabel in Java?

karthikeya Boyini
karthikeya Boyini
Updated on 30-Jul-2019 1K+ Views

Tooltip is visible whenever you will place the mouse cursor on the label. Use the setToolTipText() method to add tooltip to JLabel −label.setToolTipText("This is a demo tooltip");The following is an example to add tooltip to JLabel −Exampleimport java.awt.Color; import java.awt.Font; import javax.swing.*; import javax.swing.border.Border; public class SwingDemo {    public static void main(String args[]) {       JFrame frame = new JFrame("Demo");       JLabel label;       label = new JLabel("Demo Label!");       label.setFont(new Font("Verdana", Font.PLAIN, 14));       label.setToolTipText("This is a demo tooltip");       Border border = BorderFactory.createLineBorder(Color.ORANGE);     ...

Read More

How to Map IntSteam to String object in Java

karthikeya Boyini
karthikeya Boyini
Updated on 30-Jul-2019 230 Views

To Map IntStream to String object, use mapToObj and within that set the values −.mapToObj(val -> "z" + val)Before that, we used range() on IntStream −IntStream.range(1, 10)The following is an example to map IntStream to String object in Java −Exampleimport java.util.stream.IntStream; public class Demo {    public static void main(String[] args) throws Exception {       IntStream.range(1, 10)       .mapToObj(val -> "z" + val)       .forEach(System.out::println);    } }Outputz1 z2 z3 z4 z5 z6 z7 z8 z9

Read More

Execute operations (plus, minus, multiply, divide) while updating a MySQL table?

karthikeya Boyini
karthikeya Boyini
Updated on 30-Jul-2019 461 Views

Following is the syntax executing the plus (+) operator −update yourTableName set yourColumnName3=(yourColumnName1+yourColumnName2)The above syntax is only for plus operator. You need to change symbol like -, *, / for other operations. Let us first create a table −mysql> create table DemoTable    -> (    -> Number1 int,    -> Number2 int,    -> AddResult int,    -> MinusResult int,    -> MultiplyResult int,    -> DivideResult int    -> ); Query OK, 0 rows affected (0.89 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(Number1, Number2) values(40, 20); Query OK, 1 row affected (0.16 ...

Read More
Showing 1161–1170 of 1,421 articles
« Prev 1 115 116 117 118 119 143 Next »
Advertisements