Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

How to say "and" in java

  • 01-10-2009 12:15AM
    #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,581 ✭✭✭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