Created
February 20, 2020 07:31
-
-
Save alimuhammed056/a1fa26f1336d5991322670a08d71a26e to your computer and use it in GitHub Desktop.
Java6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Circle { | |
// double radius; | |
// public void area(){ | |
// System.out.println(3.14*radius*radius); | |
// } | |
public double square(double radius){//4 | |
return radius * radius;//16 | |
} | |
public void area(double radius){//4 | |
System.out.println(3.14*square(radius));//16*3.14 | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
-NewClass2 | |
*/ | |
public class Main { | |
public static void main(String[] args) { | |
NewClass2 n = new NewClass2(); | |
n.sayHi();//calling | |
n.sayHello("marwa",1); | |
// int z = n.getValue(); | |
// System.out.println(z); | |
// System.out.println(n.getValue()); | |
String s = n.isPositive(n.getValue()); | |
System.out.println(s); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
NewClass3 | |
*/ | |
public class Main2 { | |
public static void main(String[] args) { | |
NewClass3 n = new NewClass3(); | |
n.userInput(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class NewClass { | |
//member variable | |
double height ; | |
public static void main(String[] args) { | |
//local variable | |
int sum = 0; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class NewClass1 { | |
/* | |
member variables | |
*/ | |
/* | |
constructors | |
*/ | |
/* | |
methods | |
*/ | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
modifier return-type meth-name (parameters){ | |
statements | |
} | |
return type: void or any DT | |
parameters : int x, String s, | |
*/ | |
public class NewClass2 { | |
//void and no-parameters | |
public void sayHi(){ | |
System.out.println("Hi"); | |
} | |
//void , with parameter | |
public void sayHello(String name, int i){ | |
System.out.println("Hello "+name); | |
} | |
//return , no -parameter | |
public int getValue(){ | |
return 3*8/1; | |
} | |
//return , parameter | |
public String isPositive(int x){ | |
return x>=0?"+ve":"-ve" ; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
/* | |
*/ | |
public class NewClass3 { | |
boolean b = true; | |
public void userInput() { | |
Scanner sc = new Scanner(System.in); | |
System.out.println("Enter 1st number"); | |
int x = sc.nextInt(); | |
System.out.println("Enter 2nd number"); | |
int y = sc.nextInt(); | |
System.out.println("Enter operator"); | |
String op = sc.next(); | |
int result = calc(x, y, op); | |
if(b) | |
System.out.println(result); | |
} | |
public int calc(int x, int y, String op) { | |
int result = 0; | |
switch (op) { | |
case "+": | |
result = x + y; | |
break; | |
case "-": | |
result = x - y; | |
break; | |
case "*": | |
result = x * y; | |
break; | |
case "/": | |
if (y != 0) { | |
result = x / y; | |
} else { | |
b = false; | |
System.out.println("Can't divid by zero"); | |
} | |
break; | |
default: | |
b = false; | |
System.out.println("Unknown operator"); | |
} | |
return result; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Main Class | |
*/ | |
public class Test { | |
public static void main(String[] args) { | |
// Circle c = new Circle(); | |
// c.radius = 2.3; | |
// | |
// Circle c1 = new Circle(); | |
// c1.radius = 1.0; | |
// | |
// | |
// Circle c2 = c; | |
// c2.radius = 2.1; | |
// | |
// | |
// c1.area(); | |
// System.out.println(3.14*c.radius*c.radius);//3.14*2.1*2.1 | |
// System.out.println(3.14*c1.radius*c1.radius);//3.14*1.0*1.0 | |
// System.out.println(3.14*c2.radius*c2.radius);//3.14*2.1*2.1 | |
// c = null; | |
// c2 =null; | |
// | |
// System.out.println("Hi"); | |
// System.out.println("Hi"); | |
// System.out.println("Hi"); | |
// System.out.println("Hi"); | |
// System.out.println("Hi"); | |
// System.out.println("Hi"); | |
// System.out.println("Hi"); | |
// System.out.println(3.14*c2.radius*c2.radius);//3.14*2.1*2.1 | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Circle | |
*/ | |
public class Test2 { | |
public static void main(String[] args) { | |
Circle c = new Circle(); | |
// c.radius = 4.0; | |
// c.area(); | |
c.area(4.0); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment