class StringDemo
{
public static void main (String args[])
{
String str = "I am vijay";
System.out.println("The string is: " + str);
System.out.println("The string in upper case: " + str.toUpperCase());
System.out.println("Length of this string: " + str.length());
System.out.println("The character at position 5: "+ str.charAt(5));
System.out.println("The index of the character y: " + str.indexOf('y'));
System.out.println("The substring from 2 to 10: " + str.substring(2, 10));
System.out.println("The index of the beginning of the substring vijay: " + str.indexOf("vijay"));
}
}
{
public static void main (String args[])
{
String str = "I am vijay";
System.out.println("The string is: " + str);
System.out.println("The string in upper case: " + str.toUpperCase());
System.out.println("Length of this string: " + str.length());
System.out.println("The character at position 5: "+ str.charAt(5));
System.out.println("The index of the character y: " + str.indexOf('y'));
System.out.println("The substring from 2 to 10: " + str.substring(2, 10));
System.out.println("The index of the beginning of the substring vijay: " + str.indexOf("vijay"));
}
}
Output:
The string is: I am vijay
The string in upper case: I AM VIJAY
Length of this string: 10
The character at position 5: v
The index of the character y: 9
The substring from 2 to 10: am vijay
The index of the beginning of the substring vijay: 5
The string in upper case: I AM VIJAY
Length of this string: 10
The character at position 5: v
The index of the character y: 9
The substring from 2 to 10: am vijay
The index of the beginning of the substring vijay: 5
class arithmetic
{
public static void main(String args[])
{
short x = 8;
int y = 2;
float a = 10.5f;
float b = 6f;
System.out.println("Addition: "+(x+y));
System.out.println("Subtraction: "+(x-y));
System.out.println("Multiplication: "+(x*y));
System.out.println("Division: "+(x/y));
System.out.println("Modulus: "+(x%y));
System.out.println("Floating point Division: "+(a/b));
}
}
{
public static void main(String args[])
{
short x = 8;
int y = 2;
float a = 10.5f;
float b = 6f;
System.out.println("Addition: "+(x+y));
System.out.println("Subtraction: "+(x-y));
System.out.println("Multiplication: "+(x*y));
System.out.println("Division: "+(x/y));
System.out.println("Modulus: "+(x%y));
System.out.println("Floating point Division: "+(a/b));
}
}
Output:
Addition: 10
Subtraction: 6
Multiplication: 16
Division: 4
Modulus: 0
Floating point Division: 1.75
Subtraction: 6
Multiplication: 16
Division: 4
Modulus: 0
Floating point Division: 1.75
Syntax:
if(condition 1)
statement 1;
else if (condition 2)
statement 2;
else if (condition 3)
statement 3;
statement 1;
else if (condition 2)
statement 2;
else if (condition 3)
statement 3;
else
statement 4;
Grade System Program:
import java.util.Scanner;
class result
{
public static void main(String[] args)
{
int mark;
Scanner s=new Scanner(System.in);
System.out.print("Enter your mark: ");
mark=s.nextInt();
if ( mark >= 90 )
{
System.out.println( "Grade A" );
}
else if ( mark >= 80 )
{
System.out.println( "Grade B" );
}
else if ( mark >= 70 )
{
System.out.println( "Grade C" );
}
else if ( mark >= 60 )
{
System.out.println( "Grade D" );
}
else if ( mark >= 50 )
{
System.out.println( "Grade E" );
}
else if ( mark >= 40 )
{
System.out.println( "Grade F" );
}
else
{
System.out.println( "Failed" );
}
}
}
class result
{
public static void main(String[] args)
{
int mark;
Scanner s=new Scanner(System.in);
System.out.print("Enter your mark: ");
mark=s.nextInt();
if ( mark >= 90 )
{
System.out.println( "Grade A" );
}
else if ( mark >= 80 )
{
System.out.println( "Grade B" );
}
else if ( mark >= 70 )
{
System.out.println( "Grade C" );
}
else if ( mark >= 60 )
{
System.out.println( "Grade D" );
}
else if ( mark >= 50 )
{
System.out.println( "Grade E" );
}
else if ( mark >= 40 )
{
System.out.println( "Grade F" );
}
else
{
System.out.println( "Failed" );
}
}
}
Output:
Enter your mark: 56
Grade E
Enter your mark: 10
Failed
Syntax:
if(condition)
statement 1;
else
statement 2;
statement 1;
else
statement 2;
Program:
import java.util.Scanner;
class result
{
public static void main(String[] args)
{
int mark;
Scanner s=new Scanner(System.in);
System.out.print("Enter your mark: ");
mark=s.nextInt();
if ( mark <= 60 )
{
System.out.println("Fail");
}
else
{
System.out.println("Pass");
}
}
}
class result
{
public static void main(String[] args)
{
int mark;
Scanner s=new Scanner(System.in);
System.out.print("Enter your mark: ");
mark=s.nextInt();
if ( mark <= 60 )
{
System.out.println("Fail");
}
else
{
System.out.println("Pass");
}
}
}
Output:
Enter your mark: 23
Fail
Enter your mark: 56
Pass
Fail
Enter your mark: 56
Pass







