+ 4
homework...
Receive a name and print the first 4 letters of the name
8 Answers
+ 13
Your solution looks okay to me :)
+ 12
@Aaron
//substring(0,5) will return 1st 5 characters
+ 11
do spaces are counted as letters ?, if not then ,
its possible that name can be spaces also , then U have to run a loop ... &use str.charAt(i)
+ 9
you should do you homework alone 😁
+ 7
Is this correct?
package diversos01;
import java.util.Scanner;
/**
* @autor Aniceto Primeiro
*/
public class Diversos01 {
public static void main(String[] args) {
Scanner entrada = new Scanner (System.in);
System.out.println("Digite um nome: ");
String str = entrada.nextLine();
System.out.println("As quatro primeiras letras são:" + str.substring(0, 4));
}
}
+ 3
@Gaurav.. I just saw.. wait a sec, I'll rectify it .
+ 2
**Edited**
import java.util.Scanner;
public class homework
{
public static void main(String args[])
{
String name = new Scanner(System.in).nextLine();
String s2 = name.substring(0,4);
System.out.println(s2);
}
}
// Used substring function.. finds the substring in any given string from starting position to the given final position.
+ 1
use substring method