Java Program To Find Largest of Three Numbers
Java Program To Find Largest of Three Numbers
1. import java.util.Scanner;
2.
3. class Largest
4. {
5. public static void main(String args[])
6. {
7. int x, y, z;
8. System.out.println("Enter three integers");
9. Scanner in = new Scanner(System.in);
10.
11. x = in.nextInt();
12. y = in.nextInt();
13. z = in.nextInt();
14.
15. if (x > y && x > z)
16. System.out.println("First number is largest.");
17. else if (y > x && y > z)
18. System.out.println("Second number is largest.");
19. else if (z > x && z > y)
20. System.out.println("Third number is largest.");
21. else
22. System.out.println("The numbers are not distinct.");
23. }
24. }
class Geeks {
if (count == 0) {
System.out.println(i);
}}}}
System.out.println("Enter a string:");
str = sc.nextLine();
if (str.equals(rev))
System.out.println(str+" is a palindrome");
else
System.out.println(str+" is not a palindrome");
}}
1. class FactorialExample{
2. public static void main(String args[]){
3. int i,fact=1;
4. int number=5;//It is the number to calculate factorial
5. for(i=1;i<=number;i++){
6. fact=fact*i;
7. }
8. System.out.println("Factorial of "+number+" is: "+fact);
9. }
10. }
Add two numbers without using arithmetic operators
class GFG {
static int Add(int x, int y)
{
// Iterate till there is no carry
while (y != 0)
{
// carry now contains common // set bits of x and y
int carry = x & y;
// Sum of bits of x and // y where at least one // of the bits is not
set
x = x ^ y;
// Carry is shifted by // one so that adding it // to x gives the
required sum y = carry << 1;
}
return x;
}
// Driver code
public static void main(String arg[])
{
System.out.println(Add(15, 32));
}
}
class GFG
{
static int subtract(int x, int y)
{
while (y != 0)
{
int borrow = (~x) & y;
x = x ^ y;
y = borrow << 1;
}
return x; }
// Driver Code
int rows = 5;
System.out.print("* "); }
System.out.println(); }}
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
public class Pattern {
int rows = 5;
}System.out.println();
} } }
* * * * *
* * * *
* * *
* *
*
*
* * *
* * * * *
* * * * * * *
* * * * * * * * *
while(k != 2 * i - 1) {
System.out.print("* ");
++k;
}
System.out.println();
}
} }
1
2 3
4 5 6
7 8 9 10
System.out.println();
}
}
}