Set Graphics
Color
import java.applet.Applet;
import java.awt.Color;
import java.awt.Graphics;
public class SetGraphicsColorExample extends Applet
{
public void paint(Graphics g)
{
Color customColor = new Color(10,10,255);
g.setColor(customColor);
g.drawLine(10,10,30,30);
g.setColor(Color.red);
g.fillRect(40,40,40,40);
g.setColor(Color.green);
g.fillRect(80,80,40,40);
g.draw3DRect(81,81,40,40,true);
}
}
Round Java
float and double numbers
public class RounFloatDoubleNumbersExample
{
public static void main(String[] args)
{
System.out.println(Math.round(10f));
System.out.println(Math.round(20.5f));
System.out.println(Math.round(20.5f));
System.out.println(Math.round(-19.4f));
System.out.println(Math.round(-23.5f));
}
}
Find floor
value of a number using
public class FindFloorValueExample
{
public static void main(String[] args)
{
System.out.println(Math.floor(70));
System.out.println(Math.floor(30.1));
System.out.println(Math.floor(15.5));
System.out.println(Math.floor(-40));
System.out.println(Math.floor(-42.4));
System.out.println(Math.floor(0));
}
}
Arithmetic
Assignment Operators
public class ArithmeticAssignmentOperatorExample
{
public static void main(String[] args)
{
i = i + 5;
i+= 4;
int i = 5;
int j = 10;
System.out.println("i
= " + i);
System.out.println("j
= " + j);
}
}
Arithmetic
Operators
public class ArithmeticOperatorsExample
{
public static void main(String[] args)
{
System.out.println("Arithmetic operators example
:");
int i = 50 + 20;
int j = i - 10;
int k = j * 2;
double l = k / 6;
System.out.println("i = " + i);
System.out.println("j = " + j);
System.out.println("k = " + k);
System.out.println("l = " + l);
}
}
Increment and Decrement
Operators
public class IncrementDecrementOperatorExample
{
public static void main(String[] args)
{
int i = 10;
int j = 10;
i++;
j++;
System.out.println("i = " + i);
System.out.println("j = " + j);
int k = i++;
int l = ++j;
System.out.println("k = " + k);
System.out.println("l = " + l);
}
}
Modulus
Operator
public class ModulusOperatorExample
{
public static void
main(String[] args)
{
System.out.println("Java Modulus
Operator example");
int i = 50;
double d = 32;
System.out.println("i mod 10 = " + i%10);
System.out.println("d mod 10 = " + d%10);
}
}
No comments:
Post a Comment