0% found this document useful (0 votes)
24 views12 pages

Alan-Java 2

hii this is a ....

Uploaded by

avadhborda458
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
24 views12 pages

Alan-Java 2

hii this is a ....

Uploaded by

avadhborda458
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
[Link] [Link] 2202040601009 PROBLEAM SHEET — II Core Java 1. Write a Java program to create a Date object using the Calendar class. import [Link] Calendar; public class Calender { Public static void main(String{] args) { Calendar calendar = [Link](); [Link]([Link], 2023); [Link](Calendar. MONTH, 8); [Link]([Link], 17); [Link] dt = [Link](); [Link]( "Date: "+dt); 2. Write a Java program to get and display information (year, month, day, hour, minute) of a default calendar. import [Link]; public class DefaultCalender { Public static void main(String[] ares) { Calendar cal = [Link](); [Link](); System. [Link]("Year: " + cal,get(Calendar. YEAR)); System. [Link]("Month: " + cal,get([Link])); [Link]( "Day: " + [Link]([Link])); System. [Link](*Hour: " + [Link]( Calendar. HOUR); ‘System. [Link]("Minute: "+ [Link](Calendar. MINUTE)); [Link](); [Link] [Link] 2202040601009 3. Write a Java program to get the maximum value of the year, month, week, and date from the current date of a default calendar. import [Link]; public class MaxCalender { public static void main(String{] args) { Calendar cal = [Link](); [Link](); [Link]("\nCurrent Date and Time:" + [Link]()}; int actualMaxYear = [Link](Calendar-YEAR); int actualMaxMonth = cal,getActualMaximum(Calendar. MONTH); int actualMaxWeek = [Link]( Calendar. WEEK_OF_YEAR); int actualMaxDate = [Link](Calendar. DATE); [Link]( "Actual Maximum Year:" + actualMaxYear); [Link] printin( "Actual Maximum Month: " + actualMaxMonth); [Link] printin( "Actual Maximum Week of Year: "+ actualMaxWeek); [Link]( "Actual Maximum Date: " + actualMaxDate + "\n"); [Link](); eid ere eee es ent ene ecen em U Dre! 4. Write a Java program to get the current full date and time. [Link] [Link] 2202040601009 import [Link]; import [Link]; public class CurrentDate { public static void main(Stringl] args) { DateTimeFormatter dtf = [Link]("yyyy/MM/dd HH:mm:ss"); LocalDateTime now = [Link](); [Link]([Link](now)); 5. Write a Java method to find the smallest number among three numbers. import [Link]; public class SmalINo { public static void main(String[] args) { Scanner in = new Scanner([Link]}; ‘[Link]("Input the first number: "); double x ‘[Link]("Input the Second number: "); double y ‘[Link]("Input the third number: "); double z = [Link](); [Link]("The smallest value is " + smallest(x, y, z) +"\n"); } public static double smallest(double x, double y, double 2) { return [Link]([Link](x, y), 2); [Link](); [Link](); 6. Write a Java method to compute the average of three numbers. [Link] [Link] 2202040601009 import [Link] Scanner; public class AvgOFNo { public static void main(String{] args) { Scanner in = new Scanner([Link]); [Link]( "Input the first number: "); double x = [Link](); [Link]("Input the second number: "); double y = [Link](); [Link]("Input the third number: "}; double z= [Link](); [Link]( "The average value is" + average(x, y,2) + "\n"); } public static double average(double x, double y, double 2) { return (x+y +2)/ 7. Write a Java method to display the middle character of a string. import [Link] Scanner public class MiddString { public static void main(Stringf] args) { Scanner in = new Seanner([Link]); ‘[Link]("Input a string: "); String str = [Link](); [Link]("The middle character in the string: " + middle(str) + "\n"); } public static String midale(String str) { int position; int length; if (strlength() % 2== 0) { tr length() /2-1; [Link] [Link] 2202040601009 8. Write a Java method to count all vowels in a string. import [Link]; public class Vowels { public static void main(String{] args) { Scanner in = new Scanner([Link]}; [Link]("Input the string: String str= [Link](); [Link]("Number of Vowels in the string: " + count_Vowels(str) + "\n"); public static nt count_Vowels(String str) { int count = 0; for (int i= 0;i

You might also like