Question 1 : Write a Java method to count all vowels in a string.
JAAK - Fast and easy !
Sunday, September 26, 2021
Week one of practice questions
Saturday, September 25, 2021
Day 1 practice questions.{Methods(static method) Questions With Solutions}
Question 1 : Write a Java method to find the smallest number among three numbers.
b) If the length of the string is even there will be one middle character.
Friday, July 30, 2021
14 . Write a program to print numbers from 1 to 10.
for (int i = 1; i <= 10; i++) {
Thursday, July 15, 2021
13. Write a java program to replace spaces with underscores.
public class Main {
public static void main(String[] args) {
String name = "Berry is my brother and he is a nice brother";
System.out.println(name.replace(" ", "_"));
}
}
NOTE:
The output of this program is Berry_is_my_brother_and_he_is_a_nice_brother. By using .replace(); all the spaces in the String will be changed to underscores in the output.
12. Write a java program to convert String "BerRY" to lowercase.
public class Main {
public static void main(String[] args) {
String name = "BerRY";
System.out.println(name.toLowerCase());
}
}
NOTE:
The output of the above program is berry . Didn't import Scanner as no input was to be taken from the user. String method toLowerCase(); is used to change all upper case letters to lower case letters.
11. Write a program to print a string entered by user.
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter a String. ");
String st = sc.nextLine();
System.out.println(st);
}
}
NOTE:
Imported Scanner as input was to be taken from the user. Then asked the user the String . The user can input any kind of String he/she likes. Then at last the String given by the user will be Shown in the Screen.
Wednesday, July 14, 2021
10. Write a program to check if the two numbers 23 and 45 are equal.
public class Main {
public static void main(String[] args) {
System.out.println(23 == 45);
}
}
NOTE:
- The output of this program will come false as we used boolean operator(==).
- Didn't use Scanner as no input from the user was needed to be taken.
- We can also do this program by storing 23 and 45 in int , float , etc.