0

whats the problem?

public class Main { public static void main(String[] args) { for (int i = 1; i < 3 + 1; i++){ System.out.printf ("%d/%d/%d" , i); } } }

5th Jun 2020, 10:57 AM
Yahel
Yahel - avatar
5 Réponses
+ 1
What about System.out.print(i+"/"); Then just remove the last / for(int i = 0; i < 10 ; i++) { if(i == 9) { System.out.print(i); } else{ System.out.print(i+"/"); } }
5th Jun 2020, 11:30 AM
HNNX 🐿
HNNX 🐿 - avatar
0
Atleast the print statement is invalid, you're trying to say to the function to print 3 numbers, even though there is just 1.
5th Jun 2020, 11:01 AM
Seb TheS
Seb TheS - avatar
0
Whenever you write a question, please mention what you were trying to achieve and where is the problem exactly. This is still fine but for large codes, what's the problem is not going to help if you do not mention anything in specific. So what were you expecting?
5th Jun 2020, 11:05 AM
Avinesh
Avinesh - avatar
0
Avinesh I'm expecting that the output will be 1/2/3 . Because I did the for loop to count from 1 to 3...
5th Jun 2020, 11:12 AM
Yahel
Yahel - avatar
0
System.out.printf("%d/" , i); But this will give 1/2/3/. You can put an if else just like HNNX 🐿 has mentioned to get rid of the last /.
5th Jun 2020, 1:35 PM
Avinesh
Avinesh - avatar