• What Do You Need Help With? V6
    7,544 replies, posted
Java Question. Say I have this for a function [code] public static void printResults(String[] name, double[] radius, double[] mass, double gravity[]) { // fill in code here for(int i = 1; i <= 9; i++){ System.out.printf(); } } [/code] and I have this in my main method [code] printResults(names, radii, mass, gravities);[/code] (names, radii, mass, gravities are all arrays), how would I use printf to properly format the output neatly in columns?
How can I become better at C# web developer, for school? :downs:
Is there any formula to get aspect ratio from resolution?
[QUOTE=eirexe;46359826]Is there any formula to get aspect ratio from resolution?[/QUOTE] W / H
[QUOTE=cartman300;46359833]W / H[/QUOTE] What if I want to transform it into a user friendly value? aka 16:9?
[QUOTE=eirexe;46359891]What if I want to transform it into a user friendly value? aka 16:9?[/QUOTE] You reduce the fraction 800 / 600 => 8 / 6 => 4 / 3
[QUOTE=eirexe;46359891]What if I want to transform it into a user friendly value? aka 16:9?[/QUOTE] Then you find the smallest possible numerator and denominator.
[QUOTE=joshuadim;46355455]Java Question. Say I have this for a function [code] public static void printResults(String[] name, double[] radius, double[] mass, double gravity[]) { // fill in code here for(int i = 1; i <= 9; i++){ System.out.printf(); } } [/code] and I have this in my main method [code] printResults(names, radii, mass, gravities);[/code] (names, radii, mass, gravities are all arrays), how would I use printf to properly format the output neatly in columns?[/QUOTE] Correct me if i'm wrong, but i think you could just add [B]System.out.printf("\n");[/B] Or just after your print inside the loop, do something like this [B]System.out.printf(//your code + "\n");[/B]
What's the point of the #line preprocessor?
[QUOTE=proboardslol;46360362]What's the point of the #line preprocessor?[/QUOTE] so like if you have a custom library (or any library for that matter) that you want to use, that preprocessor (#include) finds that specified library and tells that compiler to include functions from that library example [code]#include time.h[/code] includes functions from the time.h header file so your able to use clock, clock_t.. ect. ect.. without your compiler throwing errors includes any function basically The [I]preprocessor[/I] modifies a source code file before handing it over to the compiler [editline]29th October 2014[/editline] hopefully that answer your question?
[QUOTE=confinedUser;46360631]so like if you have a custom library (or any library for that matter) that you want to use, that preprocessor (#include) finds that specified library and tells that compiler to include functions from that library example [code]#include time.h[/code] includes functions from the time.h header file so your able to use clock, clock_t.. ect. ect.. without your compiler throwing errors includes any function basically The [I]preprocessor[/I] modifies a source code file before handing it over to the compiler [editline]29th October 2014[/editline] hopefully that answer your question?[/QUOTE] I specifically meant the #line preprocessor command
[QUOTE=joshuadim;46355455]Java Question. Say I have this for a function [code] public static void printResults(String[] name, double[] radius, double[] mass, double gravity[]) { // fill in code here for(int i = 1; i <= 9; i++){ System.out.printf(); } } [/code] and I have this in my main method [code] printResults(names, radii, mass, gravities);[/code] (names, radii, mass, gravities are all arrays), how would I use printf to properly format the output neatly in columns?[/QUOTE] Bump, still unanswered :(
[QUOTE=MyNameIsMerl;46358516]How can I become better at C# web developer, for school? :downs:[/QUOTE] I would say practice and use clean and efficient code. There's also an individual Web Developer Forum Category on Facepunch. :wink:
[QUOTE=MyNameIsMerl;46358516]How can I become better at C# web developer, for school? :downs:[/QUOTE] If you want do to web development you're better off learning HTML/Javascript/CSS/etc, not C#. There are plenty of sources you can use such as w3schools or code avengers or lynda.com, along with many others. Or you can learn by yourself and teach yourself. Or go to a class in your school/online class for programming/computer science.
[QUOTE=joshuadim;46360854]Bump, still unanswered :([/QUOTE] Use the escape character "\t" to insert a tab and "\n" to insert an e new line Then use tabs for colums, like this System.out.printf("a\tb\tc\n"); System.out.printf("hello\tworld\tabc\n"); Results in [img]http://i.imgur.com/28xLJID.png[/img]
[QUOTE=joshuadim;46360854]Bump, still unanswered :([/QUOTE] Not exactly sure what you want it to look like, and not sure if C syntax applied, but in C, if you printf something like: [code] int i = 22; printf("i is: %d\n",i); [/code] it will obviously print "i is: 22" however, if you want to organize data output for multiple numbers, like: [code] int main(){ for(int i = 1;i<9;i++){ int m=toPwr(10,i); //exponential function. C doesn't have one built in. raises 10^i. printf("current m is: %d\n",m); } } [/code] the output will look like [img]http://i.imgur.com/fY5ZFnj.png[/img] a left aligned column. I'm guessing what you want is a right aligned column, space far away from the heading. In that case, printf lets you put numbers inbetween % and d (or % and c, % and f, etc.), such as: [code] int main(){ for(int i = 1;i<9;i++){ int m=toPwr(10,i); //exponential function. C doesn't have one built in. raises 10^i. printf("current m is: %10d\n",m); } } [/code] [img]http://i.imgur.com/65uwTM5.png[/img] To add more space, simply increase the number between % and d. It must be noted that to right align all data, you must add a higher or equal number than the number of digits in the highest integer being displayed. Since in my case, the highest integer is 10^9, I have 10 digits, and have to add at least 10 to the spacing. If I added 5 for example, the output would be: [img]http://i.imgur.com/QSIgJbl.png[/img] so if you want to be safe, the highest number of digits a regular 32 bit integer can have is 10, so if you want it to look pretty, try 15: [img]http://i.imgur.com/544jBIM.png[/img] Now let's say you want the spaces, but you want it to be left-aligned. Simple add \t before %d, as in: [code]printf("current m is: \t%d\n",m);[/code] [img]http://i.imgur.com/GihnyiG.png[/img] for more spaces, add more \t !
[QUOTE=proboardslol;46361006]int m=toPwr(10,i); //exponential function. C doesn't have one built in. raises 10^i.[/QUOTE] You mean pow() and exp()?
[QUOTE=BackwardSpy;46361073]You mean pow() and exp()?[/QUOTE] THAT EXISTS???? [editline]29th October 2014[/editline] oh it's in math.h I meant there's no built in operator
[QUOTE=Cold;46360955]Use the escape character "\t" to insert a tab and "\n" to insert an e new line Then use tabs for colums, like this System.out.printf("a\tb\tc\n"); System.out.printf("hello\tworld\tabc\n"); Results in [img]http://i.imgur.com/28xLJID.png[/img][/QUOTE] thanks
Guys, I could use some help understanding input/output to/from txt files in C++. If I have this function that saves to file. [CODE]saveToFile(arrayWithStrings, numberOfItemsInArray) { std::fstream fs; fs.open ("test.txt", std::fstream::in | std::fstream::out | std::fstream::app); for (int i = 0; i < numberOfItemsInArray; i++) { fs << arrayWithStrings[i].getString(); } fs.close(); }[/CODE] Assuming the .getString would return a string to save. I just can't seem to get this to work.. Same thing with loading a file.. Do I have to manually create the file for it to work?
[QUOTE=proboardslol;46360362]What's the point of the #line preprocessor?[/QUOTE] #line modifies the line number output by __LINE__ and other things that use it like assert()). C is such a manual language that extra compilation steps are not uncommon. For example, if you're writing RPC code, you will probably run your RPC functions and structs through some program that produces the networking/serialization code for them. Those compilation steps can inflate the code files [i]before[/i] they're passed to the preprocessor that processes __LINE__, which would result the line numbers in your code not matching those in the output program - unless the compilation step used #line to fix the line numbers.
Another java question. How would I read a list of integers and place it into an array into my java program? For example: [code] public static void getGravity(double[] gravity)throws IOException { //fill in code double token = 0; int i = 0; File inputFile = ("gravities.txt"); Scanner inputFile = new Scanner(inputFile); while (inFile.hasNext()) { token = inFile.net(); gravity[i] = token; i++; } } [/code] This is my code for trying to get the data in the file. This is what's in the file itself. [code] 3.69800012418735 8.868931664345153 9.78883786487358 3.6988318979269796 24.79502448454766 10.429699282821904 8.860452425760279 11.084950016446083 0.5931898951348892 [/code] What should I change/do to make this work properly?
[QUOTE=joshuadim;46361876]Another java question. How would I read a list of integers and place it into an array into my java program? For example: [code] public static void getGravity(double[] gravity)throws IOException { //fill in code double token = 0; int i = 0; File inputFile = ("gravities.txt"); Scanner inputFile = new Scanner(inputFile); while (inFile.hasNext()) { token = inFile.net(); gravity[i] = token; i++; } } [/code] This is my code for trying to get the data in the file. This is what's in the file itself. [code] 3.69800012418735 8.868931664345153 9.78883786487358 3.6988318979269796 24.79502448454766 10.429699282821904 8.860452425760279 11.084950016446083 0.5931898951348892 [/code] What should I change/do to make this work properly?[/QUOTE] Almost there, In cases like this its smart to check out the documentation and see if anything would help [url]http://docs.oracle.com/javase/7/docs/api/java/util/Scanner.html[/url] Since your file is basically numbers "seperated" by a new line. So by using hasNextLine instead of hasNext and and nextLine instead of next you're pretty much there. nextLine returns a string instead of a [B]double[/B], you can convert a string to a double by calling parseDouble.
[QUOTE=joshuadim;46360915]If you want do to web development you're better off learning HTML/Javascript/CSS/etc, not C#. There are plenty of sources you can use such as w3schools or code avengers or lynda.com, along with many others. Or you can learn by yourself and teach yourself. Or go to a class in your school/online class for programming/computer science.[/QUOTE] There's nothing too terribly wrong with ASP.net, it's just largely confined to webservers on Windows (although I believe Mono provides an Apache module for ASP.net). I think that any further debate on this topic should head over to the Web Development Category.
ASP.NET is very heavily used in enterprise software (automation) due to the really neat SOAP(webservice) integration, and easy interfacing with existing native (pinvoke) or C# applications. vNext is the offical open-source/cross-platform implementation of ASP.NET but currently still early in development. I really suggest HTML/Javascript/CSS first and then a simple server language like PHP
[QUOTE=Cold;46362156]Almost there, In cases like this its smart to check out the documentation and see if anything would help [url]http://docs.oracle.com/javase/7/docs/api/java/util/Scanner.html[/url] Since your file is basically numbers "seperated" by a new line. So by using hasNextLine instead of hasNext and and nextLine instead of next you're pretty much there. nextLine returns a string instead of a [B]double[/B], you can convert a string to a double by calling parseDouble.[/QUOTE] Alright cool, thanks! Also, when I try to compile it, it says that gravities.txt is an incompatible type, which I find weird, any idea why it's like that?
[QUOTE=joshuadim;46363777]Alright cool, thanks! Also, when I try to compile it, it says that gravities.txt is an incompatible type, which I find weird, any idea why it's like that?[/QUOTE] The compiler should give you a line number where the error occurred. The problem should be obvious if you read your java book, but if you din't, you just google for examples that do things likewise to what you want to do, and figure out what you're doing wrong.
Apologies if this is the wrong section to ask about this. Does anybody here know anything about the steam browser protocol? I'm trying to make a thing that automatically sends a message to someone on my friends list but I can't figure out how. This is all I was able to get: [code]steam://friends/message/<id>[/code] This opens a chat window with them, but I can't figure out how to get it to send messages. Any idea where to find out how?
[QUOTE=joshuadim;46363777]Alright cool, thanks! Also, when I try to compile it, it says that gravities.txt is an incompatible type, which I find weird, any idea why it's like that?[/QUOTE] [code] File inputFile = ("gravities.txt"); [/code] I think it's because you're setting a File to a string when it really wants a file. [code] File inputFile = (new File("gravities.txt"); [/code] This might fix your incompatible type problem. [editline]29th October 2014[/editline] [QUOTE=Ardosos;46364692]Apologies if this is the wrong section to ask about this. Does anybody here know anything about the steam browser protocol? I'm trying to make a thing that automatically sends a message to someone on my friends list but I can't figure out how. This is all I was able to get: [code]steam://friends/message/<id>[/code] This opens a chat window with them, but I can't figure out how to get it to send messages. Any idea where to find out how?[/QUOTE] Here's what you need [code] steam://friends/message/7656119xxxxxxxxxx/<Your message here> [/code] Which means taking your friends name and trying to find its Steam64 ID, and replacing the rest of the numbers with what the ID actually is. I don't know if the traditional Steam ID format, STEAM_0:X:XXXXXX is compatible.
[QUOTE=Ardosos;46364692]Apologies if this is the wrong section to ask about this. Does anybody here know anything about the steam browser protocol? I'm trying to make a thing that automatically sends a message to someone on my friends list but I can't figure out how. This is all I was able to get: [code]steam://friends/message/<id>[/code] This opens a chat window with them, but I can't figure out how to get it to send messages. Any idea where to find out how?[/QUOTE] You can't.
Sorry, you need to Log In to post a reply to this thread.