Output of code (asked in competition)
The output of the following code was asked in yesterday's Microsoft competition
import java.lang.*;
public class ms1
static int NumberCruncher(int num,boolean flag)
if(num==0)
return num;
if(flag)
return (NumberCruncher(num/10,false)+num%10);
else
return (NumberCruncher(num/10,true)-num%10);
public static void main(String args[])
int i=927384509,j;
while(i>=10)
j=NumberCruncher(i,true);
i=j>0?j:-j;
System.out.println(i);
}and I answered that the output is 0, due to the following steps.
Where did I go wrong?
927384509, true
92738450 + 9 = 92738459, false
9273845 - 9 = 9273836, true
927383 + 6 = 927389, false
92738 - 9 = 92729, true
9272 + 9 = 9281, false
928 - 1 = 927, true
92 + 7 = 99, false
9 - 9 = 0
(Everytime the last digit is trimmed off,
and if the flag is false, it is subtracted with the rest of the digits,
and if the flag is true, it is added up with the rest of the digits,
and the flag alternates between true and false, each time,
that is my guess)
Run this to see if it becomes clear:
public class Test {
static int NumberCruncher(int num,boolean flag) {
System.out.print("num == "+num+", flag == "+flag);
if(num==0) {
System.out.println(", so returning: "+num);
return num;
if(flag) {
System.out.println(", so returning: NumberCruncher("+(num/10)+",false) + "+num%10);
return (NumberCruncher(num/10,false)+num%10);
else {
System.out.println(", so returning: NumberCruncher("+(num/10)+",true) - "+num%10);
return (NumberCruncher(num/10,true)-num%10);
public static void main(String args[]) {
int i=927384509,j;
while(i>=10) {
j=NumberCruncher(i,true);
i=j>0?j:-j;
System.out.println("In while-statement: i == "+i);
}Output:
num == 927384509, flag == true, so returning: NumberCruncher(92738450,false) + 9
num == 92738450, flag == false, so returning: NumberCruncher(9273845,true) - 0
num == 9273845, flag == true, so returning: NumberCruncher(927384,false) + 5
num == 927384, flag == false, so returning: NumberCruncher(92738,true) - 4
num == 92738, flag == true, so returning: NumberCruncher(9273,false) + 8
num == 9273, flag == false, so returning: NumberCruncher(927,true) - 3
num == 927, flag == true, so returning: NumberCruncher(92,false) + 7
num == 92, flag == false, so returning: NumberCruncher(9,true) - 2
num == 9, flag == true, so returning: NumberCruncher(0,false) + 9
num == 0, flag == false, so returning: 0
In while-statement: i == 29
num == 29, flag == true, so returning: NumberCruncher(2,false) + 9
num == 2, flag == false, so returning: NumberCruncher(0,true) - 2
num == 0, flag == true, so returning: 0
In while-statement: i == 7
Similar Messages
-
Error for output tax code:Tax code I4 may only contain one assignment line.
Hi
While posting customer invoice with output tax code, I am getting following error.
Tax code I4 may only contain one assignment line.
Please help me resolve.
Regards
RekhaThere are quite some answered questions in this forum for this issue.
Here is one.
Error in Sample document (Message no. FF731)
Also, please search the forum with the following search key words.
Tax AND code AND may AND only AND contain AND one AND assignment AND line
Make sure you select all posts, not just the past 90 days (the default option), and you will see quite some hits. -
Output Tax Code In Purchase Order
Hi all,
It's possible to assign an output tax code to a purchase order?
The system gives me the error message 6164 'Please enter an input tax code, not an output tax code' when I use an output tax . Is there any customization to allow output taxes in purchase orders?
Thank you,
RSDear friend...
You cannot use output tax code in purchase order, since output tax codes are used only for sales. If you use output tax code in the PO it will obviously throw the error you said. If you want to have the taxes as shown in the output taxes, if not present in your input tax codes, you can create new tax code which you desire. Output codes are only for the Sales Order.
Hope it helps re-ward if so
Suraj -
Enter an input tax code, not an output tax code in Txn CNMM
Hi All,
We are trying to use PROMAN transaction CNMM from Project systems for converting PR to PO. But when I try to do that I get the following error
"Enter an input tax code, not an output tax code"
So it seems that the system is picking the incorrect sales tax code in PO because of which the PR is not converted to PO then. But when I check in transaction CNMM there is no place to input a tax code anywhere. So the system is probably picking it from somewhere, but I am not able to figure out where is it picking it from.
Does someone have an idea about where the system is picking the tax code?
Regards,
V SHi,
Can you do one thing in your testing server....
Create purchase requisition manually for that material and with respect to that requisition try to create PO without putting any tax code, and see whether you are able to create PO, keep the same document types at PR and PO level, (it should be the same when you create PO thru CNMM)
-Saleel -
POs that accept Output tax code
Hi all -
I am trying to create a PO with Output tax as the Tax code in the Invoice tab in ME21N. Could anyone please let me know the types of POs that could be created with Output Tax code.
Thanks -
ShilpaFor Sales Order's related PO Can you use this Tax type..
-
Capture JVM output machine code
Does anybody know how to capture the machine code output from the JVM? I am running Windows Vista Professional.
I ask because I am creating a Computer Architecture course, and I would like to show the students the IA instructions that are generated by the JVM. The textbooks I have been investigating traditionally introduce assembly language by way of C++. The problem is that these students are taught programming using Java. I know the Java compiler output is bytecode, but this does not help me teach the actual architecture of the computer.
Thanks in advance.Thanks all for you replies
georgemc: What you are saying is that while one can recognize a method that was written in Java in the bytecode, there is no relation between the original method (or the corresponding bytecode for that matter), and the machine code output of the JVM? For example, using Visual C++ once can view the disassembly of a method and see the IA assembly language, the values of the registers (including the flags register).
paulcw: Thanks for the suggestion. Your approach may work for future sessions, but I am afraid I do not have time to implement for this coming semseter
Captain Obvious (nice name): I had thought of taking an approach similar to your posting. However, I must cover specific topics in the class and there will not be time. For instance, I am expected to cover representing and manipulating information, machine-level representation of programs, processor architecture, optimizing program performance, memory hierarchy, exceptional control flow, and virtual memory. The difficulty some students encounter is that, up until this course, have been taught only Java programming. Then, they take this course which teaches everything from a C/C++ perspective. I was hoping I could demonstrate machine code in C++, as well as Java in an attempt to keep all levels of students engaged. -
How to output HTML code in methods without out.print
Hi,
I am trying to create a larger web-site with jsp. At first I tried to structure the page using include files. Since there is a limit for the length of if/else blocks, I now switched to using methods instead.
The Problem I have is that there a larger HTML blocks I dont want to print with out.print because that would make the source unreadable.
Unfortunately the <%= tag doesnt work in methods.
Here a code sample:
<%!
public void processOrder()
for(int i=1; i<10; i++)
out.print("<table>");
out.print("<tr>");
out.print("<td>Your Order:<td>");
%>
Isnt there a way to use a tag like <%= ?
Or are there other constructs then methods which can handle <%= ?
With PHP it would be no problem. So I wonder why there should be no way to do it with jsp.I generally put dynamic output in a separate class file; you can then either instantiate the class in a scriptlet and call the appropriate method (which can either return a string or do all of your out.prints) or use a jsp:useBean tag.
Given the following class:
public class myHTML {
public myHTML(){}
public String renderTable(){
String s = "";
s += "<TABLE>\n";
s += "<TR><TD>some content</TD></TR>\n";
s += "</TABLE>\n";
return s;
}You can then do either of the following in your JSP page:
1.<%
myHTML mh = new myHTML;
out.print(mh.renderTable());
%>2.<jsp:useBean id="somename" class="somepkg.myHTML" scope="request">
<%=somename.renderTable()%>
</jsp:useBean>Either will work, and all of the redundant out.print or String concat lines are moved out of the JSP. -
Error with output file code in utl (v_out_file)
v_out_file := utl_file.fopen (r_dca.directory_name, 'GradChallenge' || TRIM(TO_CHAR(SYSDATE,'YYYYMMDD')) || '.txt', 'W');
I was just wondering guys, the error occurs 'r_dca.directory_name'. There is an issue with r_dca, I am just stuck on what to name to put to replace it.
the complete code is specified below
Create or replace
PROCEDURE Grad_Five
IS
v_out_file UTL_FILE.FILE_TYPE;
v_out_directory all_directories.directory_path%type;
v_out_filehandle UTL_FILE.FILE_TYPE := NULL;
v_out_buffer varchar2(32767);
v_header VARCHAR2(32759 BYTE);
r_users varchar2(32759 BYTE);
r_dca number;
BEGIN
-- Output file
v_out_file := utl_file.fopen (r_dca.directory_name, 'GradChallenge' || TRIM(TO_CHAR(SYSDATE,'YYYYMMDD')) || '.txt', 'W');
-- Header
v_header := sysdate;
utl_file.PUT_LINE(v_out_file,v_header,TRUE);
FOR r_users IN
( SELECT
USERS.ID,
USERS.LOGINNAME,
USERS.FORENAME,
USERS.SURNAME
FROM USERS
LOOP
BEGIN
UTL_FILE.PUT_LINE (v_out_file,
r_users.ID|| ',' || r_users.LOGINNAME|| ',' ||r_users.FORENAME|| ',' ||r_users.SURNAME);
END;
END LOOP;
FOR r_users in
( SELECT COUNT (ID) from Users )
LOOP
BEGIN
UTL_FILE.fclose (v_out_file);
END;
END LOOP;
COMMIT;
END GRAD_FIVE;
Would appreciate help, Thank you again.Here's something that might help:
(Example 1)
http://docs.oracle.com/cd/B19306_01/appdev.102/b14258/u_file.htm
You need to:
1. Create a directory:
CREATE DIRECTORY EXAMPLE_DIR AS '<OS_DIR_PATH>';
Eg: CREATE DIRECTORY EXAMPLE_DIR AS '/temp';
2. Reference the previously created directory:
v_out_file := utl_file.fopen ('EXAMPLE_DIR', 'filename.extension', 'W');
My guess is that r_dca.directory_name does not point to a directory object (Step 1) but to an absolute OS path.
Also make sure you grant the appropriate rights on you directory:
Eg:
GRANT READ ON DIRECTORY EXAMPLE_DIR to <your_user>;
Edited by: RMi on Feb 2, 2012 6:07 AM -
Change name of parameters output by code module
Hi guys,
I am calling this code module everytime but pass different parameters as input & get different results
I want to customize the Parameter Name for the output parameters as they get saved in my report.
& so I can be very specific.Hi,
I think it is not an option or configuration in TestStand. You can try to change the parameter name in the code module.
Have you tried this?
best regards
Richard -
Pagination of output php code with sql code
if one program of php including sql query
it seems to output wrong .(means some data will be calculated sum)
if php code output all data in one page.pagination
it seems to output right(means some data will be calculated sum)
if there has column of company including two companies of A and B.
and if each page output 3 lines while A company has 4 lines in sql query,so
the last line of A company will output in second page,
i want to calculate A company including 4 lines sum
how to calculate sum of company of A in second page.
i think it will be a good interesting question of php code with sql code.
who can solution thus question ?
thanks !Hi,
for Example:
SELECT sum(quantity * price)
FROM orders
WHERE COMPANY = 'A';
This will give you the total amount for company A.
But remember that your example table will give no output, since you have no price column. So you must decide, what which sum to calculate.
A sum only calculated over the quantity makes IMHO no sense, because there are apples and bananas ...
Greetings from Hamburg
Thorsten Körner -
Code asked for while downloading Adobe creative suite 6 Design Standard
while downloading the Creative suite 6 i was aked for a code on the top left of the inside box ...doesnt seem to be one....is this PNn umber on the adobe sticker on the end of the box.
help!you're probably being asked for the serial number, http://helpx.adobe.com/x-productkb/global/find-serial-number.html
if you're not being asked for the serial number, attach a screenshot showing the request dialog, http://forums.adobe.com/message/4209263#4209263 -
Output from code running on azure cloud
How do I get the log files from an azure cloud service / or the output from an azure cloud service.
I DO NOT mean the azure cloud logs, i.e. the logs produced by the management portal - I mean the actual output of my code.
If I run the code locally it goes to console, so I can see it, but how do I see it when it is running as an azure cloud service?
I am on VS2013 / .NET4.5 / Azure SDK2.4
thxHi,
Requests may be load balance to different azure cloud service instance, so azure storage service is a good choice to save the log message, based on your description, you don't want to use azure cloud logs, because it is produced by management portal, I don't
know whether you mentioned is Azure Diagnostics or not, as far as I know, we can log our exception code to azure storage just use Trace.WriteLine(), refer to
http://blogs.msdn.com/b/sumitm/archive/2009/11/25/windows-azure-walkthrough-simple-logging.aspx for more details,and
azure storage explorer is a good tool to see the error details, below is the article that show us how to Configure Diagnostics for Azure Cloud Services.
#http://msdn.microsoft.com/en-us/library/azure/dn186185.aspx
If I misunderstand, please feel free to let me know.
Best Regards,
Jambor
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click
HERE to participate the survey. -
Prinouts outputting PJL code.
Our network printers recently began delivering printouts in PJL code. What is causing this?
Our print server is windows 2008 R2. We have tried various versions of HP's Universal PS drivers without success.
Our printer models vary. Mostly HP P4014. The client PCs are both Windows7 and XP.Compare the page source with what you expected. I suspect that the JSF portion is behaving as expected.
-
Can Labview output source code in text format?
I am trying to file a patent that includes some Labview code. The patent office recommends attaching code (either source code or machine code) to show reduction to practice.
However, it appears that the USPTO only accepts CD-Rs that have ASCII text on them. Is there a way to export Labview source code or machine code (from application builder?) to text?
Does anyone have any advice for dealing with the PTO when Labview code is involved?
Thanks,
Casey> I am trying to file a patent that includes some Labview code. The
> patent office recommends attaching code (either source code or machine
> code) to show reduction to practice.
>
> However, it appears that the USPTO only accepts CD-Rs that have ASCII
> text on them. Is there a way to export Labview source code or machine
> code (from application builder?) to text?
>
> Does anyone have any advice for dealing with the PTO when Labview code
> is involved?
>
I believe this has been done before. I did a quick search on
www.uspto.gov, and found lots of them referencing LabVIEW -- meaning
that LabVIEW was mentioned in the patent, and probably that LV code was
the mentioned embodiment of the patent. I didn't browse all of them to
see if or how they i
ncluded source, but surely you can find a precedent
for including a pdf or rtf with your diagrams.
If you can't find anything else, print your VIs to RTF and see about
submitting that.
Greg McKaskle -
Hi,
I need to trigger some messages using javascript code. The problem is that the code must be triggered from my controller classes and displayed inmediately, before calling the view: this means the JS code is not in the view !!
I had thought of something like this:
CONCATENATE
the whole JS code goes here
into mensaje.
I do not know how to render the page, so that the message is displayed.
Does somebody have an example ?? what should I do ??
Thanks
P.S. - I cannot publish the code. This damned site cancels the navigation and and get a white page with error message.hey jorge,
did you try something like
response->set_cdata( DATA = 'your script' ).
regards from PMD
stefan
Maybe you are looking for
-
How can you send an email out to more than 65 persons at a time?
I have an email notification list of 175 persons who regularly get communications from me. I have recently discovered that only 65 of them are getting these emails. How can I send to my entire list? Thanks!
-
Problem while invoking a web service within an XML native database
Within the eXist dbms, I'm writing a module which implements several extensions to XPath. These extensions must invoke a remote web-service. I initially tested a standalone consumer, and everythink worked out successfully. Thus I created a jar, I use
-
Printing to HP Laserjet 2100 via Time Capsule very very slow
If I connect the above printer directly to my Macbook (OS 10.5.2) it prints fine, at reasonable speed and quality. Connected via the Time Capsule a half-page text document takes about 4-5 minutes to print. I have updated the printer driver from this
-
Transfer line items in Profit Center
I have posted some Vendor Invoices to a wrong profit center and Business Area. Please explain how to tranfer the documents to a different Profit Center and Business Area without reversal on SAP 4.7. Thanks
-
Firefox will not download to my iPad. Why?
It's say that safari can not download