Modulus Operation Question
The code below prints out
Answer 5 %3 = 2
Answer 8 %3 = 2
whether or not the inner if statment expression is (i % 3 == 0) or (i % 3 ==1). If the inner if statment expression is (i % 3 ==2 ) nothing prints out. Yet I would expect since 5 % 3 = 2 then the code should throw exception E2.
My question is why does this work the way it does?
public class TestMod {
public static void main(String[] args) {
for(int i =0; i < 10; ++i) {
try {
if(i % 3 == 0 ) {
throw new Exception("E1");
}else{
try{
if( i % 3 == 1 ) throw new Exception("E2");
System.out.println("Answer " + i + " %3 = " + (i%3));
}catch (Exception inner){
i *= 2;
}finally {
++i;
}catch (Exception outer){
i += 3;
}finally {
++i;
}//end for
The try and catch blocks are throwing me all around
that even in debug mode I am confused about how the
code (i % 3 ==0 ) is true when i = 5.I don't blame you for being confused, because your code is utterly confusing. But trust me, your code is not confusing enough to confuse the JVM, and (i % 3 = 0) is not true when i = 5.
Look, the first time through the loop i = 0. (0 % 3) == 0, so the "E1" exception is thrown. In the catch-block for that exception you add 3 to i, making it 3. Then the outer finally-block adds 1, making it 4.
The second time you enter the loop, 1 is added to i, making it 5. (5 % 3) is not 0 or 1, so no exception is thrown and you print out the "Answer..." line. Then the inner finally-block adds 1 to i, making it 6. Then the outer finally-block adds 1 to i, making it 7.
The third time you enter the loop, 1 is added to i, making it 8. As the previous time, (8 % 3) is not 0 or 1, so again you print out the "Answer..." line. Then the each of the two finally-blocks adds 1 to i, making it 10.
Since the loop condition (i < 10) is now false, the loop will break, and your program is done.
Similar Messages
-
How to achieve modulus operation in infopath 2013
Hi,
My difference field calculates difference between the start date of the Employee and today's date and the result is in number of days.
To convert it to months i divide the result by 30. But get a weird number when divident is in single digit.
Can we have a modulus kind of operation in Infopath ?
thank you.Hi, Victoria,
Many thanks for your response.
I tried to use the approach suggested by Teylyn in the blog, but it didn't work for me. I wanted to calculate the difference between the two dates and referred to this blog:
http://www.bizsupportonline.net/infopath2007/calculate-date-difference-infopath-rules-formulas.htm
I could get the difference in days, but i wanted to convert it in months so i thought i could divide it by 30 using modulus operation. I tried what was suggested in the blog on the difference field, but didn't work. The result was something like -0.234789065748E-1.
So i'm currently doing a round() operation of the [difference / 30] in Infopath form and with the help of rules, if the difference is >29 i divide the difference by 30 and take round figure and append months as suffix and if difference is < =29, the
difference is given as is and i suffix days ahead of that.
The above solution suggested by Teylyn may be correct in other cases. I couldn't test if it works for other scenarios. If it does, kindly mark it as answer. I will try to test it for other scenarios in the meantime.
Thanks again.
Best Regards,
Prajk -
Some ppl have helped with this. please give me the complete code for the modulus operator. It asks for an integer and tells the user if it is odd or even. please help. thanks
please give me the complete code for the modulus operator. Here ya go...
inline static void mod (_int& dst, const _int& src1, const _int& src2)
divides the the two _int's and stores the rest in dst (dst[i] = src1[i] % src2)
dst pointer to destination short-array
src1 pointer to source _int #1. src1 will modulate with src2 and ...
src2 pointer to source _int #2. ... the result will be stored in dst
as before, no error checking for the size of the _int's is made
int irhs ((int::bits) (src1.m_length * BS));
int ileft ((int::bits) (src1.m_length * BS));
dst.zero ();
irhs = src2;
ileft = src1;
bool src1neg = src1.negative ();
bool src2neg = src2.negative ();
if (src1neg) ileft.negate ();
if (src2neg) irhs.negate ();
unsigned long leftlen = bitlen (ileft);
unsigned long rhslen = bitlen (irhs);
while (leftlen > rhslen)
irhs <<= leftlen - rhslen - 1;
ileft -= irhs;
leftlen = bitlen (ileft);
if (src2neg)
irhs = -src2;
else
irhs = src2;
dst = ileft;
// if ((!src1neg && src2neg) ||
// (src1neg && !src2neg)) dst.negate (); -
Hi,
Could you answer the following questions
1.Can you give one eg for:how to use the mod
operator in SQL statements.
2.Can you give me the statements corresponding to the sqlserver
if exists (select * from sysobjects where id = object_id('dbo.AcctExec') and sysstat & 0xf = 3)
drop table dbo.AcctExec
nullYou use modulus function like this
SELECT MOD(11,4) "Modulus" FROM DUAL;
null -
Scenario - I have a web application that generates Excel documents that can be downloaded or opened directly. The web pages are a mixture of both ASP.NET and Classic ASP so the Excel file is actually generated as an HTML table. When a Save or Save As operation
is done when the .xls file is downloaded a specified file name passed from the web page is used in the save operation. When you open the Excel file after saving Excel displays "The file you are trying to open "filename.xls" is in a different
format than specified by the file extension...Do you want to open the file now?" informing me that the file is not a true xls file. When you continue with the opening the file it opens normally with no issues.
Question or Possible issue: Taking one of these files after it has been saved to a location on the computer outside of the download folder, and perform a Save As operation to change the format to a true .xls file the theExisting File Name is not displayed in
the File Name field. The Save as type defaults to Web Page which is understandable due to how the file is generated.
I've tried this with actual Excel spreadsheets and the File Name field on the Save As operation is populated with the current name of the file and keeps it even if you change the Save as type.
Main Question: Is there a setting somewhere in Excel to prevent the loss of the File Name?Hi,
According to your description, the "The file you are trying to open "filename.xls" alert is from a feature called Extension Hardening, and you can find more information about it here.
http://blogs.msdn.com/b/vsofficedeveloper/archive/2008/03/11/excel-2007-extension-warning.aspx
As you said and tested, Excel will retain the current file name in file name field when we save/save as the file. It's a default behavior. I suppose that the issue may be caused by the Excel that generated by web application.
I recommend we try the 3 workarounds:
1. Modify the ASP.NET program and make the file change to new excel format when generated
Please see the thread:
http://stackoverflow.com/questions/940045/how-to-suppress-the-file-corrupt-warning-at-excel-download
2. Use "Office Migration Planning Manager" to convert the XLS to XLSX format.
The toolkit also contains the Office File Converter (OFC), which enables bulk document conversions from binary to OpenXML formats.
Overview on Technet
Download Link
3. Use a macro to convert batch of XLS file to XLSX file and retain the file name.
Sample code:
Sub ProcessFiles()
Dim Filename, Pathname, saveFileName As String
Dim wb As Workbook
Pathname = "C:\Users\myfolder1\Desktop\myfolder\Macro\"
Filename = Dir(Pathname & "*.xls")
Do While Filename <> ""
Set wb = Workbooks.Open(Pathname & Filename)
saveFilename = Replace(Filename, ".xlsx", ".xls")
wb.SaveAs Filename:=Pathname & saveFilename, _
FileFormat:=xlExcel8, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False
wb.Close SaveChanges:=False
Filename = Dir()
Loop
End Sub
Regards,
George Zhao
TechNet Community Support
It's recommended to download and install
Configuration Analyzer Tool (OffCAT), which is developed by Microsoft Support teams. Once the tool is installed, you can run it at any time to scan for hundreds of known issues in Office
programs. -
Dear sir/madam
I having question for the shift operator.
What different between >>> and >> ?
I have refer to sun tutorial, it state >>> is unsign, what does it mean?
and last is
if integer is 13
what anwer for 13>>8
is it move for 8 right by position? pls told me in detail
is it answer same with the 13>>>8 ?
Thanks for ur solutionsYou can play with the following for a while.
final public class BinaryViewer{
final static char[] coeffs = new char[]{(char)0x30,(char)0x31};
public static String toBinary(int n) {
char[] binary = new char[32];
for(int j=0;j<binary.length;j++) binary[j]=(char)0x30;
int charPointer = binary.length -1;
if(n==0) return "0";
while (n!=0){
binary[charPointer--] = coeffs[n&1];
n >>>= 1;
return new String(binary);
public static void print(int n){
System.out.print(BinaryViewer.toBinary(n));
System.out.print(" ");
System.out.println(String.valueOf(n));
public static void main(String[] args) throws Exception{
int n=Integer.MIN_VALUE;//Integer.parseInt(args[0]);
int m=Integer.MAX_VALUE;//Integer.parseInt(args[1]);
BinaryViewer.print(n);
BinaryViewer.print(n>>8);
BinaryViewer.print(n>>>8);
System.out.println();
BinaryViewer.print(m);
BinaryViewer.print(m>>8);
BinaryViewer.print(m>>>8);
System.out.println();
n=1024;
m=-1024;
BinaryViewer.print(n);
BinaryViewer.print(n>>8);
BinaryViewer.print(n>>>8);
System.out.println();
BinaryViewer.print(m);
BinaryViewer.print(m>>8);
BinaryViewer.print(m>>>8);
System.out.println();
n=2048;
m=-2048;
BinaryViewer.print(n);
BinaryViewer.print(n>>8);
BinaryViewer.print(n>>>8);
System.out.println();
BinaryViewer.print(m);
BinaryViewer.print(m>>8);
BinaryViewer.print(m>>>8);
System.out.println();
} -
Hello all,
I asked a question yesterday under the title of "Range
Operator for first 2 letters of item" which was answered promptly and was much appreciated. I have since encountered another problem and would like another example if possible.
How would I search for all folders under C:\ that start with "Commercial_Global_Trading" through the end of all folders that start with "C"? Can I use a Range Operator for this as well?
Hopefully it makes sense what I'm asking!
Thanks!Yes it is a bit confusing. Maybe an answer from my previous post will help clear up what I'm asking:
Using range operators, we can get folders that start with A, B, and C by saying:
get-childitem 'C:\Folder\[a-c]*'
We can also get folders that start with Aa, Ab, and Ac by saying:
get-childitem 'C:\Folder\A[a-c]*'
What I'm wondering is, is there a way to get all folders in a range, beginning with a specific
word and then continue through the rest of the range? For example:
The folder C:\Folder contains the following 6 folders:
Account
Commercial
Commodity
Commodity_Product
Conduct
Finance
How would I use range operators in get-childitem to return the folders that start with Commodity, and then continue on through the rest of the C's? So the output would be the folders Commodity, Commodity_Product, and Conduct. The folder "Commercial" would
be excluded from the output. Is this possible using Range Operators and Get-ChildItem? -
Conditional operator question?
Hello,
Quick question, are we not allowed to use the conditional operator this way... see code below:
char volatile ProgString_[] = "\
{Fan code} \
12 <Limit11> [C1_ACM2]_[B1] _AND_ \
bla bla \
unsigned char UPC_SYSZ_EndOfTable(unsigned long i){ // Find the double '*' in string
char volatile *u;
u = &ProgString_[i];
if(!(strncmp("*", u, 1))){
i++;
u = &ProgString_[i];
if(!(strncmp("*", u, 1))){
return TRUE;
else {
return FALSE;
else
return FALSE;
void UPC_SYSZ_Parse(){
unsigned char volatile iOCntr = 0;
unsigned long volatile i;
for(i=0; i<200; i++){
(UPC_SYSZ_EndOfTable(i))?(break):(continue); //<<<<< Invalid expression ??
I would of used the following compact line:
(UPC_SYSZ_EndOfTable(i))?(break):(continue); //<<<<< Invalid expression ??
to periodically test the end of the string by fetching the "EndOfTable() function and evaluating if the double star is detected.
If detected, I would break out of the for loop, if not then I would continue.
Is it possible to do it this way?
thanks for all help!
rThink of it along the lines of each of the operands of the ternary operator must produce a value (which of course break and continue being statements cannot do).
Based on your brief example here is what I would do
for(i=0; i<200; i++){
if (UPC_SYSZ_EndOfTable(i)) break;
// doesn't make any sense to put more code down here anyway, so no real point to continue} -
CWMS 1.5 Operational Questions
Hello All:
I am looking for some help with my new CWMS 1.5 system. I have several problems listed below. If the features aren't in the current release, I am interested if they might be planned for an upcoming release.
1. How do you delete a user or a mis-typed email address?
2. How do you delete the branding logo? We uploaded a logo but can't find a way to set it back to default.
3. How do you restrict some people to WebEx with desktop sharing and others to just personal audio conference calls? Looking for some sort of class of service capability. Might want to also allow Mobile and other features by class as well.
4. How do you generate a report of the Userids, pins, and host/moderator numbers assigned?
5. How do you turn off email notifications? We want to load a large list of users but when we do it sends everyone an email. We are trying to stage the system and get ready for testing.
6. Is there a way to allow someone from our Service Desk to act as an operator on a call that would be able to mute a line? Looking for some sort of BigBrother capability. Should have full access to someones account and all active conference calls.
7. Is there a way to get a report of what numbers were dialed? Looking to determine number of internal versus external callers.
8. Why is public access required for IOS functionality? The IPAD or IPHONE can be on the company local network or connected with a VPN connection. We don't have IRP installed but IOS should still work.Hello David,
Let me answer some of your questions:
1. You cannot delete a user profile. If you mis-typed an e-mail address, all you can do is DEACTIVATE the profile. The behavior is the same as in WebEx SaaS.
2. At this time there is no supported way to delete the company logo using GUI. I am sure there is a way to remove it via CLI, but you would need TAC assistance for this.
3. At this time, it is not possible to differentiate privilege levels on per user bases. Any changes to capabilities is done on per system basis.
4. All the available reports are found in the Reports section. There is no such a report that you are looking for. Only available reports that come within Customize Your Report are:
UserLicenseUtilizationReportForThisMonth.csv
UserLicenseUtilizationReportForLastMonth.csv
SystemDowntimeReport.csv
NetworkBandwidthUtilizationReport.csv
MeetingReport.csv
FraudAttemptsReport.csv
5. At this time, if you are importing users via CSV file, only if you mark the user as INACTIVE during the import (in a csv file under column ACTIVE you mark N for the user profile) the system won't send an e-mail. Once you mark the user as ACTIVE, the system will e-mail the end user.
6. At this time, only host of the meeting can perform those actions within the WebEx Meeting Room.
7. There is no such a report in CWMS.
8. I cannot provide you an answer for this question as this is rooted in product design. Mobile devices require IRP server to be able to join meetings on CWMS.
I hope any of these answers will help.
-Dejan -
WLS 11g License File Operational Question
Hello,
I understand there is no license file anymore with WLS11g download, however of course you need a license for usage of WLS11 in production.
So I understand it is more a legal issue that you have to buy a license.
My question is, what do you get if you buy a license for WLS?
- A file that is technically not used?
- A letter stating you have bought a license that can be used for a particular CPU?
I wonder if you still get a file (which does not affect the functionality of WLS) do I have to take care to place in the right location for legal lissues?
I am thinking of operational guidelines in bigger/big environments.
- Is there a technical way to check/gurantee in large environmnet by talking to the WLS instances and retrieve the current licensing?
I guess no one wants to risk running unlicensed instances.
thanks for your input to this untypical question,
B.If you contact support, there has been discussions going on of making available some type of auditing software to cover the cases that you mention for organizations that want to monitor their compliance and deployments on their own. I'm not sure the status of that effort.
The license file is no longer even present in 11g at all. -
Hi All,
Quite simply I don't really understand two things.
1) How is the LIKE operator is working to return both columns.
2) When to use the LIKE operator and when to use the relation operator.
Thanks.
(CODE)
SELECT *
FROM ( SELECT TO_DATE ('01/01/2009 12:01:01', 'DD/MM/YYYY HH24:MI:SS') aa,
TO_DATE ('1-Jan-2009') bb FROM DUAL
WHERE aa LIKE bb
--returns both columns
SELECT *
FROM ( SELECT TO_DATE ('01/01/2009 12:01:01', 'DD/MM/YYYY HH24:MI:SS') aa,
TO_DATE ('1-Jan-2009') bb FROM DUAL
WHERE aa = bb
--returns nothing
(/CODE)Hi,
DaveyB wrote:
Hi All,
Quite simply I don't really understand two things.
1) How is the LIKE operator is working to return both columns.The WHERE clause (whether it contains LIKE or anything else) will only control the number of rows: every row will have the same numberr of columns.
2) When to use the LIKE operator and when to use the relation operator.Use LIKE when you want to use "wildcards" (% or _).
Use other operators (like =) when you don't have wildcards.
(CODE)
SELECT *
FROM ( SELECT TO_DATE ('01/01/2009 12:01:01', 'DD/MM/YYYY HH24:MI:SS') aa,
TO_DATE ('1-Jan-2009') bb FROM DUAL
WHERE aa LIKE bb
--returns both columns
SELECT *
FROM ( SELECT TO_DATE ('01/01/2009 12:01:01', 'DD/MM/YYYY HH24:MI:SS') aa,
TO_DATE ('1-Jan-2009') bb FROM DUAL
WHERE aa = bb
--returns nothing
(/CODE)It's great that you're trying to format your code! I wish everyione did that.
Use square brackets ([ and ]) if you want to use [CODE] and [/CODE] tags.
LIKE operates on strings. Don't use a DATE where a string is required. Do some experiments like the ones you tried just using strings, if you want to see how LIKE behaves. -
If a and b contain a number each, what should
if(a>0&&b6=0)be?= --> assignment operator
example:
a = 0;
a = a + 1
// a now equals 1; it doesn't solve the algebraic equation or anything
== --> comparison operator, returns boolean value
example:
if(a == 0)
// do something
Now you can correct it.
theAmerican -
Math Addition Operator Question
Hi there,
I'm trying to write a very simple math equation:
var gal_width = 100;
var m_box_pos = 2000;
var total = (gal_width+m_box_pos);
When I display this in a text element, the numbers are shown together rather than being added together
(eg: 1002000)
I get the feeling Edge is interpreting the + as a string operator rather than a math operator.
Replacing the + with a - (as a test), the 2 numbers are being subtracted.
Multiplying the numbers with the * operator also works as it should.
I've tried many configerations, escaping the operator with no luck.
Any ideas of how to get addition to work?
ThanksHi 29sketc.
console.log( sym.$("text_111").text());
// logs : 111
console.log(typeof sym.$("text_111").text());
// logs : string
var number_222 = 222;
console.log(typeof number_222);
// logs : number
console.log( sym.$("text_111").text() +number_222);
// logs : 111222
text() has produced a String so + is interpreted here as string concatenation.
var number_111 = 111;
console.log(typeof number_111);
// logs : number
console.log(number_111 +number_222);
// logs : 333
When you have two Number variables + is interpreted as addition.
Gil -
Post Increment Operator Question
I had written a small program to test the working of Post increment operator.
public static void main(String[] args)
int a = 4;
a = a++;
System.out.println ( a );
I expected the output to be '5', but the output given is '4'.
Can anyone tell me to how this works in Java ?There is a big difference between a++ and ++a.
a++ means increment a AFTER you have performed the line.
++a mean increment a BEFORE you perform the line.
class Test
public static void main(String[] args)
int a = 4;
a = ++a; //returns a = 5
// a = a++; //returns a = 4
//a++; //returns a = 5
//++a; //returns a = 5
System.out.println ( a );
} -
Ternary Operator Question (with regex).
Hi, I was learning regex in java and wrote a program which tests a string to see if it is an email address.
import javax.swing.*;
public class IsEmailAddress
public static void main(String[] args)
String address = JOptionPane.showInputDialog("Enter an email address");
if(address.matches("[a-zA-Z0-9\\.]+@\\w+\\.{1}\\w+"))
JOptionPane.showMessageDialog(null, "It is an email address");
else
JOptionPane.showMessageDialog(null, "It is not an email address");
}The above program works correctly. But then I decided to try and make the program only one line inside the main:
import javax.swing.*;
public class IsEmailAddress
public static void main(String[] args)
JOptionPane.showInputDialog("Enter an email address").matches("[a-zA-Z0-9\\.]+@\\w+\\.{1}\\w+") ? JOptionPane.showMessageDialog(null, "It is an email address") : JOptionPane.showMessageDialog(null, "It is not an email address");
}I get the compilation error not a statement, what am I doing wrong? Is this even possible?
Thanks for any helpI would never use a piece of code like that as part of a bigger program, I wanted to see if it was possible and maybe to learn something about the ternary operator.
Keeping in mind what you said about the ternary operator having to return something, I was able to make it work:
import javax.swing.*;
public class IsEmailAddress
public static void main(String[] args)
int a = JOptionPane.showInputDialog("Enter an email address").matches("[a-zA-Z0-9\\.]+@\\w+\\.{1}\\w+") ? JOptionPane.showOptionDialog(null, "It is an email address","Is it an email Adress?",JOptionPane.CANCEL_OPTION,JOptionPane.PLAIN_MESSAGE,null,null,null) : JOptionPane.showOptionDialog(null, "It is not an email address","Is it an email Adress?",JOptionPane.CANCEL_OPTION,JOptionPane.PLAIN_MESSAGE,null,null,null);
}I chose showOptionDialog because it returns a static int.
Thank you for your help!!!
Maybe you are looking for
-
I used to print greetings cards on windows easily. I still don't know how to do it well on my MacBook. Can anyone te me how to print a folded card on a MacBook Pro using an HP color printer? On windows, there are direction on where to fold the paper
-
How do i get my stuff back from icloud. only part loaded to my new phone
I backed up my Iphone4 before it was switched to a new one by the Apple Store. My new phone uploaded, but it appears not all of my pictures from Icloud loaded on my new phone. I did not go over my storage space. I believe the upload was interupted
-
I just installed OS X Yosemite on my MacBook. I now cannot get the computer to start up. If I hold down the power button to try and power it back up, it will not start. Any ideas on how to fix this?
-
Failed to parse eve: please help
failed to parse eve: /applications/adobe dreamweaver cc 2014.1/configuration/dialogs/eve/titanoptionaldialog.eve please help
-
Flash Builder failed to lunch after installation.
Adobe Flash Builder can't lunch after installation completed successfully. it says to uninstall and reinstall again. if problem continues, contact adobe support. and it says: "error: 5" ~ Then after I uninstalled it. Download it again and reinstall a