take a string input in java code example
Example 1: how to take input in java
Scanner sc = new Scanner(System.in);
String userName = sc.nextLine();
int age = sc.nextInt();
long mobileNo = sc.nextLong();
double cgpa = sc.nextDouble();
System.out.println(userName);
Example 2: taking string input in java
Scanner in = new Scanner(System.in);
String s = in.nextLine();
Example 3: how to take input of something in python
name = input("What is your name? ")
print("Hi, " + name)
Example 4: loop and save letters in a string java
StringBuilder phone = new StringBuilder();
for (int i = 0; i < number.length(); i++){
if (Character.isLetter(number.charAt(i))){
phone.append(getNumber(Character.toUpperCase(number.charAt(i))));
}else{
phone.append(number.charAt(i));
}
}
System.out.println("Your number is " + phone.toString());