SEM2Java
SEM2Java
VOWELS IN A STRING
Import java.util.scanner;
Class Vowelsinastring
{
Public static void main(String[]args)
{
String s;
Scanner sc = new Scanner(Systen.in);
System.out.print(“Enter a string:”);
S=sc.nextline();
System.out.println(“Vowels in a string”’+s+”’are:”);
Vowels(s);
}
Static void vowels(String str)
{
Char ch;
Int i = 0;
For(int j = 0;j<str.length();j++)
{
Ch = str.char At(j);
If(ch==’a’|| ch==’e’|| ch==’i’|| ch==’o’|| ch==’u’|| ch==’A’|| ch==’E’|| ch==’I’|| ch==’O’||
ch==’U’||)
{
I = 1;
System.out.println(ch);
}
}
If(i==0)
System.out.println(“There are no vowels in a Entered String”);
}
}
OUTPUT:
Enter a string:
Abcdefghijklmnopqrstuvwxyz
Vowels ia a String
Abcdefghijklmnopqrstuvwxyz
are:
a
e
i
o
u
PLUS SYMBOL
Import java.util.scanner;
Public classplus
{
Public static void main (String[]args)
{
Scanner sc = new Scanner(System.in);
System.out.println(“Enter N:”);
Int n =sc.nextint();
System.out.print(“Enter Symbol:”);
Char c = sc.next().charAt(0);
For(int i=1;j<=n*2-1;i++)
{
If(i!=n)
For(int j = 1;j<=n;j++)
{
If(j==n)
System.out.print(c);
System.out.print(“”);
For(int j=1;j<=n*2-1;j++)
{
System.out,print(c);
}
System.out,println();
}
}
}
OUTPUT:
5
Enter Symbol:+
+
Display Date and Time
import java.util.*;
class GetCurrentDateAndTime
{
public static void main(String args[])
{
int day, month, year;
int second, minute, hour;
GregorianCalendar date = new GregorianCalendar();
day = date.get(Calendar.DAY_OF_MONTH);
month = date.get(Calendar.MONTH);
year = date.get(Calendar.YEAR);
second = date.get(Calendar.SECOND);
minute = date.get(Calendar.MINUTE);
hour = date.get(Calendar.HOUR);
System.out.println("Current date is "+day+"/"+(month+1)+"/"+year);
System.out.println("Current time is "+hour+" : "+minute+" : "+second);
}
}
OUTPUT:
Current date is 14|3|2024
Current time is 9:30:45
import java.util.Scanner;
public class SortArray
{
public static void main(String[] args)
{
int n, temp;
Scanner s = new Scanner(System.in);
System.out.print("Enter no. of elements you want in array:");
n = s.nextInt();
int a[] = new int[n];
System.out.println("Enter all the elements:");
for (int i=0; i<n; i++)
{
a[i]=s.nextInt();
}
for (int i =0; i<n; i++)
{
for (int j=i+1; j<n; j++)
{
if (a[i]>a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
System.out.print("Elements in Ascending Order:");
for (int i=0; i<n-1; i++)
{
System.out.print(a[i]+ ", ");
}
System.out.print(a[n-1]);
}
}
OUTPUT:
import java.io.*;
import java.util.*;
class GFG {
System.out.println(
"List Before Rotation : "
+ Arrays.toString(my_list.toArray()));
System.out.println(
"List After Rotation : "
+ Arrays.toString(my_list.toArray()));
}
}
OUTPUT:
List Before Rotation:[10,20,30,40,50,60,70]
List After Rotation:[30,40,50,60,70,10,20]
OUTPUT:
9 is present at location 4
REVERSE OF A STRING
Import java.util.scanner;
Class Reverseofastring
{
Public static void main(String[]args)
{
Reverse of a string rev = new Reverse of a string();
Scanner sc = new Scanner(System.in)
System.out.print(“Enter a String:”);
String str = sc.nextline();
System.out.println(“Reverse of a string is :”+ rev.revrese (str));
}
Static string reverse(String s)
{
String rev = “ ”;
For(int j = s.length();j>0;--j)
{
Rev = rev + (s.char At(j-1);
}
Return rev;
}
}
OUTPUT:
Enter a String : String
Reverse of a String : gnirtS
t1.start();
t2.start();
t2.suspend();
t3.start();
}
}
OUTPUT:
Currently running-Thread-0
1
Currently running-Thread-1
1
2
3
4
EXCEPTION HANDLING
public class TryCatchExample6
{
public static void main(String[] args)
{
int i=50;
int j=0;
int data;
try
{
data=i/j;
}
catch(Exception e)
{
System.out.println(i/(j+2));
}
}
}
OUTPUT:
25
try{
int a[]=new int[5];
a[5]=30/0;
}
catch(ArithmeticException e)
{ System.out.println("Arithmetic Exception occurs");
}
catch(ArrayIndexOutOfBoundsException e)
{
System.out.println("ArrayIndexOutOfBounds Exception occurs");
} catch(Exception e)
{ System.out.println("Parent Exception occurs");
} System.out.println("rest of the code");
}
}
OUTPUT:
Output:
exception handled
normal flow...
OUTPUT:
OUTPUT:
thread is running...
for(int i=1;i<=5;i++)
System.out.println(n*i);
Try
Thread.sleep(400);
catch(Exception e)
System.out.println(e);
Table t;
MyThread1(Table t)
this.t=t;
{
t.printTable(5);
Table t;
MyThread2(Table t)
this.t=t;
t.printTable(100);
t1.start();
t2.start();
}
OUTPUT:
5
10
15
20
25
100
200
300
400
500
OUTPUT:
Hello World
OUTPUT:
March 14,2024
OUTPUT:
OUTPUT:
Sample Banner