Printing out series of numbers in java
Posted
by
Jay
on Stack Overflow
See other posts from Stack Overflow
or by Jay
Published on 2012-06-06T22:29:17Z
Indexed on
2012/06/06
22:40 UTC
Read the original article
Hit count: 247
hi guys i am just doing some reading for myself to learn java and came across this problem and is currently stuck.
i need to print out series of number based on the input given by the user. for example, if input = 5, the output should be as follows
@1@22@333@4444@55555
import java.util.*;
public class ex5{
public static void main(String[] args){
Scanner kb = new Scanner(System.in);
System.out.println("Please type a #: ");
int input = kb.nextInt();
for(int i=0;i<input;i++){
if(input==1){
System.out.print("@1");
}
if(input==2){
System.out.print("@1@22");
}
}
}
}
this doesnt seem to be working because this is the output i get
Please type a #: 2 @1@22@1@22
im not sure what to put inside the for loop right now and i dont think i am using the for loop here very well either...
any help guys?
© Stack Overflow or respective owner