loop structure in java

Solutions on MaxInterview for loop structure in java by the best coders in the world

showing results for - "loop structure in java"
Isidora
22 Aug 2020
1package tophCoding;
2
3import javax.swing.JOptionPane;
4
5public class DoWhileDiscussion {
6
7	public static void main(String[] args) {
8	
9	String myString = ("This is my string.");
10	String secondString = ("This is my second string.");
11	String thirdString = ("This is my third string.");
12    int x = (9);
13    int y = (5);
14    int z = (1);
15    
16    
17        while (y <6) {
18        	
19            JOptionPane.showMessageDialog(null, secondString);
20            y++;       
21        }
22        
23        
24        do {
25        	JOptionPane.showMessageDialog(null, secondString);
26        	y++;
27        }
28        while (y < 6);
29 
30        
31        for(int y1 = 5; y1<6; y1= y1+1) {
32        	JOptionPane.showMessageDialog(null, secondString);
33        }
34        
35        
36        
37        
38        
39        
40        
41		do {
42		    JOptionPane.showMessageDialog(null, myString);
43		    x++;	
44		}
45		while (x < 10);
46	    
47		
48		while (x<11) {
49		    x++;
50	        JOptionPane.showMessageDialog(null, myString);
51	        }
52		
53		
54		for (int x1 = 9; x1<10; x1= x1+1) {
55			JOptionPane.showMessageDialog(null, myString);
56		}
57		
58	
59		
60		
61		
62		
63		
64		
65		for (int z1 = 1; z1<2; z1 = z+1) {
66			JOptionPane.showMessageDialog(null, thirdString);
67		}
68		
69		do {
70			JOptionPane.showMessageDialog(null, thirdString);
71		    z++;
72		}
73		while (z<2);
74		
75		while (z<3) {
76			JOptionPane.showMessageDialog(null, thirdString);
77			z++;
78		}
79		
80		
81	}
82}
83
Sarah
03 Jan 2019
1numbers = new int[10];
2numbersResult = "The resulting numbers inside Do While loop are:\n";
3count = 0;
4while (count < 10) {
5	numbers[count] = (int) (count*8.87);
6	numbersResult += "number " + String.valueOf(numbers[count] + "\n");
7	count ++;
8}
9JOptionPane.showMessageDialog(null, numbersResult);