If Else in Java Code: Class
If Else in Java Code: Class
If Else in Java Code: Class
{
public static void main(String args[])
{
System.out.println("Hello World");
}
}
---------------------------------------------------------
/ If else in Java code
import java.util.Scanner;
class IfElse {
public static void main(String[] args) {
int marksObtained, passingMarks;
passingMarks = 40;
marksObtained = input.nextInt();
import java.util.Scanner;
class WhileLoop {
public static void main(String[] args) {
int n;
class Alphabets
{
public static void main(String args[])
{
char ch;
char c = 'a';
char c = 'A';
do {
System.out.println(c);
c++;
} while (c <= 'Z');
import java.util.Scanner;
class GetInputFromUser
{
public static void main(String args[])
{
int a;
float b;
String s;
System.out.println("Enter an integer");
a = in.nextInt();
System.out.println("You entered integer "+a);
System.out.println("Enter a float");
b = in.nextFloat();
System.out.println("You entered float "+b);
System.out.println("Enter a string");
s = in.nextLine();
System.out.println("You entered string "+s);
}
}
import java.util.Scanner;
class MultiplicationTable
{
public static void main(String args[])
{
int n, c;
System.out.println("Enter an integer to print it's multiplication table");
Scanner in = new Scanner(System.in);
n = in.nextInt();
System.out.println("Multiplication table of "+n+" is :-");
import java.util.Scanner;
class OddOrEven
{
public static void main(String args[])
{
int x;
System.out.println("Enter an integer to check if it is odd or even ");
Scanner in = new Scanner(System.in);
x = in.nextInt();
if ( x % 2 == 0 )
System.out.println("You entered an even number.");
else
System.out.println("You entered an odd number.");
}
}
import java.util.Scanner;
class SwapNumbers
{
public static void main(String args[])
{
int x, y, temp;
System.out.println("Enter x and y");
Scanner in = new Scanner(System.in);
x = in.nextInt();
y = in.nextInt();
temp = x;
x = y;
y = temp;
import java.util.Scanner;
class SwapNumbers
{
public static void main(String args[])
{
int x, y;
System.out.println("Enter x and y");
Scanner in = new Scanner(System.in);
x = in.nextInt();
y = in.nextInt();
x = x + y;
y = x - y;
x = x - y;
System.out.println("After Swapping\nx = "+x+"\ny = "+y);
}
}
import java.util.Scanner;
class Factorial
{
public static void main(String args[])
{
int n, c, fact = 1;
n = in.nextInt();
if (n < 0)
System.out.println("Number should be non-negative.");
else
{
for (c = 1; c <= n; c++)
fact = fact*c;
import java.util.Scanner;
class ArmstrongNumber
{
public static void main(String args[])
{
int n, sum = 0, temp, remainder, digits = 0;
temp = n;
while (temp != 0) {
digits++;
temp = temp/10;
}
temp = n;
while (temp != 0) {
remainder = temp%10;
sum = sum + power(remainder, digits);
temp = temp/10;
}
if (n == sum)
System.out.println(n + " is an Armstrong number.");
else
System.out.println(n + " isn't an Armstrong number.");
}
return p;
}
}
import java.util.*;
class ReverseString
{
public static void main(String args[])
{
String original, reverse = "";
Scanner in = new Scanner(System.in);
import java.util.*;
class Palindrome
{
public static void main(String args[])
{
String original, reverse = ""; // Objects of String class
Scanner in = new Scanner(System.in);
if (original.equals(reverse))
System.out.println("Entered string is a palindrome.");
else
System.out.println("Entered string isn't a palindrome.");
}
}
import java.util.Scanner;
class ReverseNumber
{
public static void main(String args[])
{
int n, reverse = 0;
while(n != 0)
{
reverse = reverse * 10;
reverse = reverse + n%10;
n = n/10;
}
main(string args[])
strongnumber ss=new
strongnumber();
int a,b,r,s=0;
system.out.println(“Enter a number”);
b=sl.nextInt();
a=b;
while(b>0)
r=b%10;
s=s+ss.fact(r);
b=b/10;
if(a==s)
else
int fact(int i)
int f,j;
f=1;
for(j=i;j>0;j--)
f=f*j;
return f;
import java.util.P;
{
public static void
main(string args[])
int a,b,gcd;
a=b=gcd=0;
a=s.nextInt();
b=s.next.Int();
while(a!=0)
gcd=a;
a=b%a;
b=gcd;
system.out.println(“GCD”+gcd);