List of usage examples for java.lang Math floor
public static double floor(double a)
From source file:Main.java
public static void main(String[] args) { System.out.println(Math.floor(31.1)); }
From source file:Main.java
public static void main(String[] args) { System.out.println(Math.floor(70)); System.out.println(Math.floor(31.1)); System.out.println(Math.floor(12.5)); System.out.println(Math.floor(-10)); System.out.println(Math.floor(-12.4)); System.out.println(Math.floor(0)); }
From source file:MainClass.java
public static void main(String args[]) { System.out.println("The floor of 45.7 is " + Math.floor(45.7)); }
From source file:Main.java
public static void main(String[] args) { double x = 123456.7; double y = -123.45; // call floor and print the result System.out.println("Math.floor(" + x + ")=" + Math.floor(x)); System.out.println("Math.floor(" + y + ")=" + Math.floor(y)); System.out.println("Math.floor(0)=" + Math.floor(0)); }
From source file:Main.java
public static void main(String[] args) { ArrayList<String> list = new ArrayList<>(); list.add("A"); list.add("B"); list.add("C"); list.add("D"); list.add("E"); list.add("F"); list.add("G"); list.add("H"); System.out.println(list);//from w ww . j a v a 2 s .c om while (!list.isEmpty()) { long index = Math.round(Math.floor(Math.random() * list.size())); System.out.println("Name " + list.get((int) index)); list.remove((int) index); } }
From source file:RandNum.java
public static void main(String[] args) { int num;/*from ww w.j av a2 s. c o m*/ int[] dist = new int[10]; // Storage for distribution // Generate 10000 random numbers using Math.random() for (int x = 0; x < 10000; x++) { num = (int) (Math.floor(Math.random() * 10)); dist[num]++; } // Display distribution of random integers in the range // 0 to 9 System.out.println("Distribution using Math.random() "); for (int k = 0; k < 10; k++) System.out.print(k + "\t"); // Display results for (int y = 0; y < 10; y++) { System.out.print(dist[y] + "\t"); } System.out.println(); }
From source file:MainCLass.java
public static void main(String[] args) { double x = 2.4; double y = 9.5; double z = -1.3; System.out.println("round(x) = " + Math.round(x)); System.out.println("round(y) = " + Math.round(y)); System.out.println("round(z) = " + Math.round(z)); System.out.println();/*from w ww. j a v a2s .c o m*/ System.out.println("ceil(x) = " + Math.ceil(x)); System.out.println("ceil(y) = " + Math.ceil(y)); System.out.println("ceil(z) = " + Math.ceil(z)); System.out.println(); System.out.println("floor(x) = " + Math.floor(x)); System.out.println("floor(y) = " + Math.floor(y)); System.out.println("floor(z) = " + Math.floor(z)); System.out.println(); System.out.println("rint(x) = " + Math.rint(x)); System.out.println("rint(y) = " + Math.rint(y)); System.out.println("rint(z) = " + Math.rint(z)); }
From source file:MainClass.java
public static void main(String args[]) { System.out.printf("Math.abs( 23.7 ) = %f\n", Math.abs(23.7)); System.out.printf("Math.abs( 0.0 ) = %f\n", Math.abs(0.0)); System.out.printf("Math.abs( -23.7 ) = %f\n", Math.abs(-23.7)); System.out.printf("Math.ceil( 9.2 ) = %f\n", Math.ceil(9.2)); System.out.printf("Math.ceil( -9.8 ) = %f\n", Math.ceil(-9.8)); System.out.printf("Math.cos( 0.0 ) = %f\n", Math.cos(0.0)); System.out.printf("Math.exp( 1.0 ) = %f\n", Math.exp(1.0)); System.out.printf("Math.exp( 2.0 ) = %f\n", Math.exp(2.0)); System.out.printf("Math.floor( 9.2 ) = %f\n", Math.floor(9.2)); System.out.printf("Math.floor( -9.8 ) = %f\n", Math.floor(-9.8)); System.out.printf("Math.log( Math.E ) = %f\n", Math.log(Math.E)); System.out.printf("Math.log( Math.E * Math.E ) = %f\n", Math.log(Math.E * Math.E)); System.out.printf("Math.max( 2.3, 12.7 ) = %f\n", Math.max(2.3, 12.7)); System.out.printf("Math.max( -2.3, -12.7 ) = %f\n", Math.max(-2.3, -12.7)); System.out.printf("Math.min( 2.3, 12.7 ) = %f\n", Math.min(2.3, 12.7)); System.out.printf("Math.min( -2.3, -12.7 ) = %f\n", Math.min(-2.3, -12.7)); System.out.printf("Math.pow( 2.0, 7.0 ) = %f\n", Math.pow(2.0, 7.0)); System.out.printf("Math.pow( 9.0, 0.5 ) = %f\n", Math.pow(9.0, 0.5)); System.out.printf("Math.sin( 0.0 ) = %f\n", Math.sin(0.0)); System.out.printf("Math.sqrt( 900.0 ) = %f\n", Math.sqrt(900.0)); System.out.printf("Math.sqrt( 9.0 ) = %f\n", Math.sqrt(9.0)); System.out.printf("Math.tan( 0.0 ) = %f\n", Math.tan(0.0)); }
From source file:BasicMathDemo.java
public static void main(String[] args) { double aNumber = -191.635; System.out.println("The absolute value of " + aNumber + " is " + Math.abs(aNumber)); System.out.println("The ceiling of " + aNumber + " is " + Math.ceil(aNumber)); System.out.println("The floor of " + aNumber + " is " + Math.floor(aNumber)); System.out.println("The rint of " + aNumber + " is " + Math.rint(aNumber)); }
From source file:com.mapr.PurchaseLog.java
public static void main(String[] args) throws IOException { Options opts = new Options(); CmdLineParser parser = new CmdLineParser(opts); try {/*from w w w .jav a 2 s . co m*/ parser.parseArgument(args); } catch (CmdLineException e) { System.err.println("Usage: -count <number>G|M|K [ -users number ] log-file user-profiles"); return; } Joiner withTab = Joiner.on("\t"); // first generate lots of user definitions SchemaSampler users = new SchemaSampler( Resources.asCharSource(Resources.getResource("user-schema.txt"), Charsets.UTF_8).read()); File userFile = File.createTempFile("user", "tsv"); BufferedWriter out = Files.newBufferedWriter(userFile.toPath(), Charsets.UTF_8); for (int i = 0; i < opts.users; i++) { out.write(withTab.join(users.sample())); out.newLine(); } out.close(); // now generate a session for each user Splitter onTabs = Splitter.on("\t"); Splitter onComma = Splitter.on(","); Random gen = new Random(); SchemaSampler intermediate = new SchemaSampler( Resources.asCharSource(Resources.getResource("hit_step.txt"), Charsets.UTF_8).read()); final int COUNTRY = users.getFieldNames().indexOf("country"); final int CAMPAIGN = intermediate.getFieldNames().indexOf("campaign_list"); final int SEARCH_TERMS = intermediate.getFieldNames().indexOf("search_keywords"); Preconditions.checkState(COUNTRY >= 0, "Need country field in user schema"); Preconditions.checkState(CAMPAIGN >= 0, "Need campaign_list field in step schema"); Preconditions.checkState(SEARCH_TERMS >= 0, "Need search_keywords field in step schema"); out = Files.newBufferedWriter(new File(opts.out).toPath(), Charsets.UTF_8); for (String line : Files.readAllLines(userFile.toPath(), Charsets.UTF_8)) { long t = (long) (TimeUnit.MILLISECONDS.convert(30, TimeUnit.DAYS) * gen.nextDouble()); List<String> user = Lists.newArrayList(onTabs.split(line)); // pick session length int n = (int) Math.floor(-30 * Math.log(gen.nextDouble())); for (int i = 0; i < n; i++) { // time on page int dt = (int) Math.floor(-20000 * Math.log(gen.nextDouble())); t += dt; // hit specific values JsonNode step = intermediate.sample(); // check for purchase double p = 0.01; List<String> campaigns = Lists.newArrayList(onComma.split(step.get("campaign_list").asText())); List<String> keywords = Lists.newArrayList(onComma.split(step.get("search_keywords").asText())); if ((user.get(COUNTRY).equals("us") && campaigns.contains("5")) || (user.get(COUNTRY).equals("jp") && campaigns.contains("7")) || keywords.contains("homer") || keywords.contains("simpson")) { p = 0.5; } String events = gen.nextDouble() < p ? "1" : "-"; out.write(Long.toString(t)); out.write("\t"); out.write(line); out.write("\t"); out.write(withTab.join(step)); out.write("\t"); out.write(events); out.write("\n"); } } out.close(); }