vendredi 1 mai 2015

Java If Statement issue [duplicate]

This question already has an answer here:

I have this code in Java to give some information about either a circle, a triangle or a quadrilateral. I have specified an if statement, which I'm going to add more information to.

I don't know whether an if statement is the right way to let the user choose if he wants to have information about a circle, triangle or rectangle. Because I actually wanted to have some kind of buttons each for the circle, triangle and rectangle. So if you have any tips on that I would really appreciate it.

This is the code I'm having trouble with, everytime I type in 'cirkel' which I have mentioned in the if statement, it goes on to the else statement and I get a dialog saying 'bye'.

import java.util.*;
import javax.swing.JOptionPane;

public class Vormen {

    public static void main(String[] args){
        String vorm;
        double diameter;
        double r;
        double omtrek;
        double oppervlakte;

        Scanner keyboard = new Scanner(System.in);
        vorm = JOptionPane.showInputDialog("Kiest u voor de 'cirkel', 'driehoek' of 'vierhoek'?");

        if (vorm == "cirkel"){
            diameter = diameter = Double.parseDouble(JOptionPane.showInputDialog("Wat is de diameter van de cirkel (in m)"));
            r = diameter / 2;
            omtrek = 2 * Math.PI * r;
            oppervlakte = Math.PI * r * r;
            JOptionPane.showMessageDialog(null, "De straal = " + r + " m\n\n" + "De omtrek = " + omtrek + " m\n\n" + "De oppervlakte = " + oppervlakte + " m^2");
        }

        else {
            JOptionPane.showMessageDialog(null, "bye");
        }

    }

}

Thanks in advance!

tcl non curly braces expression slower than with them?

I have noticed something. Let's look at two codes bit. in 1, if is not input with a curly brace input, the other is. The curly braced 1 is slightly faster. Why?
See codes and outputs below:

puts [ time { if { [ expr { 5 % 2 } ] } { puts 1 } else { puts 2 } } ]
1
52 microseconds per iteration
puts [ time { if [ expr { 5 % 2 } ] { puts 1 } else { puts 2 } } ]
1
54 microseconds per iteration

The differences are stable. 2 microseconds faster when using more code characters.
Why?

Python: i'm having an issue with my if else statement

My if and else statement works but when i press the button i created for it, i get no results from it and i am not sure if its the cmds.setKeyframe i have set up within the statement thats causing the issue.

class Shells(object):  
def __init__(self): #initializing the class ShellsUI
    self.Shells = [] #empty list
    self.currentX = 0 # this is where the ball is placed
    self.space = 4 # spacing of the cups

def createUI(self):
    #Test to see if the window exists
    if cmds.window('ShellsWin', exists=True):
        #delete the window
       cmds.deleteUI('ShellsWin')
    #create a new window
    cmds.window('ShellsWin', title='Shells Game UI')
    cmds.columnLayout()
    cmds.rowColumnLayout( numberOfColumns=2, columnAttach=(3, 'right', 0), columnWidth=[(1, 100), (2, 250)] )
    #    Attach commands to pass focus to the next field if the Enter
    #    key is pressed. Hitting just the Return key will keep focus
    #    in the current field.
    cmds.button( label='start Game',command=partial (self.startGame) ) #not sure if i need a start game button you will see later on if its needed or not.
    cmds.rowColumnLayout( numberOfColumns=1, columnAttach=(3, 'right', 0), columnWidth=[(1, 100), (2, 250)] )
    cmds.text(label='choose cup', align='center')
    cmds.button(label='cup1',command=partial(self.chooseCup))
    cmds.button(label='cup2',command=partial(self.chooseCup))
    cmds.button(label='cup3',command=partial(self.chooseCup))
    cmds.showWindow()

    cmds.file(new=True,force=True)              
    getObj = cmds.file("F:/python/cupz.obj",i=True,type="OBJ",groupName=True)

def startGame(self,args=None): #animate objects with the start of the button             

    cmds.play( forward=True )

    cmds.setKeyframe("cup_1.tx",t=0,v=0)
    cmds.setKeyframe("cup_1.tz",t=0,v=0)
    #
    cmds.setKeyframe("cup_1.tx",t=100,v=0)
    cmds.setKeyframe("cup_1.tz",t=100,v=0)

    cmds.setKeyframe("cup_2.tx",t=0,v=0)
    cmds.setKeyframe("cup_2.tz",t=0,v=0)
    #
    cmds.setKeyframe("cup_2.tx",t=100,v=0)
    cmds.setKeyframe("cup_2.tz",t=100,v=0)

    cmds.setKeyframe("cup_3.tx",t=0,v=0)
    cmds.setKeyframe("cup_3.tz",t=0,v=0)
    #
    cmds.setKeyframe("cup_3.tx",t=100,v=0)
    cmds.setKeyframe("cup_3.tz",t=100,v=0)



    for x in range (0,100):
        cmds.setKeyframe('cup_1.tx',t=x,v=m.sin(x)*15)
        cmds.setKeyframe('cup_1.tz',t=x,v=m.cos(x)*13)

    for x in range (1,100):
        cmds.setKeyframe('cup_2.tx',t=x,v=m.cos(x)*18)
        cmds.setKeyframe('cup_2.tz',t=x,v=m.sin(x)*12)

    for x in range (1,100):
        cmds.setKeyframe('cup_3.tx',t=x,v=m.sin(x)*15)
        cmds.setKeyframe('cup_3.tz',t=x,v=m.cos(x)*13)        





