总结:switch循环,不用break.那么程序每一个case都会运行到,直到遇到break停止 package com.aa; //格子区域 //3行3列的格子 public class Bu { public static int Bu(int x) { int j = 1; switch (x) { case 1: j++; case 2: j++; case 3: j++; default: j++; } return j + x; } public static void main(S…
不多说,直接上干货! java里如何实现循环打印出字符里的内容 没写,暂时不会 java里如何实现循环打印出字符数组里的内容 public class test { public static void main(String[] args) { String str = "; char[] s = str.toCharArray();//这是字符串转变成字符数组 for(char val : s){ System.out.println(val); } } }…
大纲:一.分支结构 if switch二.循环 for while do while break continue三.格式化输出 [printf] int score = 100; String name = "张三": int number = 19; System.out.println(name + "的分数是" + score + "分,排名为第" + number + "名.");换用格式化输出:System.out…
while循环 只要布尔表达式为true,循环就一直执行下去. public class Test( public static void main(String args[]){ int x=10; while(x<20){ System.out.print("value of x: "+x); x++; System.out.print("\n"); } } } /*执行结果: value of x:10 value of x:11 value of x:…
java里一共有八大数据类型 boolean(未定) char(2字节) byte(1字节) short(2字节) int(4字节) long(8字节) float(4字节) double(8字节),还有与之对应的包装类 Boolean Character Byte Short Integer Long Float Double, 基本数据与包装类之间的转换叫做装箱与拆箱 Integer i = new Integer(10);//装箱这个在java1.5之前只能这样new一个出来 Intege…
关于java里小数点的保留 1.先给大家看一个代码. import java.util.*;import java.text.*; public class A { public static void main(String[] args ) { System.out.println("请输入半径的大小"); int r; Scanner in=new Scanner(System.in); r=in.nextInt(); …