Created
February 16, 2020 22:23
-
-
Save alimuhammed056/1bd6ea1cf384c5fbce2cc18a45d272af to your computer and use it in GitHub Desktop.
Java4
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; | |
/* | |
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); | |
} | |
} |
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 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"); | |
} | |
} | |
} |
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 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); | |
} | |
} |
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 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); | |
} | |
} |
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 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(""); | |
} | |
} | |
} |
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 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