String String System: Out Println Charat
String String System: Out Println Charat
String String System: Out Println Charat
a) class
b) object
c) variable
d) character array
2. Which of these method of String class is used to obtain character at specified index?
a) char()
b) Charat()
c) charat()
d) charAt()
3. Which of these keywords is used to refer to member of base class from a sub class?
a) upper
b) super
c) this
d) none of the mentioned
4. Which of these method of String class can be used to test to strings for equality?
a) isequal()
b) isequals()
c) equal()
d) equals()
5. What is the output of this program?
class string_demo
{
public static void main(String args[])
{
String obj = "I" + "like" + "Java";
System.out.println(obj);
}
}
class HelloWorld
{
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;
System.out.println("Out of loop");
}
}
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;
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;
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;
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);