这篇文章主要讲解了如何使用Java中的判断结构、选择结构、循环结构,内容清晰明了,对此有兴趣的小伙伴可以学习一下,相信大家阅读完之后会有帮助。
package study.program_struct;
import java.util.Scanner;
public class if_useage {
public static void main(String args[]){
int i;
Scanner reader=new Scanner(System.in);
i=reader.nextInt();
if(i>=90){
System.out.println("i>=90");
}else if (i>60){
System.out.println("60<i<90");
}else{
System.out.println("i<=60");
}
}
}
package study.program_struct;
import java.util.Scanner;
public class switch_useage {
public static void main(String args[]){
int i;
Scanner reader=new Scanner(System.in);
i=reader.nextInt();
switch (i){
case 1:System.out.println("1");break;
case 2:System.out.println("2");break;
case 3:System.out.println("3");break;
case 4:System.out.println("4");break;
default:System.out.println("default");
}
}
}
package study.program_struct;
public class While_usage {
public static void main(String args[]){
int i=5;
while(i>0){
System.out.println(i);
i=i-1;
}
}
}
package study.program_struct;
public class While_usage {
public static void main(String args[]){
do {
System.out.println("hello");
}while (false);
}
}
package study.program_struct;
public class For_usage {
public static void main(String args[]){
for (int i=0;i<5;i++){
System.out.println(i);
}
}
}
package study.program_struct;
public class For_usage {
public static void main(String args[]){
for (int i=0;i<5;i++){
if(i%2==0)continue;
System.out.println(i);// 1,3
}
}
}
java中也可以使用return来中断循环。
看完上述内容,是不是对如何使用Java中的判断结构、选择结构、循环结构有进一步的了解,如果还想学习更多内容,欢迎关注亿速云行业资讯频道。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。