Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

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 7 of 7

Threaded View

  1. #1
    Junior Member
    Join Date
    Nov 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Java program to find the minimum and maximum values of input data

    Hey i'm writing this code...and well.

    I'm very new to java ><...

    There are two things that I am trying to do,

    Basically, without using Arrays,

    - I want to write a program that asks the user how many integers that they want to input, then have the user input those variables and then have the program determine and display the minimum and maximum values of whatever the user inputs.
    This is what I have so far but it isn't working...

    // Import Scanner Class
    import java.util.Scanner;
    public class maxMinValues
    {
    // main method is the start point of java applications
    public static void main(String args[])
    {
    // variable to read user input
    Scanner input = new Scanner(System.in);
     
    //Title
    System.out.printf("\t\n Finding the largest & smallest Value ");
    System.out.printf("\t\n How many integers are ");
     
    //Variables
     
    int lowValue=0;
    int a=0;
    int b=0;
    int c=0;
    int d=0;
    int e=0;
     
    while ( a >= 0 )
    {
    System.out.printf("\n\n Enter Integer: ");
    a = input.nextInt();
     
    if ( a == -100 )
     
    {
    break;
    }
    } 
     
    if (a <= b && a <= c && a <= d && a <= e || a == b || a == c || a == d || a == e)
    lowValue = a;
    else if (b <= a && b <= c && b <= d && b <= e || a == b || b == c || b == d || b == e)
    lowValue = b;
    else if (c <= a && c <= b && c <= d && c <= e || c == a || c == b || c == d || c == e)
    lowValue = c;
    else if (d <= a && d <= b && d <= c && d <= e || d == a || d == b || d == c || d == e)
    lowValue = d;
    else if (e <= a && e <= b && e <= c && e <= d || e == a || e == b || e == c || e == d)
    lowValue = e;
    System.out.printf ("\n Min Value:%d", lowValue); 
    }
    int highValue=0;
    int a=0;
    int b=0;
    int c=0;
    int d=0;
    int e=0; 
    {
    if (a >= b && a >= c && a >= d && a >= e)
    highValue = a;
    else if (b >= a && b >= c && b >= d && b >= e)
    highValue = b;
    else if (c >= a && c >= b && c >= d && c >= e)
    highValue = c;
    else if (d >= a && d >= b && d >= c && d >= e)
    highValue = d;
    else if (e >= a && e >= b && e >= c && e >= d)
    highValue = e;
    System.out.printf ("\n Max Value:%d", highValue); 
     
     
    } // end main()
     
    } // end class

    Then...

    - program that converts temperatures from -5 to 15 C. by increments of 1 to Fahrenheit. Repeating it 3 times 1 with a for loop, 1 with while and 1 with do.

    // Import Scanner Class
    import java.util.Scanner;
    public class tempConvert
    {
    // main method is the start point of java applications
    public static void main(String args[])
    {
    // variable to read user input
    Scanner input = new Scanner(System.in);
     
    //Title
    System.out.printf("\t\n Celcius To Fahrenheit (-5 to 15) ");
     
    int getFahrenheit=0;
     
     
    for (int f= getFahrenheit(); f <= 212; f= getFahrenheit())
    System.out.println(f+"F = "+convertToC(f)+"C");
     
    System.out.println("Enter temperature in "); // prompt for input
    x = input.nextInt(); // read first integer in farenheit
     
    result = (5.0/9)*(x-32); 
    System.out.println("Fahrenheit Celsius", result);
     
    } //end method main
     
    } // end class

    - Im not sure how to input the other 2 loops aswell >< ugh.

    no idea what to do after this point. I'm using blueJ btw:


    if someone could help that would be wonderful.

    thanks. >.<
    Last edited by Deep_4; November 7th, 2012 at 01:03 PM.


Similar Threads

  1. GUI program won't take 'char' input code, can't seem to find the correct one...
    By Eclecstatic in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 1st, 2012, 07:12 AM
  2. when i run the program to find the y values it always prints y2 instead
    By jamesR in forum What's Wrong With My Code?
    Replies: 7
    Last Post: September 30th, 2012, 08:38 AM
  3. Replies: 2
    Last Post: June 15th, 2011, 03:49 PM
  4. Replies: 1
    Last Post: June 11th, 2011, 05:39 AM
  5. [ask]input data from java file to another java
    By bontet in forum File I/O & Other I/O Streams
    Replies: 6
    Last Post: October 29th, 2010, 10:50 AM