Skip to content

Instantly share code, notes, and snippets.

@joeyv
joeyv / Distance.java
Last active December 26, 2015 05:59
Simple program to calculate the distance of two coordinates
import java.util.*;
public class Distance
{
public static void main(String[] args)
{
int x1, y1;
int x2, y2;
int inside, distance;
@joeyv
joeyv / Usernames.java
Last active December 26, 2015 08:39
Generates a username based off of the first letter of your name, the first 5 letters of your last name, and a random 2 digit number.
import java.util.*;
public class Usernames {
public static void main(String[] args) {
String first, last, username;
int randomNum;
// Scan in first and last name
@joeyv
joeyv / Sphere.java
Last active December 26, 2015 10:28
Calculates Volume and Surface Area of a sphere
import java.util.Scanner;
import java.text.*;
public class Sphere
{
public static void main(String[] args)
{
double pi = Math.PI;
double radius, volume, surfaceArea;
@joeyv
joeyv / Tax.java
Created October 24, 2013 12:50
Calculates your tax cost
import java.util.Scanner;
import java.text.*;
public class Tax {
public static void main(String[] args)
{
// Declare variables
int allowedDeduction = 10000, deduction = 2000;
int grossIncome, dependents;
@joeyv
joeyv / Payroll.java
Created October 24, 2013 17:20
calculate your payroll
import java.util.Scanner;
import java.text.*;
public class Payroll{
public static void main(String []args){
double hourPay, hourWorked;
double overtime, total;
@joeyv
joeyv / Sum.java
Last active December 26, 2015 11:39
Adds 1 - 100 inclusively
class Sum {
public static void main(String[] args) {
int i = 0, sum = 0;
// Loop adds numbers 1 = 100
while(i < 100){
i++;
sum += i;
}
@joeyv
joeyv / Root.java
Last active December 26, 2015 11:39
Displays the square roots of 25 and every number 5 less than it until you reach 0. Using a while loop and for loop
public class Root {
public static void main(String[] args)
{
int base = 25;
while(base > 0){
System.out.println("Square root of " + base + "\t= " + Math.sqrt(base));
base -= 5;
@joeyv
joeyv / Factorial.java
Last active December 26, 2015 13:29
Calculates factorial of a number
import java.util.Scanner;
public class Factorial {
public static void main(String[] args) {
int total = 1;
int i, num;
Scanner scan = new Scanner(System.in);
num = scan.nextInt();
@joeyv
joeyv / Prime.java
Last active December 26, 2015 19:29
IM STUCK
import java.util.Scanner;
public class Prime{
public static void main(String []args){
int total = 0;
int num,num2, i;
Scanner scan = new Scanner(System.in);
num = scan.nextInt();
@joeyv
joeyv / Lucky7.java
Last active December 27, 2015 00:19
import java.util.*;
public class Lucky{
public static void main(String []args){
int money, userMoney; //userMoney is the amount user started with. Money is the total after the rolls
int die1, die2, sum;
int i = 1, roll = 0; // i is the counter, roll will hold the value of the counter when needed
Scanner scan = new Scanner(System.in);