Skip to content

Instantly share code, notes, and snippets.

@alimuhammed056 alimuhammed056/NewClass
Last active Feb 16, 2020

Embed
What would you like to do?
Java2
//2- Floating points
//---------------------
// float32 bit - double 64bit
public class NewClass {
public static void main(String[] args) {
double d = 3.2;
float e = 0.5f;
float w = (float)0.5;
}
}
//byte short - int - long - float -double
// char
//--------------------------------------->
//<--------------cast---------------------
/*
3- Chcarcter
-------------
char 16bit
*/
public class NewClass1 {
public static void main(String[] args) {
char ch = 'M';
char ch1 = 80;
System.out.println(ch1);
int i = 'P';
System.out.println(i);
int j = 80;//32bit
char ch2 = (char)j;//16bit
}
}
/*
Task
*/
public class NewClass10 {
public static void main(String[] args) {
int x = -10;
String s = x >=0?"+ve":"-ve";
System.out.println(s);
String s1 = x%2==0?"even":"odd";
System.out.println(s1);
}
}
/*
Control Statements
-Condition Statement ( if - switch)
-Looping Statement (for -while - do while)
=======================
*/
//if
public class NewClass11 {
public static void main(String[] args) {
int x = 15;
/*
if(boolean){
//statements
}
*/
if(x>5){
System.out.println("x is greater than 5");
}else if(x<5){
System.out.println("x is less than 5");
}else{
System.out.println("x is equals to 5");
}
}
}
/*
Example
*/
public class NewClass12 {
public static void main(String[] args) {
int x = 80;
if(x >0){
System.out.println("+ve");
}
if(x%2==0){
System.out.println("even");
}
if(x>0 && x<100){
System.out.println("Yes in range from 0 to 100");
}
if(x/2 == 6){
System.out.println("x divid by 2 is 6");
}else{
System.out.println("No");
}
}
}
/*
Example
*/
public class NewClass13 {
public static void main(String[] args) {
int x = -5;
int y = 7;
if(x>=5){
if(y%2 == 0){
System.out.println("Ok");
}else{
System.out.println("No");
}
}else{
System.out.println("x");
}
}
}
/*
Task
*/
public class NewClass14 {
public static void main(String[] args) {
int x = 10;
int y = 20;
int z = 30;
if (x >= y && x >= z) {
System.out.println(x);
} else if (y >= x && y >= z) {
System.out.println(y);
} else {
System.out.println(z);
}
}
}
/*
Task1
*/
public class NewClass15 {
public static void main(String[] args) {
int x = 10;
int y = 20;
int z = 30;
int max = 0;
if (x > y) {
max = x;
} else {
max = y;
}
if(z>max){
max = z;
}
System.out.println(max);
}
}
/*
Task2
*/
public class NewClass16 {
public static void main(String[] args) {
int x = 10;
int y = 20;
int z = 30;
if (x > y) {
//A
if(x>z){
//A1
System.out.println(x);
} else{
//A2
System.out.println(z);
}
} else {
//B
if(y>z){
//B1
System.out.println(y);
}else{
//B2
System.out.println(z);
}
}
}
}
/*
Switch
*/
public class NewClass17 {
public static void main(String[] args) {
/*
switch(var){
case :
}
*/
int x = 50;
switch (x) {
default:
System.out.println("default");
break;
case 3:
System.out.println("x = 3");
break;
case 5:
System.out.println("x = 5");
break;
case 2:
System.out.println("x = 2");
break;
}
}
}
/*
boolean (true/false)
*/
public class NewClass2 {
public static void main(String[] args) {
boolean b = true;
boolean c = false;
}
}
/*
String
*/
public class NewClass3 {
public static void main(String[] args) {
String s = "Java"; //object reference
}
}
/*
Operators
1- Arithmetic
+ - * / %
*/
public class NewClass4 {
public static void main(String[] args) {
String a = "1";
String b = "2";
System.out.println(a+b);
double x = 5;
double y = 7;
double z = x/y;
System.out.println(z);
int m = 5;
int n = 7;
int k = m%n;
System.out.println(k);
}
}
/*
++ increment
-- decrement
*/
public class NewClass5 {
public static void main(String[] args) {
int i = 4;
i--;
System.out.println(i);
int x = 3;
int y = x++;//postfix
System.out.println(y);//3
System.out.println(x);//4
int a = 3;
int b = ++a;//prefix
System.out.println(a);//4
System.out.println(b);//4
int m = 3;
m+=2; // m = m + 2;
System.out.println(m);//5
}
}
/*
Comparison
> >= < <= == !=
String -> .equlas()
o/p -> boolean
*/
public class NewClass6 {
public static void main(String[] args) {
int x = 7;
int y = 10;
System.out.println(x==y);
String s = "marwa";
System.out.println(!s.equals("java"));
}
}
/*
Logical
---------------------
& | ^ !
&& ||
i/p -> boolean
o/p -> boolean
*/
public class NewClass7 {
public static void main(String[] args) {
int x = 7;
int y = 9;
System.out.println(x>=5 || y<10);
}
}
/*
Truth Table
-------------------------
A B & | ^ !A
F F F F F T
F T F T T T
T F F T T F
T T T T F F
*/
/*
* 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.
*/
/**
*
* @author NH
*/
public class NewClass8 {
}
/*
Conditional Op
Ternary OP
inline if
----------------------
?
*/
public class NewClass9 {
public static void main(String[] args) {
int x = 6;
String s = x > 5 ? "Yes" : "No";
System.out.println(s);
int y = x > 5 ? ++x : --x;
System.out.println(y);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.