Skip to content

Instantly share code, notes, and snippets.

@viveknarang
Last active February 9, 2018 22:16
Show Gist options
  • Save viveknarang/b664f00175960a640e1c6648338fd6da to your computer and use it in GitHub Desktop.
Save viveknarang/b664f00175960a640e1c6648338fd6da to your computer and use it in GitHub Desktop.
public class Session1 {
public static void main(String[] args) {
System.out.println("A");
System.out.println("B");
int total = sum(5, 10);
System.out.println("The sum is " + total);
}
public static int sum(int a, int b) {
int c = a + b;
return c;
}
}
-----
public class Session1 {
public static void main(String[] args) {
int p1 = 5;
int p2 = 10;
int p3 = 15;
int total = sum(p1, p3);
System.out.println("The sum is " + total);
}
public static int sum(int number1, int number2) {
int c = number1 + number2;
return c;
}
}
------
public static void main(String[] args) {
int x = 10;
if (x > 10) {
System.out.println("The number is greater than 10");
} else {
System.out.println("The number is less than equal to 10");
}
}
--------
public class Session1 {
public static void main(String[] args) {
int p1 = 5;
int p2 = 10;
int total = f(p1, p2);
System.out.println("The sum is " + total);
int p3 = 51;
int p4 = 101;
int total1 = f(p3, p4);
System.out.println("The sum is " + total1);
}
public static int f(int x1, int x2) {
int c = x1 + x2;
return c;
}
}
// Gave us the total of both...
The sum is 15
The sum is 152
-----
public class Session1 {
public static void main(String[] args) {
int p1 = 5;
p1 = 45;
int p2 = 10;
int total = f(p1, p2);
System.out.println("The sum is " + total);
int p3 = 51;
int p4 = 101;
int total1 = f(p3, p4);
System.out.println("The sum is " + total1);
}
public static int f(int x1, int x2) {
int c = x1 + x2;
return c;
}
}
// Changing the variable value ...
------
public class Numbers {
int x;
int y;
/**
* Constructor
*/
public Numbers(int x1, int y1) {
x = x1;
y = y1;
}
public int sum() {
return x+y;
}
public int diff() {
return x-y;
}
public int multiply() {
return x*y;
}
public int divide() {
return x/y;
}
}
public class Session1 {
public static void main(String[] args) {
Numbers n1 = new Numbers(4, 6);
Numbers n2 = new Numbers(13, 21);
int t = n1.multiply();
System.out.println(t);
int t2 = n2.multiply();
System.out.println(t2);
}
}
// Working on two different pair of numbers ...
---
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment