0% found this document useful (0 votes)
8 views

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)
8 views

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
You are on page 1/ 12
kaif.K.Chandiwala ST-B.scIT 2202040601009 PROBLEAM SHEET — II Core Java 1. Write a Java program to create a Date object using the Calendar class. import java.util Calendar; public class Calender { Public static void main(String{] args) { Calendar calendar = Calendar.getinstance(); calendar.set(Calendar.YEAR, 2023); calendar.set(Calendar. MONTH, 8); calendar.set(Calendar.DATE, 17); java.util.Date dt = calendar.getTime(); System.out.printin( "Date: "+dt); 2. Write a Java program to get and display information (year, month, day, hour, minute) of a default calendar. import java.util; public class DefaultCalender { Public static void main(String[] ares) { Calendar cal = Calendar.getinstance(); System.outprintin(); System. out.printin("Year: " + cal,get(Calendar. YEAR)); System. out.printin("Month: " + cal,get(Calendar.MONTH)); System.out.printin( "Day: " + cal.get(Calendar.DATE)); System. out.printin(*Hour: " + cal.get( Calendar. HOUR); ‘System. out.printin("Minute: "+ cal.get(Calendar. MINUTE)); System.out.printin(); kalf.K.Chandiwala ST-B.scIT 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 java.util; public class MaxCalender { public static void main(String{] args) { Calendar cal = Calendar.getinstance(); System.out.printin(); system.out.printin("\nCurrent Date and Time:" + cal.getTime()}; int actualMaxYear = cal.getActualMaximum(Calendar-YEAR); int actualMaxMonth = cal,getActualMaximum(Calendar. MONTH); int actualMaxWeek = cal.getActualMaximum( Calendar. WEEK_OF_YEAR); int actualMaxDate = cal.getActualMaximum(Calendar. DATE); System.out.printin( "Actual Maximum Year:" + actualMaxYear); System.out printin( "Actual Maximum Month: " + actualMaxMonth); System.out printin( "Actual Maximum Week of Year: "+ actualMaxWeek); System.out.printin( "Actual Maximum Date: " + actualMaxDate + "\n"); System.out.printin(); eid ere eee es ent ene ecen em U Dre! 4. Write a Java program to get the current full date and time. kaif.K.Chandiwala ST-B.scIT 2202040601009 import java.time.format.DateTimeFormatter; import java.time.LocalDateTime; public class CurrentDate { public static void main(Stringl] args) { DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss"); LocalDateTime now = LocalDateTime.now(); System.out.printin(dtf.format(now)); 5. Write a Java method to find the smallest number among three numbers. import java.utilScanner; public class SmalINo { public static void main(String[] args) { Scanner in = new Scanner(System.in}; ‘System.out.print("Input the first number: "); double x ‘System.out.print("Input the Second number: "); double y ‘System.out.print("Input the third number: "); double z = in.nextDouble(); System.out.print("The smallest value is " + smallest(x, y, z) +"\n"); } public static double smallest(double x, double y, double 2) { return Math.min(Math.min(x, y), 2); in.nextDouble(); in.nextDouble(); 6. Write a Java method to compute the average of three numbers. kalf.K.Chandiwala ST-B.scIT 2202040601009 import java.util Scanner; public class AvgOFNo { public static void main(String{] args) { Scanner in = new Scanner(System.in); System.out.print( "Input the first number: "); double x = in.nextDouble(); System.out.print("Input the second number: "); double y = in.nextDouble(); System.out.print("Input the third number: "}; double z= in.nextDouble(); System.out.print( "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 java.util Scanner public class MiddString { public static void main(Stringf] args) { Scanner in = new Seanner(System.in); ‘System.out.print("Input a string: "); String str = in.nextLine(); System.out.print("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; kaif.K.Chandiwala ST-B.scIT 2202040601009 8. Write a Java method to count all vowels in a string. import java.util.Scanner; public class Vowels { public static void main(String{] args) { Scanner in = new Scanner(System.in}; System.out.print("Input the string: String str= in.nextLine(); System.out.print("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