SHARE
TWEET

lmurrell_mp2

a guest Jun 16th, 2019 50 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package bounds;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class bounds {
  6.  
  7.     public static void main(String[] args) {
  8.        
  9.         Scanner scan = new Scanner(System.in);
  10.         System.out.println("Enter a starting number.");
  11.         int starting_num = scan.nextInt();
  12.         System.out.println("Enter an upper bound.");
  13.         int upper_bound = scan.nextInt();
  14.         System.out.println("Enter a step size.");
  15.         int step_size = scan.nextInt();
  16.        
  17.         int count=0;
  18.         System.out.println(starting_num);
  19.         int num = starting_num;
  20.         while(num<=upper_bound) {
  21.             num += step_size;
  22.             System.out.println(num);
  23.             count += 3;
  24.             if(count%10==0) {
  25.                 System.out.println("\n");
  26.             }
  27.         }
  28.  
  29.     }
  30.  
  31. }
  32. package temperature;
  33.  
  34. import java.util.Scanner;
  35.  
  36. public class temperature {
  37.  
  38.     public static void main(String[] args) {
  39.        
  40.         Scanner scan = new Scanner(System.in);
  41.         boolean calc=true;
  42.         double total_f_temp = 0;
  43.         double total_c_temp = 0;
  44.         double user_inputs = 0;
  45.         while(calc==true) {
  46.             System.out.println("Enter a temperature in Centigrade or <=-100 to quit: ");
  47.             double centigrade_temp = scan.nextDouble();
  48.             if(centigrade_temp<=(-100.0)) {
  49.                 break;
  50.             }
  51.             else {
  52.                 user_inputs += 1;
  53.                 double fahrenheit_temp = (9.0/5.0)*centigrade_temp + 32.0;
  54.                 System.out.println("Temperature: F(" + fahrenheit_temp+") C(" + centigrade_temp + ")");
  55.                 total_f_temp += fahrenheit_temp;
  56.                 total_c_temp += centigrade_temp;
  57.             }
  58.         }
  59.         double average_c_temp = (total_c_temp)/(user_inputs);
  60.         double average_f_temp = (total_f_temp)/(user_inputs);
  61.         System.out.println("Average: Centigrade("+average_c_temp+") Fahrenheit("+average_f_temp+")");
  62.        
  63.     }
  64.  
  65. }
  66. package alphabet;
  67.  
  68. import java.util.Scanner;
  69.  
  70. public class alphabet {
  71.  
  72.     public static void main(String[] args) {
  73.         char letter = 'a';
  74.         while(letter<='z') {
  75.             System.out.println(letter);
  76.             switch(letter) {
  77.             case 'a':
  78.                 System.out.println(" is a vowel");
  79.                 break;
  80.             case 'e':
  81.                 System.out.println(" is a vowel");
  82.                 break;
  83.             case 'i':
  84.                 System.out.println(" is a vowel");
  85.                 break;
  86.             case 'o':
  87.                 System.out.println(" is a vowel");
  88.                 break;
  89.             case 'u':
  90.                 System.out.println(" is a vowel");
  91.                 break;
  92.             case 'y':
  93.                 System.out.println(" is a vowel");
  94.                 break;
  95.             default:
  96.                 System.out.println(" is a consonant");
  97.                 break;
  98.             }
  99.             letter += 1;
  100.         }
  101.  
  102.     }
  103.  
  104. }
  105. package factorial;
  106.  
  107. import java.util.Scanner;
  108.  
  109. public class factorial {
  110.  
  111.     public static void main(String[] args) {
  112.        
  113.         Scanner scan = new Scanner(System.in);
  114.         System.out.println("Would you like to compute a factorial (y/n)?");
  115.         char selection = scan.next().charAt(0);
  116.         boolean choice = false;
  117.         if(selection == 'y') {
  118.             choice = true;
  119.         }
  120.         while(choice == true) {
  121.             //calculate factorial
  122.             System.out.println("Enter a number N: ");
  123.             int n = scan.nextInt();
  124.             int factorial = n;
  125.             int subtract_n = 0;
  126.             int num = n;
  127.             while(num>1) {
  128.                 subtract_n += 1;
  129.                 factorial *= (n-subtract_n);
  130.                 System.out.println(factorial);
  131.                 num -= 1;
  132.             }
  133.             System.out.println("Factorial: "+factorial);
  134.             System.out.println("Would you like to continue (y/n?)");
  135.             char selection2 = scan.next().charAt(0);
  136.             if(selection2=='n') {
  137.                 choice = false;
  138.             }
  139.             else {
  140.                 choice = true;
  141.             }
  142.         }
  143.         System.out.println("Have a nice day.");
  144.        
  145.     }
  146.  
  147. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top