java - Printing an int array in a certain way -


In this form I will have to print my last array 1 2 3 4 5 mega: 6 Now it is printing my numbers All is connected and I'm not sure how to create spacing and to add the word Mega between the 5th and the 6th number in the array

  import java.util.Scanner; Public class super lottoplus {// script public static entry] Generate subtotal lotions () {int [] number; Numbers = new int [6]; Numbers [0] = (int) (47 * Math. Random ()) + 1; Number [1] = (int) (47 * math.rendum ()) + 1; Numbers [2] = (int) (47 * Math.Rendam ()) + 1; Number [3] = (int) (47 * math.rendum ()) + 1; Numbers [4] = (int) (47 * Math.rendum ()) + 1; Numbers [5] = (int) (27 * math.rendum ()) + 1; Return number; } // method to print the method public static zero printrate (int [] array) {int i; (I = 0; i & lt; array_lb; i ++) for {System.out.print (array [i]); }} // Print ticket number based on the number of tickets the user wants (n) public static zero main (string [] args) {int n; Scanner Keyboard = New Scanner (System.in); System.out.println ("How many lottery tickets would you like?"); n = keyboard.nextInt (); For (int i = 0; i & lt; n; i ++) {printTicket (generates Lotton points ()); Println (); }}}}    

Just add spaces, and check a conditional if you set it The final number for that is mega

  public static zero printet (int [] array) {int i; (I = 0; i & lt; arrays.label; i ++) for {if (i == array.length - 1) {System.out.print ("mega:"); } System.out.print (array [i]); System.out.print (""); }    

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -