Jump to content

how can i display out yhe largest number out ?

- - - - -

  • Please log in to reply
12 replies to this topic

#1
xxxxjayxxx

xxxxjayxxx

    Programmer

  • Members
  • PipPipPipPip
  • 123 posts
For example the ans I get are all from a range of 0.0 to 0.5 .. how can display out the largest number out ?

#2
nicckk

nicckk

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 629 posts
The Math.max() method.

#3
xxxxjayxxx

xxxxjayxxx

    Programmer

  • Members
  • PipPipPipPip
  • 123 posts
Ya but Math.max method is for those who know yr int numbers. But mine reading from a file and pick the largest number out . The number generated will be random in the file. So yea, I can't use Math.max method.

#4
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Java
Pseudo

int max;


while( file.hasMoreNumbers() ){

    int currentNumber = file.nextNumber();


    if(max < currentNumber){

         max = currentNumber;

    }

}


Print: "Max number: " + max;



#5
xxxxjayxxx

xxxxjayxxx

    Programmer

  • Members
  • PipPipPipPip
  • 123 posts
.hasMoreNumbers()

:confused:

#6
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Java
Well, loop as long the file has more numbers to read...

#7
xxxxjayxxx

xxxxjayxxx

    Programmer

  • Members
  • PipPipPipPip
  • 123 posts
sorry but I cant seem to find
.hasMoreNumbers()



#8
Sinipull

Sinipull

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 386 posts
It's pseudo, you won't find it.
You have to open the file and read the numbers.

#9
xxxxjayxxx

xxxxjayxxx

    Programmer

  • Members
  • PipPipPipPip
  • 123 posts
sound complicated ... hmmm :sleep:

#10
xxxxjayxxx

xxxxjayxxx

    Programmer

  • Members
  • PipPipPipPip
  • 123 posts
public int[] bubbleSort(int[] arr) {

      boolean swapped = true;

      int j = 0;

      int tmp;

      while (swapped) {

            swapped = false;

            j++;

            for (int i = 0; i < arr.length - j; i++) {

                  if (arr[i] > arr[i + 1]) {

                        tmp = arr[i];

                        arr[i] = arr[i + 1];

                        arr[i + 1] = tmp;

                        swapped = true;

                  }

            }

      }

      return arr;

     }
can bubble sort be used also ?

#11
lethalwire

lethalwire

    while(false){ ... }

  • Members
  • PipPipPipPipPipPipPip
  • 748 posts
  • Programming Language:Java, PHP
  • Learning:Java, PHP
Yes, assuming you've successfully gathered your data and stored it into arr.
Depending on how much data you have, you might reconsider using bubble sort.

#12
xxxxjayxxx

xxxxjayxxx

    Programmer

  • Members
  • PipPipPipPip
  • 123 posts
oh ok ...
I had found this code something in google:
Here's the code :
{

        Scanner input=new Scanner(System.in);

        System.out.println("Enter positive real numbers: ");

        Integer array[]=new Integer[10];

        for(int i=0;i<array.length;i++){

            array[i]=input.nextInt();

        }

        System.out.println("Sorted Array in reverse order:");

        Arrays.sort(array,Collections.reverseOrder());

        for(int i=0;i<array.length;i++){

            System.out.println(array[i]);

        }


    }
As you can see the code requires the user to type in the number ..
How can i convert :
for (int j = 0; j < bitSet2.length() - 1 || j < result1.length() - 1; j++) {


                    if (bitSet2.get(j)) {

                        writer.append("1");

                        writer.append(",");

                        writer.flush();

                    } else {

                        writer.append("0");

                        writer.append(",");

                        writer.flush();

                    }


                }


                

                nlast = (nlast / (ntarget + nresult - nlast));

                float round = Round(nlast, 3);


                writer.append(round);

                writer.append("\n");


                

            }
As this code, the number(round) would be printed out into the file. How can this code to be modify so that it will be similar to the above ?




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users