new semester, new repo structure
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package exam2_calebfontenot;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author ar114
|
||||
*/
|
||||
public class Problem1 {
|
||||
|
||||
/**
|
||||
* @param args the command line arguments
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
// Define variables
|
||||
double userInput = 0, average = 0;
|
||||
int timesRun = 0;
|
||||
|
||||
// Create scanner
|
||||
Scanner input = new Scanner(System.in);
|
||||
|
||||
System.out.println("I will calculate the average of numbers you will enter. \n");
|
||||
|
||||
// While loop to grab inputs and calculate
|
||||
while (userInput != -1) {
|
||||
System.out.print("Enter a positive number, or type -1 to quit: ");
|
||||
userInput = input.nextDouble();
|
||||
|
||||
if (userInput != -1) {
|
||||
// Calculate average
|
||||
average += userInput;
|
||||
// Increment timesRun
|
||||
timesRun++;
|
||||
}
|
||||
}
|
||||
average = average / (double) timesRun;
|
||||
System.out.println("The average is: " + average);
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,25 @@
|
||||
package exam2_calebfontenot;
|
||||
public class Problem2 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
int i = 1;
|
||||
do {
|
||||
int j = i;
|
||||
while (j > 1) {
|
||||
System.out.print(" ");
|
||||
j--;
|
||||
}
|
||||
j = 1;
|
||||
while (j <= 6 + 1 - i) {
|
||||
j++;
|
||||
if (i % 2 == 0) {
|
||||
continue;
|
||||
}
|
||||
System.out.print((j - 1) + " ");
|
||||
|
||||
}
|
||||
System.out.println();
|
||||
i++;
|
||||
} while ( i <= 6);
|
||||
}
|
||||
}
|
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package exam2_calebfontenot;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author ar114
|
||||
*/
|
||||
public class Problem3 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// Create scanner
|
||||
Scanner input = new Scanner(System.in);
|
||||
|
||||
// Define args
|
||||
int currentPrime = 0, timesToIterate = 0, timesIncremented = 0;
|
||||
|
||||
while (timesToIterate != -1) {
|
||||
System.out.print(" " + "===> -1 to quit or enter the number of primes you need generated and i will print 10 per line: ");
|
||||
|
||||
// Get amount of times the user wants us to iterate for.
|
||||
timesToIterate = input.nextInt();
|
||||
|
||||
// Don't do anything if the input is -1
|
||||
if (timesToIterate != -1) {
|
||||
// First loop. This determines how many times to iterate.
|
||||
for (int i = 0; i <= timesToIterate; i++) {
|
||||
currentPrime++;
|
||||
|
||||
// It's broken somewhere here, but I'm not sure where exactly...
|
||||
// Generate primes by incrementing currentPrime and attempting to divide by itself.
|
||||
for (int j = 1; j < timesIncremented; j++) {
|
||||
if (currentPrime % j == 0) {
|
||||
System.out.print(currentPrime + " ");
|
||||
}
|
||||
timesIncremented++;
|
||||
// If we've incremented 10 times, print a new line.
|
||||
if (timesIncremented % 10 == 0) {
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user