The Java Foundation does while loop

Source: Internet
Author: User

Tag: the base port exti new Int () defines the ring string

http://www.verejava.com/?id=16992623980921

/* do{ }while(判断表达式)  : 直到 while 判断表达式为 false 退出循环*/import java.util.Scanner;public class Test1 {    /**     * @param args the command line arguments     */    public static void main(String[] args)     {        // 模拟切水果游戏, 键盘输入 1:西瓜,2:香蕉,3:水蜜桃,-1:雷        //输入数字打印对应的水果,  如果输入-1 终止游戏输入                Scanner in=new Scanner(System.in);      int num=0; //定义了一个变量        do        {           num=in.nextInt();//变量的生命周期            if(num==1)            {                System.out.println("您切到了西瓜");            }else if(num==2)            {                 System.out.println("您切到了香蕉");            }else if(num==3)            {                 System.out.println("您切到了水蜜桃");            }            else if(num==-1)            {                 System.out.println("您切到了 雷 游戏终止");            }        }while(num!=-1); //如果输入-1 终止游戏输入                }}

http://www.verejava.com/?id=16992623980921

The Java Foundation does while loop

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.