Docstoc

J03Prj_Listing

Document Sample
J03Prj_Listing Powered By Docstoc
					import java.util.*;

public class Class01 {
  public static void main(String[] args) {
    int count;
    int i = 1;             // loop variable
    System.out.print("How many greetings? : ");
    count = Sys.readInt();
    do {
      i++;                 // same as i = i+1;
      System.out.println(i+" Hello -- Do");
    } while (i <= count);
  }
}




import java.util.*;

public class Class02 {
  public static void main(String[] args) {
    int count;
    int i = 0;             // loop variable
    System.out.print("How many greetings? : ");
    count = Sys.readInt();
    do {
      i++;                 // same as i = i+1;
      System.out.println(i+" Hello -- Do");
    } while (i < count);
  }
}




import java.util.*;

public class Class03 {
  public static void main(String[] args) {
    int count;
    int i = 1;             // loop variable
    System.out.print("How many greetings? : ");
    count = Sys.readInt();
    while (i <= count) {
      System.out.println(i+" Hello -- While");
      i++;                 // same as i = i+1;
    }
  }
}
import java.util.*;

public class Class04 {
  public static void main(String[] args) {
    int count;
    int i = 0;             // loop variable
    System.out.print("How many greetings? : ");
    count = Sys.readInt();
    while (i < count) {
      i++;                 // same as i = i+1;
      System.out.println(i+" Hello -- While");
    }
  }
}




import java.util.*;

public class Class05 {
  public static void main(String[] args) {
    int i;       // loop variable
    int count;
    System.out.print("How many greetings? : ");
    count = Sys.readInt();
    while (i = 1; i <= count; i++)
      System.out.println(i+" Hello -- For");
  }
}




import java.util.*;

public class Class06 {
  public static void main(String[] args) {
    int i;
    System.out.println("Square roots table");
    while (i = 0; i < 20; i++ )
      System.out.println(i+ " "+ Math.sqrt(i));
  }
}
import java.util.*;

public class Class07 {
  public static void main(String[] args) {
    int i;
    System.out.println("Square roots table");
    while (i = 0; i < 20; i++ ) {
      if (i < 10) System.out.print(" ");      // indentation
      System.out.println(i + " " + Math.sqrt(i));
    }
  }
}




import java.util.*;

public class Class08 {
  public static void main(String[] args) {
    int sum = 0;
    int item;
    System.out.println("Enter bill items one by one, stop with zero:");
    do {
      System.out.print("--> "); item = Sys.readDouble();
      sum += item;
    } while (item != 0.0);
    System.out.println("------------------------");
    System.out.println("    " + sum);

        // add the items numeraton (1.,   2., etc ) as an exercise
    }
}




import java.util.*;

public class Class09 {
  public static void main(String[] args) {
    int int1, int2;
    System.out.println("I find the gratest common divisor");
    System.out.print("Enter two integers: ");
    int1 = Sys.readInt(); int2 = Sys.readInt();
    while (int1 != int2)
      if (int1 < int2)
        int2 = int2-int1;     // int2 -= int1; is also possible
      else
        int1 = int1-int2;
    System.out.println("NSD = "+int1);

        // add the output of int1 and int2 in each loop
    }
}
import java.util.*;

public class Class10 {
  public static void main(String[] args) {
    int number;
    int sum =0;
    System.out.println("Sum of digits of the given number");
    System.out.print("number: "); number = Sys.readInt();
    while (number != 0) {
      sum += (number % 10);
      number /= 10;         // same as  number = number/10;
    }
    System.out.println("Soucet: " + sum);
  }
}




import java.util.*;

public class Class11 {
  public static void main(String[] args) {
    int secret = (int) (Math.random()*100);
    System.out.println("Guess the whole number betwen 0 and 99");
    int guess;
    do {
      System.out.print("Guess: ");
      guess = Sys.readInt();
      if (guess == secret)
         System.out.println("Bravo!");
      else
         if (guess < secret)
           System.out.println("Too small");
         else
           System.out.println("Too big");
    } while (guess != secret);
  }
}
import java.util.*;

public class Class12 {
  public static void main(String[] args) {
    // the program is the same as the previous one,
    // only it also counts the guesses
    int secret = (int) (Math.random()*100);
    int guess;
    int count = 1;
    System.out.println("Guess the whole number betwen 0 and 99");
    do {
      System.out.print(count+". Guess: ");
      guess = Sys.readInt();
      if (guess == secret)
         System.out.println("Bravo!");
      else
         if (guess < secret)
           System.out.println("Too small");
         else
           System.out.println("Too big");
       count++;
    } while (guess != secret);
  }
}




import java.util.*;

public class Class13 {
  public static void main(String[] args) {
    System.out.println("Multiplication table");
    while (int i = 1; i < 8; i++) {        // i is a row index
      while (int j = 1; j < 10; j++)       // j is a column index
        System.out.print(i*j+" ");
      System.out.println();                         // new line
    }
  }
}
import java.util.*;

public class Class14 {
  public static void main(String[] args) {
    // the program is the same as the previous one,
    // only the output is more neat
    int product;
    System.out.println("Multiplication table");
    while (int i = 1; i < 8; i++) {      // i is a row index
       while (int j = 1; j < 10; j++) { // j is a column index
         product = i * j;
         if (product < 10)             // add a space before a 1digit
number
           System.out.print(" ");
         System.out.print(i * j + " ");
       }
       System.out.println();                      // new line
    }
  }
}


import java.util.*;

public class Class15 {
  public static void main(String[] args) {
     int max = Integer.MIN_VALUE;
     int input;
     System.out.println("Find a maximum of the sequence");
     System.out.println("Enter integers, stop with 0.");
     do {
       System.out.print("--> "); input = Sys.readInt();
       if (input > max)
          max = input;
     } while (input != 0);
    System.out.println("Maximum: "+max);
  }
}


import java.util.*;

public class Class16 {
  public static void main(String[] args) {
     boolean allPositive = true;
     int vstup;
     System.out.println("Are all entries positive?");
     System.out.println("Enter integers, stop with 0.");
     do {
       System.out.print("--> "); vstup = Sys.readInt();
       if (vstup < 0)
          allPositive = false;
     } while (vstup != 0);
    System.out.println("All entries positive: " + allPositive);
  }
}

				
DOCUMENT INFO
Shared By:
Categories:
Tags:
Stats:
views:4
posted:12/8/2012
language:Unknown
pages:6