Print a list of integers in a rectangular layout, skipping those integers that contain, or area a multiple of, a specified digit. Uses a method (indexOf) to detect if a character is in a given string.
Description: Print a list of integers in a rectangular layout, skipping those integers that contain, or area a multiple of, a specified digit. Uses a method (indexOf) to detect if a character is in a given string.
Create a new Netbeans Porject, name it PrintingIntergers
packageasu.printingintegers;importjava.util.Scanner;publicclassPrintingIntergers { /** * @param args the command line arguments */publicstaticvoidmain(String[] args) {Scanner input =newScanner(System.in);System.out.println("Please enter a value of n:");int n =input.nextInt();String nString =""+ n; //length of n treated as stringint maxDigits =nString.length();System.out.println("How many intergers per line?");int p =input.nextInt();System.out.println("Which digit, and its multoples, to skip?");int m =input.nextInt();for (int i =1; i < n; i++){if( ((i%m) ==0) ||hasM(i,m) ){int iLength = (""+ i).length();String stars =getStars(iLength);System.out.format("%"+ (maxDigits +1) +"s", stars); } else {System.out.format("%"+ (maxDigits +1) +"d", i); }if (i % p ==0){System.out.println(""); } }System.out.println("");System.out.println(""); }publicstaticStringgetStars(int p){String stars ="";for(int k =0; k < p; k++){ stars +="*"; }return stars; }publicstaticbooleanhasM(int i,int m){char c =String.format("%s", m).charAt(0);String x =""+ i;returnx.indexOf(c) >=0; }}