+ 4

homework...

Receive a name and print the first 4 letters of the name

9th Mar 2018, 12:55 PM
Aniceto Do Rosário Primeiro🇲🇿🇲🇿
Aniceto Do Rosário  Primeiro🇲🇿🇲🇿 - avatar
8 Answers
+ 13
Your solution looks okay to me :)
9th Mar 2018, 12:59 PM
Shamima Yasmin
Shamima Yasmin - avatar
+ 12
@Aaron //substring(0,5) will return 1st 5 characters
9th Mar 2018, 1:10 PM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 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)
9th Mar 2018, 1:04 PM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 9
you should do you homework alone 😁
9th Mar 2018, 1:17 PM
Vukan
Vukan - avatar
+ 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)); } }
9th Mar 2018, 12:57 PM
Aniceto Do Rosário Primeiro🇲🇿🇲🇿
Aniceto Do Rosário  Primeiro🇲🇿🇲🇿 - avatar
+ 3
@Gaurav.. I just saw.. wait a sec, I'll rectify it .
9th Mar 2018, 1:13 PM
Aaron Stone
Aaron Stone - avatar
+ 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.
9th Mar 2018, 1:09 PM
Aaron Stone
Aaron Stone - avatar
+ 1
use substring method
10th Mar 2018, 1:58 PM
Dinith Sadeepa
Dinith Sadeepa - avatar