Java)CodeUp 100第[61-80]



  • import java.util.Scanner;
    
    public class Main{
        public static void main(String[] args){
            Scanner sc = new Scanner(System.in);
            
            int a;
            a= sc.nextInt();
        
           if(a>0){
               System.out.println("plus");
               if(a%2==0){
                   System.out.println("even");
               }
               else 
                     System.out.println("odd");
           }
           else{
                System.out.println("minus");
                if(a%2==0){
                   System.out.println("even");
               }
               else 
                     System.out.println("odd");
           }
        }
    }
    1061.ビット論理演算子or
    import java.util.Scanner;
    
    
    public class Main{
        public static void main(String[] args){
            Scanner sc = new Scanner(System.in);
            
            int a,b;
            a= sc.nextInt();
            b= sc.nextInt();
            
            System.out.printf("%d", a|b);
        }
    }
    1062.ビット論理演算子XOR
    import java.util.Scanner;
    
    
    public class Main{
        public static void main(String[] args){
            Scanner sc = new Scanner(System.in);
            
            int a,b;
            a= sc.nextInt();
            b= sc.nextInt();
            
            System.out.printf("%d", a^b);
        }
    }
    1063.三項演算-二つの整数入力、大数出力
    3つの演算(?)=(条件式?(真):(偽)を「」として使用する演算子
    true->左/false->右
    import java.util.Scanner;
    
    
    public class Main{
        public static void main(String[] args){
            Scanner sc = new Scanner(System.in);
            
            int a,b;
            a= sc.nextInt();
            b= sc.nextInt();
           
           int max = (a>b ? a :b) ;
           
           System.out.printf("%d", max);
        }
    }
    1064.3つの演算-3つの整数入力の最小出力
    3個の比較最大出力
    ((a >b ? a : b) >c ? (a >b ? a : b) : c)
    import java.util.Scanner;
    public class Main{
        public static void main(String[] args){
            Scanner sc = new Scanner(System.in);
            
            int a,b,c;
            a= sc.nextInt();
            b= sc.nextInt();
            c= sc.nextInt();
           
           int min = ((a<b ? a :b) < c ? (a<b ? a :b) :c) ;
           
           System.out.printf("%d", min);
        }
    } 
    1065.条件文-3個の整数出力偶数を受け入れる
    import java.util.Scanner;
    
    public class Main{
        public static void main(String[] args){
            Scanner sc = new Scanner(System.in);
            
            int a,b,c;
            a= sc.nextInt();
            b= sc.nextInt();
            c= sc.nextInt();
           
            if(a%2==0){
                System.out.println(a);
            }
            if(b%2==0){
                System.out.println(b);
            }
           
            if(c%2==0){
                System.out.println(c);
            }
        }
    }
  • 条件文-3つの整数入力を受け入れ、パリティ/パリティ/パリティ
  • import java.util.Scanner;
    
    public class Main{
        public static void main(String[] args){
            Scanner sc = new Scanner(System.in);
            
            int a,b,c;
            a= sc.nextInt();
            b= sc.nextInt();
            c= sc.nextInt();
           
            if(a%2==0){
                System.out.println("even");
            }
            else
                System.out.println("odd");
                
            if(b%2==0){
                System.out.println("even");
            }
            else
                System.out.println("odd");
           
            if(c%2==0){
                System.out.println("even");
            }
            else
                System.out.println("odd");
        }
    }
    1067.条件文-1つの整数を入力し、解析音(マイナス)/正(プラス)および偶数(偶数)/空(奇数)
    import java.util.Scanner;
    
    public class Main{
        public static void main(String[] args){
            Scanner sc = new Scanner(System.in);
            
            int a;
            a= sc.nextInt();
        
           if(a>0){
               System.out.println("plus");
               if(a%2==0){
                   System.out.println("even");
               }
               else 
                     System.out.println("odd");
           }
           else{
                System.out.println("minus");
                if(a%2==0){
                   System.out.println("even");
               }
               else 
                     System.out.println("odd");
           }
        }
    }
    1068.条件文-1つの整数入力を受けて評価出力(90~100:A,70~89:B,40~69:C,0~39:D)
    import java.util.Scanner;
    
    public class Main{
        public static void main(String[] args){
            Scanner sc = new Scanner(System.in);
            
            int a;
            a= sc.nextInt();
        
            if(a>=90 && a<=100)
                System.out.println("A");
            else if(a>=70 && a<=89)
                System.out.println("B");
            else if(a>=40 && a<=69)
                System.out.println("C");
            else
                System.out.println("D");
        }
    }
    1069.条件文-評価を文字形式で入力し、異なる結果を出力する(A:best!!B:good!C:run!D:遅い~他の文字:何?)
    import java.util.Scanner;
    
    public class Main{
        public static void main(String[] args){
            char a;
            Scanner sc = new Scanner(System.in);
            
            a=sc.nextLine().charAt(0);
            
            switch(a){
                case 'A' :
                    System.out.println("best!!!");
                    break;
                case 'B' :
                    System.out.println("good!!");
                    break;
                case 'C' :
                    System.out.println("run!");
                    break;
                case 'D' :
                    System.out.println("slowly~");
                    break;
                default:
                    System.out.println("what?");
                  
            }
        }
    }
    1070.条件文-月入力、季節出力
    import java.util.Scanner;
    
    public class Main{
        public static void main(String[] args){
            int a;
            Scanner sc = new Scanner(System.in);
            
            a=sc.nextInt();
            
            switch(a){
                case 1 :
                case 2 :
                case 12 :
                    System.out.println("winter");
                    break;
                case 3 :
                case 4 :
                case 5 :    
                    System.out.println("spring");
                    break;
                case 6 :
                case 7 :
                case 8 :
                    System.out.println("summer");
                    break;
                case 9 :
                case 10 :
                case 11 :
                    System.out.println("fall");
                    break;
                  
            }
        }
    }

  • import java.util.*;
    
    public class Main{
        public static void main(String[] args){
            Scanner sc= new Scanner(System.in);
    
            int n;
    
            while(true){
                n=sc.nextInt();
                if(n==0)
                    break;
                else
                    System.out.printf("%d\n",n);
    
            }
        }
    }
    1072.
    import java.util.*;
    
    public class Main{
        public static void main(String[] args){
            Scanner sc= new Scanner(System.in);
    
            int n = sc.nextInt();
            int [] num = new int[n];
    
            for(int i=0; i<num.length;i++){
                num[i] = sc.nextInt();
            }
            for(int i=0; i<num.length;i++){
                System.out.println(num[i]) ;
            }
    
    
        }
    }
    1073.
    1074.カウントダウン
    import java.util.*;
    
    public class Main{
        public static void main(String[] args){
            Scanner sc= new Scanner(System.in);
    
            int n = sc.nextInt();
    
            while(n!=0){
                System.out.println(n);
                n--;
            }
        }
    }

  • import java.util.*;
    
    public class Main{
        public static void main(String[] args){
            Scanner sc= new Scanner(System.in);
    
            int n = sc.nextInt();
    
            while(n>=1){
                System.out.println(n-1);
                n--;
            }
        }
    }

  • import java.util.*;
    
    public class Main{
        public static void main(String[] args){
            Scanner sc= new Scanner(System.in);
    
            char c = sc.next().charAt(0);
            char start ='a';
    
            do{
                System.out.print(start+" ");
                start ++;
            }while(start <= c);
    
        }
    }

  • import java.util.*;
    
    public class Main{
        public static void main(String[] args){
            Scanner sc= new Scanner(System.in);
    
            int n=sc.nextInt();
            int start = 0;
    
            do{
                System.out.print(start+"\n");
                start ++;
            }while(start <= n);
    
        }
    }
    1078.偶数と入力までの数を求める
    import java.util.*;
    
    public class Main{
        public static void main(String[] args){
            Scanner sc= new Scanner(System.in);
    
            int n=sc.nextInt();
            int sum=0;
            for(int i=1; i<=n; i++){
                if(i%2==0) {
                    sum += i;
                }
            }
            System.out.println(sum);
    
        }
    }
    1079.必要な文字が入力されるまで出力を繰り返す
    import java.util.*;
    
    public class Main{
        public static void main(String[] args){
            Scanner sc= new Scanner(System.in);
    
            while(true){
                char c= sc.next().charAt(0);
                if(c =='q'){
                    System.out.println(c);
                    break;
                }
               System.out.println(c);
            }
        }
    }
    1080.1から、和が入力整数以上の場合、最後に整数出力が加算される
    import java.util.*;
    
    public class Main{
        public static void main(String[] args){
            Scanner sc= new Scanner(System.in);
    
            int n= sc.nextInt();
            int sum=0;
            int i=0;
    
           while(true){
               if(sum<n) {
                   sum += i;
                   i++;
               }
               else
                   break;
           }
           System.out.println(i-1);
    
    
        }
    }