Program to find occurence of digit 9 between 1 to 1000
use this code public class Numbers { public static void main(String[] args) { int firstDigit = 0; int secondDigit = 0; int thirdDigit = 0; int count = 0; for (int i = 0; i < 1000; i++) { if (i == 9) { count++; } if (i > 10 && i < 100) { secondDigit = i % 10; if (secondDigit == 9) { count++; } firstDigit = i / 10; if (firstDigit == 9) { count++; } } if (i > 100) { thirdDigit = i % 10; if (thirdDigit == 9) { count++; } firstDigit = i / 100; if (firstDigit == 9) { count++; } secondDigit=i%100; secondDigit=secondDigit/10; if (secondDigit == 9) { count++; } } } System.out.println(count); } } "Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 1" means that array does not go that far. new array[10]; //contains 10 numbers. array[15]; //calling 15th number will give exception.
We offer online selenium and UFT/QTP training. The course is very comprehensive and covers every aspect of automation testing with UFT/QTP and selenium. All types of frameworks are covered in depth - data driven framework, hybrid framework, page object model with a live project
© 2020 Whizdom Trainings. All rights Reserved - Powered by Whizdom Trainings