Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package bounds;
- import java.util.Scanner;
- public class bounds {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- System.out.println("Enter a starting number.");
- int starting_num = scan.nextInt();
- System.out.println("Enter an upper bound.");
- int upper_bound = scan.nextInt();
- System.out.println("Enter a step size.");
- int step_size = scan.nextInt();
- int count=0;
- System.out.println(starting_num);
- int num = starting_num;
- while(num<=upper_bound) {
- num += step_size;
- System.out.println(num);
- count += 3;
- if(count%10==0) {
- System.out.println("\n");
- }
- }
- }
- }
- package temperature;
- import java.util.Scanner;
- public class temperature {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- boolean calc=true;
- double total_f_temp = 0;
- double total_c_temp = 0;
- double user_inputs = 0;
- while(calc==true) {
- System.out.println("Enter a temperature in Centigrade or <=-100 to quit: ");
- double centigrade_temp = scan.nextDouble();
- if(centigrade_temp<=(-100.0)) {
- break;
- }
- else {
- user_inputs += 1;
- double fahrenheit_temp = (9.0/5.0)*centigrade_temp + 32.0;
- System.out.println("Temperature: F(" + fahrenheit_temp+") C(" + centigrade_temp + ")");
- total_f_temp += fahrenheit_temp;
- total_c_temp += centigrade_temp;
- }
- }
- double average_c_temp = (total_c_temp)/(user_inputs);
- double average_f_temp = (total_f_temp)/(user_inputs);
- System.out.println("Average: Centigrade("+average_c_temp+") Fahrenheit("+average_f_temp+")");
- }
- }
- package alphabet;
- import java.util.Scanner;
- public class alphabet {
- public static void main(String[] args) {
- char letter = 'a';
- while(letter<='z') {
- System.out.println(letter);
- switch(letter) {
- case 'a':
- System.out.println(" is a vowel");
- break;
- case 'e':
- System.out.println(" is a vowel");
- break;
- case 'i':
- System.out.println(" is a vowel");
- break;
- case 'o':
- System.out.println(" is a vowel");
- break;
- case 'u':
- System.out.println(" is a vowel");
- break;
- case 'y':
- System.out.println(" is a vowel");
- break;
- default:
- System.out.println(" is a consonant");
- break;
- }
- letter += 1;
- }
- }
- }
- package factorial;
- import java.util.Scanner;
- public class factorial {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- System.out.println("Would you like to compute a factorial (y/n)?");
- char selection = scan.next().charAt(0);
- boolean choice = false;
- if(selection == 'y') {
- choice = true;
- }
- while(choice == true) {
- //calculate factorial
- System.out.println("Enter a number N: ");
- int n = scan.nextInt();
- int factorial = n;
- int subtract_n = 0;
- int num = n;
- while(num>1) {
- subtract_n += 1;
- factorial *= (n-subtract_n);
- System.out.println(factorial);
- num -= 1;
- }
- System.out.println("Factorial: "+factorial);
- System.out.println("Would you like to continue (y/n?)");
- char selection2 = scan.next().charAt(0);
- if(selection2=='n') {
- choice = false;
- }
- else {
- choice = true;
- }
- }
- System.out.println("Have a nice day.");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement