TRENDING NEWS

POPULAR NEWS

Netbeans - If Statement Expecting

What does the "String[ ] args" in a Java main method actually mean?

Think twice, write once.In programming, one of the main purposes is which the code is cross-platform or not. If you write the code again and again for every little changes, it’s not a good code.To avoid this, some arguments passes from Operating System to application.For example; you write a code that prints all lines of a file. If you write the directory of this file to the code, it will work for just that file. If you want to use same application for different file, you need to change the directory and compile it again.But if you use system arguments, you can pass the directory of the file you want to print. In this case, you write & compile code once and run for all files.

C++, cin statement question?

i think i know what the problem is, but not sure what to do about it.

netbeans is providing a unicode text interface to your running program, and your keyboard and video subsystem is providing an ascii stream.

the key idea is that unicode is basically a two-byte encoding of keyboard characters whereas ascii is just single-byte encoding. so when you press enter on your keyboard, your OS generates the ascii code for enter and sends it to the netbeans input pipe. but netbeans is expecting another byte of data. so you end up needing two keystrokes to get the enter to register. the boxes on output are common when the program produces a unicode stream to an ascii display -- akin to a website sending a language encoded stream to a browser that doesn't have the right character mapping avaialble.

this makes sense because netbeans is targeted at Java development, where everything is unicode anyway. so developing java in netbeans, you'd never see a problem. but because the evolution of eclipse was to be multi-language in terms of programming languages and international languages, eclipse is a lot more sensitive to the two-byte versus one-byte encoding issues.

the other complicating factor that may also be a source of problems is that you're running on a Windows platform (MinGW is to Windows-Linux as Wine is to Linux-win32) In the windows platforms, the "enter" key is mapped to two ASCII characters -- CR followed by LF. In a strict UNIX environment, the "\n" maps to just one character (can't remember if its CR or LF, but would put money on CR before LF.) so that's a possible complication, but becuase the text is producing black/white boxes as well, i'm more inclined to look into the handling of unicode versus ascii first.

fwiw, most developers use eclipse because it's a lot easier to develop plug-ins and perspectives for new languages and capabilities, and makes far fewer assumptions about the native language being used by its host operating system; resulting in better cross-platform and cross-country performance.

How can I solve a syntax error or an unexpected end of a file in PHP?

The best way to solve missing brackets / braces is to use an editor that will highlight the problem and allow you to collapse the code statements using brackets. That way you go along the file, collapse the statements using brackets and find the missing one.I use sublime text most of the time. When I need better debugging I'll go to netbeans or phpstorm.

PHP: Calling a function and passing a value to a variable?

Unfortunately, I did not check the code before I posted the first time. I had to add the "case" keyword for option C and drop the function keyword where I called the checkGrade function. This was easy enough to see when I copied the code into Netbeans. If you don't already use Netbeans, you might want to give it a try. See source link (there is a specific download version for PHP).

function checkGrade($Grade) {

switch ($Grade) {

case "A":
$msg = "Your grade is excellent.";
break;
case "B":
$msg = "Your grade is good.";
break;
case "C":
$msg = "Your grade is fair.";
break;
case "D":
$msg = "You are barely passing.";
break;
case "F":
$msg = "You failed.";
break;
default:
$msg = "You did not enter a valid letter grade.";
break;
}

return $msg;

}

// *** Now call your function.
if (isset($_GET["Grade"])) {

$grade = $_GET["Grade"];

echo(checkGrade($grade));

} else {

echo("Error. No grade selected.");

}

?>

Does Java allow strings and integers to be concatenated?

Two people have suggested that it's something to do with what println does or expects but this is wrong."foo"+10 is an expression in Java whether it is being passed to println or another method or used in an if() statement etc. It is evaluated and the result of evaluation, whatever it may be, is passed to println or anything else.Expressions are evaluated left to right and have a type which is determined at compile-time.The Java rules for expression evaluation say that if one operand of the + operator is a String and the other isn't, then the one that isn't is converted to a String, then they're concatenated left to right. So what happens is the integer literal is converted to an Integer, by doing new Int(10); then this is converted to a String using Integer.toString(); then "foo" and "10" are concatenated. The result of String concatenation is a String and so the compile-time type of this expression is String. At runtime, a String object will be passed to println().That's how it works. (In principle; in reality this example would get optimized.) For the full gory technical details about how expressions are evaluated in Java see Oracle's documentation: Chapter 15. Expressions and Chapter 5. Conversions and Promotions

What is your favorite IDE for Python programming and why?

PyCharm is an editor and debugger developed by Jetbrains who are the same people who developed Resharper which is a great tool used by Windows developers for refactoring code and to make their lives easier when writing .NET code. Many of the principles of Resharper have been added to the professional version of PyCharm.There are two versions available. The community version is for the casual developer whereas the professional environment provides all the tools a developer could need for creating professional software.A really powerful feature of PyCharm is code refactoring . When you start to develop code little marks will appear in the right margin. If you type something which is likely to cause an error or just isn't written well then PyCharm will place a colored marker. Clicking on the colored marker will tell you the issue and will offer a solution. For example, if you have an import statement which imports a library and then don't use anything from that library not only will the code turn gray the marker will state that the library is unused. Other errors that will appear are for good coding, such as only having one blank line between an import statement and the start of a function. You will also be told when you have created a function that isn't in lowercase. You don't have to abide by all of the PyCharm rules. Many of them are just good coding guidelines and are nothing to do with whether the code will run or not.The code menu has other refactoring options. For example, you can perform code cleanup and you can inspect a file or project for issues. So, I choose Pycharm, although it’s a bit costly.

Why doesn’t "sizeof(a)/sizeof(a[0])" work for an array passed as a parameter?

The behavior you found is actually a big wart in the C language. Whenever you declare a function that takes an array parameter, the C standard requires the compiler to ignore you and change the parameter to a pointer. So these declarations all behave like the first one:void func(int *a)void func(int a[])void func(int a[5])typedef int array_plz[5];void func(array_plz a)a will be a pointer to int in all four cases. If you pass an array to func, it will immediately decay into a pointer to its first element. (On a 64-bit system, a 64-bit pointer is twice as large as a 32-bit int, so your sizeof ratio returns 2.)This only happens in the context of function parameters. In general, arrays are not the same thing as pointers. In contexts other than function parameters, such as variables, struct members, array elements, or pointer targets, int *, int[], int[5], and int[7] are all different types with distinguishable behaviors; for instance, they have different sizes. (“The first step to learning C is understanding that pointers and arrays are the same thing. The second step is understanding that pointers and arrays are different.”)The only purpose of this rule is to maintain backwards compatibility with historical compilers that did not support passing aggregate values as function arguments.This does not mean that it’s impossible to pass an array to a function. You can get around this wart by embedding the array into a struct (this is basically the purpose of C++11’s std::array):struct array_rly {
int a[5];
};
void func(struct array_rly a)
{
printf("%zd\n", sizeof(a.a)/sizeof(a.a[0])); /* prints 5 */
}
or by passing a pointer to the array:void func(const int (*a)[5])
{
printf("%zd\n", sizeof(*a)/sizeof((*a)[0])); /* prints 5 */
}
In case the array size isn’t a compile-time constant, you can use the pointer-to-array technique with C99 variable-length arrays:void func(int n, const int (*a)[n])
{
printf("%zd\n", sizeof(*a)/sizeof((*a)[0])); /* prints n */
}

TRENDING NEWS