new semester, new repo structure
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package lab11_calebfontenot;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public class DoWhile1 {
|
||||
public static void main(String[] args) {
|
||||
int i = 0;
|
||||
do {
|
||||
System.out.println(i);
|
||||
i++;
|
||||
}
|
||||
while (i < 10);
|
||||
}
|
||||
}
|
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package lab11_calebfontenot;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public class DoWhile2 {
|
||||
public static void main(String[] args) {
|
||||
int i = 1;
|
||||
do {
|
||||
|
||||
System.out.print(i + ", ");
|
||||
|
||||
// if number is divisable by 10, delete the last two characters and print a new line.
|
||||
if (i % 10 == 0) {
|
||||
System.out.print("\b\b\n");
|
||||
}
|
||||
i++;
|
||||
|
||||
}
|
||||
while (i <= 100);
|
||||
}
|
||||
}
|
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package lab11_calebfontenot;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public class DoWhileEvent1 {
|
||||
public static void main(String[] args) {
|
||||
Scanner scan = new Scanner(System.in);
|
||||
int num = 0;
|
||||
int sum = 0;
|
||||
do {
|
||||
System.out.print("Please enter a positive number to add it to the sum or -1 to quit: ");
|
||||
num = scan.nextInt();
|
||||
sum = num != -1 ? sum + num : sum;
|
||||
} while (num != -1);
|
||||
System.out.println("Total : " + sum);
|
||||
}
|
||||
}
|
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package lab11_calebfontenot;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public class DoWhileEvent2 {
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Please enter a positive number to add it to sum or -1 to quit");
|
||||
Scanner scan = new Scanner(System.in);
|
||||
int num = scan.nextInt(); //2 Condition: initialize the condition of the loop
|
||||
int sum = 0; //1 task: Initialize the task
|
||||
do //1 condition: What is the condition?
|
||||
{
|
||||
sum += num; //2 task: task of the loop and its update
|
||||
System.out.println("Please enter a positive number to add it to sum or -1 to quit");
|
||||
num = scan.nextInt();//3 condition update the condition of the loop.
|
||||
}
|
||||
while (num != -1);
|
||||
System.out.println("Total " + sum);
|
||||
}
|
||||
}
|
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package lab11_calebfontenot;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public class DoWhileEvent3 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// Define variables
|
||||
int sum = 0, numInt = 0;
|
||||
String num = "This can be literally anything, it just needs to be initialized";
|
||||
|
||||
// Create scanner
|
||||
Scanner input = new Scanner(System.in);
|
||||
|
||||
do {
|
||||
System.out.print("Enter an integer to add to the sum (type x to exit): ");
|
||||
num = input.nextLine(); //Read input from console
|
||||
try {
|
||||
numInt = Integer.parseInt(num); // Parse input as integer
|
||||
} catch (Exception NumberFormatException) { // Catch invalid inputs
|
||||
if (num.toLowerCase().equals("x")) {
|
||||
break;
|
||||
} else;
|
||||
System.out.println("Invalid input!");
|
||||
}
|
||||
sum += numInt; // add integer to the sum
|
||||
|
||||
System.out.println("Current sum: " + sum);
|
||||
} while (!(num.toLowerCase().equals("x")));
|
||||
System.out.println("Exited loop!");
|
||||
System.out.println("Final sum: " + sum);
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package lab11_calebfontenot;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public class For1 {
|
||||
public static void main(String[] args) {
|
||||
for (int i=0; i < 10; ++i) {
|
||||
System.out.println(i);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package lab11_calebfontenot;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public class For2 {
|
||||
public static void main(String[] args) {
|
||||
for (int i=10; i < 20; ++i) {
|
||||
System.out.println("Square Root of " + i + ": " + Math.sqrt(i));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Main.java to edit this template
|
||||
*/
|
||||
//package lab11_calebfontenot;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public class Lab11_CalebFontenot {
|
||||
|
||||
/**
|
||||
* @param args the command line arguments
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
System.out.println("\uDD14");
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package lab11_calebfontenot;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public class While1 {
|
||||
public static void main(String[] args) {
|
||||
int i = 0;
|
||||
while (i < 10)
|
||||
{
|
||||
System.out.println(i);
|
||||
++i;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package lab11_calebfontenot;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public class While2 {
|
||||
public static void main(String[] args) {
|
||||
int i = 0;
|
||||
while (i < 10)
|
||||
System.out.println(i++);
|
||||
}
|
||||
}
|
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package lab11_calebfontenot;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public class While3 {
|
||||
public static void main(String[] args) {
|
||||
int i = 10;
|
||||
while (i > -1)
|
||||
System.out.println(i--);
|
||||
}
|
||||
}
|
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package lab11_calebfontenot;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public class WhileEvent1 {
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Please enter a positive number to add it to sum or -1 to quit");
|
||||
Scanner scan = new Scanner(System.in);
|
||||
int num = scan.nextInt(); //2 Condition: initialize the condition of the loop
|
||||
int sum = 0; //1 task: Initialize the task
|
||||
while (num != -1) //1 condition: What is the condition?
|
||||
{
|
||||
sum += num; //2 task: task of the loop and its update
|
||||
System.out.println("Please enter a positive number to add it to sum or -1 to quit");
|
||||
num = scan.nextInt();//3 condition update the condition of the loop.
|
||||
}
|
||||
|
||||
System.out.println("Total " + sum);
|
||||
}
|
||||
}
|
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package lab11_calebfontenot;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public class WhileEvent3 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// Define variables
|
||||
int sum = 0, numInt = 0;
|
||||
String num = "This can be literally anything, it just needs to be initialized";
|
||||
|
||||
// Create scanner
|
||||
Scanner input = new Scanner(System.in);
|
||||
|
||||
while (!(num.toLowerCase().equals("x"))) {
|
||||
System.out.print("Enter an integer to add to the sum (type x to exit): ");
|
||||
num = input.nextLine(); //Read input from console
|
||||
try {
|
||||
numInt = Integer.parseInt(num); // Parse input as integer
|
||||
} catch (Exception NumberFormatException) { // Catch invalid inputs
|
||||
if (num.toLowerCase().equals("x")) {
|
||||
break;
|
||||
} else;
|
||||
System.out.println("Invalid input!");
|
||||
}
|
||||
sum += numInt; // add integer to the sum
|
||||
|
||||
System.out.println("Current sum: " + sum);
|
||||
}
|
||||
System.out.println("Exited loop!");
|
||||
System.out.println("Final sum: " + sum);
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user