Skip to content

Instantly share code, notes, and snippets.

@alimuhammed056
Created February 16, 2020 22:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alimuhammed056/1bd6ea1cf384c5fbce2cc18a45d272af to your computer and use it in GitHub Desktop.
Save alimuhammed056/1bd6ea1cf384c5fbce2cc18a45d272af to your computer and use it in GitHub Desktop.
Java4
import java.util.Scanner;
/*
Calculator
*/
public class NewClass {
public static void main(String[] args) {
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();
boolean b = true;
System.out.println("Enter operator");
String ops = sc.next();
char op = ops.charAt(0);
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.err.println("Can't divid by zero");
}
break;
default:
b = false;
System.out.println("Wrong operator");
}
if(b)
System.out.println("The result = "+result);
}
}
import java.util.Scanner;
public class NewClass1 {
public static void main(String[] args) {
int x = 5;
int i = 0;
Scanner sc = new Scanner(System.in);
for (; i < 3; i++) {
System.out.println("Guess Number from 0 to 100");
int y = sc.nextInt();
if(y == x){
System.out.println("You win");
break;
}else{
if(i<2)
System.out.println("Try Again");
}
}
if(i==3){
System.out.println("you lose");
System.err.println("Game Over");
}
}
}
public class NewClass2 {
public static void main(String[] args) {
int m = 6;
int n = 6;
int a = 4;
int k = 0;
k = m / a;
int j = 0;
j = n / a;
if (m % a != 0) {
k = k + 1;
}
if (n % a != 0) {
j = j + 1;
}
System.out.println(k * j);
}
}
public class NewClass3 {
public static void main(String[] args) {
double m = 6;
double n = 6;
double a = 4;
double k = m/a;
double j = n/a;
double f = Math.ceil(k)* Math.ceil(j);
System.out.println(f);
}
}
public class NewClass4 {
public static void main(String[] args) {
for (int i = 0; i <4; i++) {
for(int j =0 ; j<=i ; j++){
System.out.print("*");
}
System.out.println("");
}
}
}
public class NewClass5 {
public static void main(String[] args) {
String s ="";
for (int i = 0; i <4; i++) {
s =s +"*";
System.out.println(s);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment