Friday 18 January 2013

Print only 9s upto 200

//If you want more you can improve the logic in if loop
//In the same way if you want only 8's or 7's u can change that 9 to 8 or 7
import java.util.Scanner;

public class Print9s {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("Enter the number upto 200");
Scanner scan = new Scanner(System.in);
int number = scan.nextInt();
for (int i = 0; i <= number; i++) {
if ((i == 9) || (i % 10 == 9) || (i / 10 == 9) || (i % 10 == 19)
|| (i / 10 == 19)) {
System.out.println(i);

}
}

}


}

No comments:

Post a Comment