def chooseCup(self,cup):
    chooseCup = "cup"
    if cup == ('cup_1'):
        cmds.setKeyframe("cup_1.ty",t=0,v=0)
        cmds.setKeyframe("cup_1.tx",t=0,v=0)

        cmds.setKeyframe("cup_1.ty",t=24,v=5)
        cmds.setKeyframe("cup_1.rx",t=24,v=-25)
    elif chooseCup: None

    if cup == ('cup_2'):
        cmds.setKeyframe("cup_2.ty",t=0,v=0)
        cmds.setKeyframe("cup_2.tx",t=0,v=0)

        cmds.setKeyframe("cup_2.ty",t=24,v=5)
        cmds.setKeyframe("cup_2.rx",t=24,v=-25)
    elif chooseCup: None

    if cup == ('cup_3'):
        cmds.setKeyframe("cup_3.ty",t=0,v=0)
        cmds.setKeyframe("cup_3.tx",t=0,v=0)

        cmds.setKeyframe("cup_3.ty",t=24,v=5)
        cmds.setKeyframe("cup_3.rx",t=24,v=-25)
    elif chooseCup: None
    else :
         print "out of range" 


def hiddenBall(self,ball):
    self.ball = cmds.polySphere()[0]
    cmds.setKeyframe("ball",t=100,v=r.randiant)

inst = Shells() #creating an instance of a class
inst.createUI()

How do I sum results of two if statements in the same cell?

I'm looking to have the results of two If statements calculated and added in the same cell. I'm getting #VALUE! error.

=SUM(IF(ISERROR(GETPIVOTDATA("Sum of CHARGES",'Ship City'!$A$3, "ship_city",$B$7,"carrier_type",$A$27, "INV_month_id",D$6,"INV_year_id",$D$5,"Company Name",$B29)),"",GETPIVOTDATA("Sum of CHARGES",'Ship City'!$A$3, "ship_city",$B$7,"carrier_type",$A$27, "INV_month_id",D$6,"INV_year_id",$D$5,"Company Name",$B29))+IF(ISERROR(GETPIVOTDATA("Sum of CHARGES",'Recipient City'!$A$4, "recipient_city",$B$7,"carrier_type",$A$27, "INV_month_id",D$6,"INV_year_id",$D$5,"Company Name",$B29)),"",GETPIVOTDATA("Sum of CHARGES",'Recipient City'!$A$4, "recipient_city",$B$7,"carrier_type",$A$27, "INV_month_id",D$6,"INV_year_id",$D$5,"Company Name",$B29)))

Same row different column. Excel Formula

If is possible with the if(indirect formula to give me the value from the same row but from a different column if a specific cell is from that row?

More specific: I want cell =Sheet2!F23 to give me =Sheet1!N11 if =sheet2!C23 is from Sheet1!B11. The important thing is the I need it to come from row 11 but from a different column.

Thanks in advance.

execute if statement in variable value assignement powershell

Sometimes I need to check if a pathname ends with "\" adding it if necessary, the code is pretty simple, something like this

if ($destFolder[-1] -ne '\') {
    $destFolder += '\';
}

Is there a way to evaluate an if statement inside () so that I can use it in variable assignement? I mean something like this

$finalName = $destFolder + (if ($destFolder[-1] -ne '\') { '\' } ) + $fileName

Given that if is not a cmdlet I get this error

if : The term 'if' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

If else error I don't understand this error

I don't understand this error is it logical error or something else here is the coding " this program should convert riyal to currency that is chosen by the user using multiway if-else

import java.util.Scanner;

public class Convert
{
    public static void main (String[] args)
    {
        Scanner kb= new Scanner (System.in);

        double riyal, c;
        int opp;

        System.out.println("Please enter the amount of money in Riyal: ");
        riyal= kb.nextDouble();

        System.out.println("Enter the currency option(1- Dollar, 2- Euro, 3- Yen): ");
        opp= kb.nextInt();

        if(opp==1)

            c=riyal*0.267;
        System.out.print(riyal+" Riyals is converted to "+c" Dollars");

        else if (opp==2)

            c=riyal*0.197;  
            System.out.print(riyal+" Riyals is converted to "+c" Euros");

         else if (opp==3)

            c=riyal*0.27.950;
          System.out.print(riyal+" Riyals is converted to "+c" Yens");

         else
         {
            System.out.println("Invalied opption");
        }
    }
}


error massage 
error: illegal start of expression
error: 'else' without 'if'
error: ';' expected
error: ')' expected