package com.zhang.struct;
public class ForDemo04 {
public static void main(String[] args) {
//1.我们先打印第一列
//2.我们把固定的1再用一个循环包起来
//3.去掉重复项,i<=j
//4.调整样式
for (int j = 0; j <= 9; j++) {
for (int i = 1; i <= j; i++) {
System.out.print(j+"*"+i+"="+(j*i)+"\t");
}
System.out.println();
}
}
}
package com.zhang.struct;
public class ForDemo05 {
public static void main(String[] args) {
int[] numbres = {10,20,30,40,50};
for (int i = 0; i < numbres.length; i++) {
System.out.println(numbres[i]);
}
System.out.println("===========");
//遍历数组元素
for (int x:numbres){
System.out.println(x);
}
}
}
package com.zhang.struct;
public class BreakDemo {
public static void main(String[] args) {
int i =0;
while (i<100){
i++;
System.out.println(i);
if (i==30){
break;
}
}
}
}
package com.zhang.struct;
public class ContinueDemo {
public static void main(String[] args) {
int i=0;
while (i<100){
i++;
if (i%10==0){
System.out.println();
continue;
}
System.out.print(i);
//break 用于强行退出循环 辞职
//continue 用于退出这次循环 请假
}
}
}
package com.zhang.struct;
public class LabeDemo {
public static void main(String[] args) {
//打印101~150之间所用的质数
//质数是指在大于1的自然数中,除了1和它本身以外不再有其他因数的自然数
int count = 0;
//不建议使用
outer:for (int i =101;i<150;i++){
for (int j =2;j<i/2;j++){
if (i %j==0){
continue outer;
}
}
System.out.println(i+" ");
}
}
}
package com.zhang.struct;
public class TestDemo {
public static void main(String[] args) {
//打印一个三角形 5行
for (int i = 1; i <= 5; i++) {
for (int j = 5; j >=i; j--) {
System.out.print(" ");
}
for (int j = 1; j <=i; j++) {
System.out.print("*");
}
for (int j = 1; j <i; j++) {
System.out.print("*");
}
System.out.println();
}
}
}
package com.zhang.method;标签:int,System,Demo07,println,static,public,out From: https://www.cnblogs.com/fenghuahua/p/17292355.html
public class Demo01 {
//main 方法
public static void main(String[] args) {
// int sum = add(1,2);
// System.out.println(sum);
test();
}
//加法
public static int add(int a,int b){
return a+b;
}
public static void test(){
for (int i = 0; i <= 1000; i++) {
if (i%5==0){
System.out.print(i+"\t");
}
if (i%(5*3)==0){
System.out.println();
//System.out.print("\n");
}
}
}
}