braces

Strange behavior using braces in Java

眉间皱痕 提交于 2019-12-04 08:48:00
问题 When I run the following code: public class Test { Test(){ System.out.println("1"); } { System.out.println("2"); } static { System.out.println("3"); } public static void main(String args[]) { new Test(); } } I expect to get the output in this order: 1 2 3 but what I got is in reverse order: 3 2 1 Can anyone explain why it is output in reverse order? ================ Also, when I create more than one instance of Test : new Test(); new Test(); new Test(); new Test(); static block is executed

Difference between braces {} and brackets () in shell scripting

喜欢而已 提交于 2019-12-04 05:44:33
We use braces {} for variable expression like NAME="test" FILE_NAME=${NAME}file But I don't understand in which scenarios we use brackets () Say nslookup $(hostname) works only with () brackets. Can someone explain? Minor nitpick first: Brackets [] Parentheses () Braces {} (Double) Quotation marks "" (Single) Quotation marks (apostrophes) '' Backticks `` (Same as the tilde ~ key) Braces are used in BASh scripts for complex variable expansion. Consider string concatenation: STR="hello" STR2=$STR STR2 evaluates to "hello". What if you wanted to make it something like "helloWorld". Doing

How to change brace indentation levels in Emacs?

泄露秘密 提交于 2019-12-03 07:01:26
问题 I can't for the life of me find any answer to this through conventional Internet means, so I'm hoping for some help. Emacs for me right now tends to do indentation on braces as follows: if( ... ) { } Which I find incredibly irritating; I've never even seen this behaviour anywhere else. At any rate, the behaviour I'm expecting is, if( ... ) { } If anyone knows how to modify this, it'd be greatly appreciated. 回答1: Basically you want: (setq c-default-style "bsd" c-basic-offset 4) For more

Bash command groups: Why do curly braces require a semicolon?

匆匆过客 提交于 2019-12-03 05:12:31
I know the difference in purpose between parentheses () and curly braces {} when grouping commands in bash . But why does the curly brace construct require a semicolon after the last command, whereas for the parentheses construct, the semicolon is optional? $ while false; do ( echo "Hello"; echo "Goodbye"; ); done $ while false; do ( echo "Hello"; echo "Goodbye" ); done $ while false; do { echo "Hello"; echo "Goodbye"; }; done $ while false; do { echo "Hello"; echo "Goodbye" }; done bash: syntax error near unexpected token `done' $ I'm looking for some insight as to why this is the case. I'm

Strange behavior using braces in Java

时光怂恿深爱的人放手 提交于 2019-12-03 00:57:41
When I run the following code: public class Test { Test(){ System.out.println("1"); } { System.out.println("2"); } static { System.out.println("3"); } public static void main(String args[]) { new Test(); } } I expect to get the output in this order: 1 2 3 but what I got is in reverse order: 3 2 1 Can anyone explain why it is output in reverse order? ================ Also, when I create more than one instance of Test : new Test(); new Test(); new Test(); new Test(); static block is executed only at first time. It all depends on the order of execution of initialization statements. Your test

How to change brace indentation levels in Emacs?

本小妞迷上赌 提交于 2019-12-02 20:37:58
I can't for the life of me find any answer to this through conventional Internet means, so I'm hoping for some help. Emacs for me right now tends to do indentation on braces as follows: if( ... ) { } Which I find incredibly irritating; I've never even seen this behaviour anywhere else. At any rate, the behaviour I'm expecting is, if( ... ) { } If anyone knows how to modify this, it'd be greatly appreciated. Basically you want: (setq c-default-style "bsd" c-basic-offset 4) For more indentation commands: M-x c-set-style RET style RET Select predefined indentation style style. Type ? when

If Statements And Braces.. Different Result With/Without

给你一囗甜甜゛ 提交于 2019-12-02 20:19:45
问题 Alright, so I'm in the process of learning C++, and I've hit a strange effect while working with one of the tutorials, and I don't quite get while it's happening.. For the tutorial (copied from the example offered), I have written a function within a class template specialization that checks if the char is lowercase, and then makes it uppercase: char uppercase () { //checks to see if "element"(char) is a lower-case letter between 'a' and 'z' if ((element >= 'a') && (element <= 'z')) { /

C language: if() with no else(): using braces fails

旧时模样 提交于 2019-12-02 12:59:08
I'm confused on need for braces after IF() expression. When using IF(){...}ELSE{...} I'm used to using braces around both IF and ELSE blocks. But when I use no ELSE block it works with no braces and fails with braces: works: IF()... fails: IF(){...} Example below, this is for a microcontroller #include "simpletools.h" int main() { while(1) { print("button = %d\n", input(3)); if(input(3) == 1) //works if no braces high(14); pause(50); low(14); pause(50); } //while } // main A single statement follows the if . If you need multiple statements, they must be combined into a single compound

Reached End of file while parsing

痴心易碎 提交于 2019-12-02 10:13:23
I keep getting this message when I try to compile: Reached End of file while parsing Anyone know why? The only thing that I have figured out is that it has something to do with my curly braces. I have tried to move braces around, add them, and delete them but I can not figure this out. The error occurs in the last line of code. import java.awt.event.ActionEvent; //Next group of lines import various Java classes import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JCheckBox; import javax.swing.JPanel; import

If Statements And Braces.. Different Result With/Without

只谈情不闲聊 提交于 2019-12-02 07:38:24
Alright, so I'm in the process of learning C++, and I've hit a strange effect while working with one of the tutorials, and I don't quite get while it's happening.. For the tutorial (copied from the example offered), I have written a function within a class template specialization that checks if the char is lowercase, and then makes it uppercase: char uppercase () { //checks to see if "element"(char) is a lower-case letter between 'a' and 'z' if ((element >= 'a') && (element <= 'z')) { //changes value of "element" to be element + (value of A - Value of a)[-32] element += 'A' - 'a'; //element =