Tuesday, September 28, 2010

IsSorted

1. int totalnumbers = number.length -1
2. int output = 0
3. while (totalnumbers >0)
  if number[n] <= number[n+1] then output = 1
  totalnumbers++
4. if (output = 1)
   print "Yes, it is Sorted"
  else print "No, it is not sorted"

Thursday, September 16, 2010

Find the Number

import java.util.Scanner;

public class FindTheNumber
{
    public static void main (String[] args)
    {
    Scanner scan = new Scanner(System.in);
    System.out.println ("Enter 5 numbers");
    int num1 = scan.nextInt();
    int num2 = scan.nextInt();
    int num3 = scan.nextInt();
    int num4 = scan.nextInt();
    int num5 = scan.nextInt();

    int out=0;
    System.out.println ("Please enter the number you would like to check for: ");
    int num = scan.nextInt();
    if (num==num1)
        out= 1;
    if (num==num2)
        out= 1;
    if (num==num3)
        out= 1;
    if (num==num4)
        out= 1;
    if (num==num5)
        out= 1;
    if (out==1)
        System.out.println ("Yes, the number is here");
    else
        System.out.println ("No, the number is not here");


    }
}

The answer will output "yes" if the number is in the list. The answer will output "no" if it is not. The program will end no matter when it runs through once.

Wednesday, September 15, 2010

SortMax

1. Assign an int max to be the value of the first number.
2. Compare max to the next number
3. If max is smaller than the number, let max equal the value of the number
4. Repeat step 2 and 3 until every number has been checked
5. print max value
6. terminate

The program will end once every number has been checked. It is finite.
The program will work for any set of numbers because it continues until all numbers have been checked.