Posts
Showing posts from 2017
Java precedence
- Get link
- X
- Other Apps
Level Operator Description Associativity 16 [] . () access array element access object member parentheses left to right 15 ++ -- unary post-increment unary post-decrement not associative 14 ++ -- + - ! ~ unary pre-increment unary pre-decrement unary plus unary minus unary logical NOT unary bitwise NOT right to left 13 () new cast object creation right to left 12 * / % multiplicative left to right 11 + - + additive string concatenation left to right 10 << >> >>> shift left to right 9 < <= > >= instanceof relational not associative 8 == != equality left to right 7 & bitwise AND left to right 6 ^ bitwise XOR left to right 5 | bitwise OR left to right 4 && logical AND left to right 3 || logical OR left to right 2 ?: ternary right to left 1 = += -= *= /= %= &= ^= |= <<= >>= >>>= assignment right to left Resource: https://introcs.cs.princeton.edu/java/11precedence/
DataSructure Lab 6
- Get link
- X
- Other Apps
Laboratory Sheet 6 1. Write a method to generate 1000 numbers between 1-1000. Use random number generator. Store the numbers in an array of integer. 2. Write a method to sort numbers generated in 1. Implement selection sort . 3. Write a method to sort numbers generated in 1. Implement bubble sort . 4. Write a method to sort numbers generated in 1. Implement linear insertion sort . 5. Compare the time taken to sort 1000 numbers between the three methods. 6. Repeat 1-5, with 15000 numbers.
java code round to two decimal place
- Get link
- X
- Other Apps
Method 1: x = (double)int((x+0.005)*100.0)/100.0; Method 2: x = Math.round(x*100.0) / 100.0; Method 3: DecimalFormat df2 = new DecimalFormat( "#,###,###,##0.00" ); double dd = 100.2397; double dd2dec = new Double(df2.format(dd)).doubleValue(); Method 4: f = (float) (Math.round(n*100.0f)/100.0f); Method 5: double r = 5.1234; System.out.println(r); // r is 5.1234 int decimalPlaces = 2; BigDecimal bd = new BigDecimal(r); bd = bd.setScale(decimalPlaces, BigDecimal.ROUND_HALF_UP); // setScale is immutable r = bd.doubleValue(); System.out.println(r); // r is 5.12 source: http://salmanjamali.blogspot.my/2008/01/java-rounding-off-to-2-decimal-places.html :http:// www.thescripts.com
contoh JOptionPane
- Get link
- X
- Other Apps
import javax.swing.*; /** * JOptionPane showInputDialog example #1. * A simple showInputDialog example. * @author alvin alexander, http://alvinalexander.com */ public class JOptionPaneShowInputDialogExample1 { public static void main(String[] args) { // a jframe here isn't strictly necessary, but it makes the example a little more real JFrame frame = new JFrame("InputDialog Example #1"); // prompt the user to enter their name String name = JOptionPane.showInputDialog(frame, "What's your name?"); JOptionPane.showMessageDialog(frame,"my name is "+name); // get the user's input. note that if they press Cancel, 'name' will be null System.out.printf("The user's name is '%s'.\n", name); System.exit(0); } } //original source: http://alvinalexander.com/java/joptionpane-showinputdialog-examples
Tutorial 27 April 2017
- Get link
- X
- Other Apps
Sistem maklumat pelajar dan staff UMT -Boleh rekod maklumat staff dan pelajar -Print maklumat pelajar dan staff. Untuk pelajar perlu rekod maklumat nama, ic, alamat, no tel, umur, no matrik, nama kursus Untuk staff perlu rekod maklumat nama, ic, alamat, no tel, umur, nama pejabat, nama jawatan Alamat ada mklumat nama, alamat, poskod, daerah, negeri dan negara -mesti ada inheritance dan aggregation * Sediakan UML class diagram * Tulis coding penuh bagi sistem ini * input 5 nama pelajar dan staff * output maklumat pelajar dan staff
contoh enum
- Get link
- X
- Other Apps
//contoh enum //source:https://docs.oracle.com/javase/tutorial/java/javaOO/enum.html /* * 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 javaapplication1; /** * * @author Makmal PPIMG */ public enum NewEnum { MERCURY (3.303e+23, 2.4397e6), VENUS (4.869e+24, 6.0518e6), EARTH (5.976e+24, 6.37814e6), MARS (6.421e+23, 3.3972e6), JUPITER (1.9e+27, 7.1492e7), SATURN (5.688e+26, 6.0268e7), URANUS (8.686e+25, 2.5559e7), NEPTUNE (1.024e+26, 2.4746e7); private final double mass; // in kilograms private final double radius; // in meters //constructor mesti sama type dengan enum NewEnum(double mass, double radius) { this.mass = mass; this.radius = radius; } public double getMass(){ return mass; } //main method b
session tracking for logOut
- Get link
- X
- Other Apps
<% String email = ( String ) session . getAttribute ( "email" ) ; / / redirect user to home page if already logged in if ( email != null ) { response . sendRedirect ( "home.jsp" ) ; } String status = request . getParameter ( "status" ) ; if ( status != null ) { if ( status . equals ( "false" ) ) { out . print ( "Incorrect login details!" ) ; } else { out . print ( "Some error occurred!" ) ; } } %> resource: http://www.thecrazyprogrammer.com/2016/03/jsp-login-logout-system-example-using-session.html