import java.util.Random; /* * Simulates rolling a pair of dice * * @author Willy Ferreiras */ public class DiceRoller{ public static void main(String[] args){ Random rand = new Random(); // Random's nextInt method generates a random int, not including limit int die1 = rand.nextInt(6) + 1; int die2 = rand.nextInt(6) + 1; int sum = die1 + die2; System.out.println("Die 1: " + die1); System.out.println("Die 2: " + die2); System.out.println("Sum: " + sum); } }
import java.util.Random; import java.math.BigInteger; import java.net.HttpCookie; import java.util.GregorianCalendar; /** * Demo of objects and constructors * * @author Wil levonuk * */ public class ConstructorDemo { public static void main(String[] args) { //A zero-argument constructor is called a default constructor //whereas a parameterized constructor takes one or more arguments Random rand = new Random(34); //Random() is a default constructor BigInteger num = new BigInteger("666666666666666666666666666666666666"); System.out.println(rand); HttpCookie cookie = new HttpCookie("username", "Password"); GregorianCalendar today = new GregorianCalendar(); GregorianCalendar bDay = new GregorianCalendar(1999, 4, 7); //operands System.out.println(today); System.out.println(bDay); System.out.print("This is " + 1 + "," + 2); } }
import java.util.Scanner; /** * Performs integer exponentiation with a user-specified base and exponent. * * Rachel Szivos */ public class PowerCalculator { public static void main(String []args){ // prompt the user and read input System.out.print("Enter two integers (base and exponent): "); Scanner in = new Scanner(System.in); int base= in.nextInt(); int exp = in.nextInt(); // calculate result int result = (int) Math.pow(base, exp); // format and display result String output = base + "^" + exp + " is " + result; System.out.println(output); } }
import java.util.Scanner; /* Performs integer exponention with a user-specified base and exponent. @author Jake Nocentino @version September 13, 2017 */ public class PowerCalculator { public static void main(String[] args) { // prompt the user and read input System.out.print("Enter two integers (base and exponent): "); Scanner in = new Scanner(System.in); int base = in.nextInt(); int exp = in.nextInt(); // calculate result int result = (int) Math.pow(base, exp); // format and display results String output = base + "^" + exp + " is " + result; System.out.println(output); } }
import java.util.Scanner; /** * Performs integer exponentiation with a user-specified base and exponent. * * @author Taylor Raker * @version September 13, 2017 */ public class PowerCalculator { public static void main(String[ ] args) { // ---prompt the user and read input System.out.print("Enter two integers (base and exponent):"); /*^print, not println because it will output the text but the cursor will stay on that line and not go to the next one. */ Scanner in = new Scanner(System.in); /*in is a variable of type "Scanner". Constructed a scanner that can read inputs from a keyboard. */ int base = in.nextInt(); //variable base of type Int int exp = in.nextInt(); // ----calculate result int result = (int) Math.pow(base, exp); //static method, "Math". not a class. independent of any object. "pow" //performs "power" // ----format and display result String output = base + "^" + exp + " is " + result; System.out.println(output); } }
import java.util.Random; /** * Simulates rollling a pair of dice. * * @author Sarah Joiner * @version September 13, 2017 */ public class DiceRoller { public static void main(String[] args) { Random rand = new Random(); // roll dice and compute sum int die1 = 1 + rand.nextInt(6); int die2 = 1 + rand.nextInt(6); int sum = die1 + die2; // output results System.out.println("First die: " + die1); System.out.println("Second dies "+ die2); System.out.println("The sum is " + sum + "."); } }
// Print and Println Assignment /* Created By: Ryan Arokia-Raj Date created: 09/7/2017 */ public class Main { public static void main(String[] args) { System.out.println(" O D"); System.out.println(" L L"); System.out.println(" L R"); System.out.println(" E O"); System.out.println(" H W"); System.out.println("*****************"); System.out.println("** I **"); System.out.println("** J S ****"); System.out.println("** A ** **"); System.out.println("** V H ** **"); System.out.println("** A O ** **"); System.out.println("** T ** **"); System.out.println("** ** **"); System.out.println("** ****"); System.out.println("*****************"); } }
import java.util.Random; import java.math.BigInteger; import java.net.HttpCookie; import java.util.GregorianCalendar; /** * Demonstrates the creation of objects and their initialization using constructors. * * Rachel Szivos */ public class ConstructorDemo{ public static void main(String []args){ Random rand = new Random(); BigInteger num = new BigInteger("484573438"); HttpCookie cookie = new HttpCookie ("username", "rszivos"); GregorianCalendar today = new GregorianCalendar(); GregorianCalendar bDay = new GregorianCalendar(1999,8,5); } }
public class HelloWorld{ public static void main(String []args) { System.out.println("Hello World"); } }
import java.util.Scanner; public class HelloWorld{ public static void main(String []args){ int a,d; int x=1; Scanner in = new Scanner(System.in); System.out.println("enter the integer"); a=in.nextInt(); while(x<=10){ d=a*x; System.out.println(d); x++; } } }
We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy. Accept Learn more