Java - Skip values in for loop

后端 未结 8 2079
太阳男子
太阳男子 2021-01-07 03:06

I am trying to skip values using a for loop. Something like

for(int i = 32; i <= 255 - but skip 128 to 159; i++) {

    char ascii = (char) i;
    System.         


        
相关标签:
8条回答
  • 2021-01-07 03:55

    just for completeness, this is also possible

    for (int i = 32; i <= 255; i = (i == 127 ? 160 : i + 1)) {
        char ascii = (char) i;
        System.out.println(ascii);
    }
    
    0 讨论(0)
  • 2021-01-07 04:00

    I would make two loops :

        int MIN = 128;
        int MAX = 159;
    
        for(int i = 32; i < MIN ; i++) {
    
        char ascii = (char) i;
        System.out.println(ascii);
    }
    
        for(int i = MAX + 1; i < 255; i++){
         char ascii = (char) i;
        System.out.println(ascii); 
        }
    
    0 讨论(0)
提交回复
热议问题