Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: To print out the lowest and largest number from user input

  1. #1
    Junior Member
    Join Date
    Oct 2019
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default To print out the lowest and largest number from user input

    Hi,
    im a java programmer biginner,
    i have been trying to print out the lowest and largest number from user input of 5 digit. here is my code below. can anyone please assist

    import java.util.Scanner;

    public class LowestLargest{

    public static void main(String[] args){
    Scanner input = new Scanner(System.in);
    int number1;
    int number2;
    int number3;
    int number4;
    int number5;
    int result;
    int lowest;
    //int highest;

    System.out.println("Enter first integer");
    number1 = input.nextInt();

    System.out.println("Enter second integer");
    number2 = input.nextInt();

    System.out.println("Enter third integer");
    number3 = input.nextInt();

    System.out.println("Enter forth integer");
    number4 = input.nextInt();

    System.out.println("Enter fifth integer");
    number5 = input.nextInt();


    result = number1 & number2 & number3 & number4 & number5;
    lowest = number1 & number2 & number3 & number4 & number5;


    if(lowest < result){
    System.out.printf("lowest %d is lowest integer", result);
    }else{
    System.out.printf("highest = %d is highest integer", result);
    }


    }
    }
    Last edited by samuel355; October 17th, 2019 at 07:30 AM.

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: To print out the lowest and largest number from user input

    Can you explain what is wrong with the posted code? Copy the contents of the console from when you execute the program and paste it here.
    Add some comments describing where the output is wrong.

    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. How can I add a user input into a 2D- array and print it?
    By Fan Zhendong in forum What's Wrong With My Code?
    Replies: 16
    Last Post: March 29th, 2019, 02:54 PM
  2. Replies: 4
    Last Post: April 17th, 2014, 11:49 AM
  3. Print a letter of the alphabet based on a number that is input
    By justlearning in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 20th, 2013, 01:36 PM
  4. How to print the day of the week from user input?
    By f0x in forum Java Theory & Questions
    Replies: 2
    Last Post: October 31st, 2011, 05:33 PM
  5. Replies: 4
    Last Post: June 10th, 2009, 01:04 AM