Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

How to say "and" in java

  • 30-09-2009 11:15pm
    #1
    Registered Users, Registered Users 2 Posts: 142 ✭✭


    May seem like a stupid question but how do you say "and" in java?

    This may help ye get a better understanding of what im trying to do,

    format = digit1 and digit2 and digit3;


Comments

  • Registered Users, Registered Users 2 Posts: 18,272 ✭✭✭✭Atomic Pineapple


    are you adding up the digits?


  • Registered Users, Registered Users 2 Posts: 981 ✭✭✭fasty


    Logical and? Bitwise and? former is &&, the latter is &.

    Just Google this stuff, man! :D

    http://en.wikipedia.org/wiki/Java_syntax#Bitwise_operations


  • Registered Users, Registered Users 2 Posts: 142 ✭✭coffey-16


    no im not, i just want the word format to equal the 3 different digits, for example: format= 1 and 2 and 3, therefore format=123

    fasty, iv tried both and neither work for in this instance! Thanks for the advice though.


  • Registered Users, Registered Users 2 Posts: 18,272 ✭✭✭✭Atomic Pineapple


    coffey-16 wrote: »
    no im not, i just want the word format to equal the 3 different digits, for example: format= 1 and 2 and 3, therefore format=123

    I might be getting a bit confused as to what your asking but I think you would have to have format as a String and if your taking the digits in as ints or doubles you will have to cast them to String and then use this.

    format = digit1 + digit2 + digit3;

    so System.out.println("format = " + format);

    would give you format = 123

    *Disclaimer: I'm wrecked so I could be misreading what you actually want ;)


  • Registered Users, Registered Users 2 Posts: 1,355 ✭✭✭dyl10


    Are you trying to take all 3 digits in one input?


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 142 ✭✭coffey-16


    no im trying to take them as 3 seperate inputs.
    I can post the rest of the code if ye think it would make it more clear as to what I am asking:)


  • Registered Users, Registered Users 2 Posts: 18,272 ✭✭✭✭Atomic Pineapple


    coffey-16 wrote: »
    no im trying to take them as 3 seperate inputs.
    I can post the rest of the code if ye think it would make it more clear as to what I am asking:)

    yes please do, dont forget to use the code tags


  • Registered Users, Registered Users 2 Posts: 142 ✭✭coffey-16


    package displaydate;
    
    import java.util.Scanner;
    
    public class DisplayDate {
    
        public static void main( String args[] ) {
    
            Scanner input = new Scanner(System.in);
    
            int number1;
            int number2;
            int number3;
            int format;
    
            System.out.print("Enter the day:");
            number1 = input.nextInt();
    
            System.out.print ("Enter the month:");
            number2 = input.nextInt();
    
            System.out.print ("Enter the year:");
            number3 = input.nextInt();
    
           format = number1 & number2 & number3;
    
            System.out.printf("The date entered was the %02d/", format );
    


  • Registered Users, Registered Users 2 Posts: 8,584 ✭✭✭TouchingVirus


    printf can take more than 1 argument.

    System.out.printf("The date entered was %d, %d, %d", number1, number2, number3);?


    This isn't an "and" by the way :)


  • Registered Users, Registered Users 2 Posts: 18,272 ✭✭✭✭Atomic Pineapple


    since your not doing any equation with the date just take them in as strings instead, have format as a string too and then do what I said above

    ie: format = number1 + number2 + number3;

    If you were doing an equation with the numbers you could take them in as ints but then cast them to a string so you can concatenate them.

    If you haves ints the + will simply add up the numbers and give a total


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 36 THEDUDEINWHITE


    By any chance would this code be for a computer software project?


  • Registered Users, Registered Users 2 Posts: 34 Mikia


    first thing i thought of was logical and: &&

    but I guess your question has already been answered :)


Advertisement