Article From:https://www.cnblogs.com/samhx/p/9972594.html

P1060 Tam Haoqiang C Language Exercise 7.5 (Third Edition)

Pay attention to the space at the end of the line.

import java.util.*;
import java.io.*;
import java.math.*;
import java.lang.Character;

public class Main
{
    public static void main(String args[])
    {
        Scanner cin=new Scanner(System.in);
        int[] arr=new int[10];
        for(int i=0;i!=10;++i)
            arr[i]=cin.nextInt();
        for(int i=9;i>=0;--i)
        {
            System.out.print(arr[i]);
            if(i!=0) System.out.print(" ");
            else System.out.print("\n");
        }
    }
}

import java.util.*; import java.io.*; import java.math.*; import java.lang.Character; public class Main { static int gcd(int x,int y) { if(y==0) return x; else return gcd(y, x%y); } static int lcm(int x,int y) { return x/gcd(x,y)*y; } public static void main(String args[]) { Scanner cin=new Scanner(System.in); int x=cin.nextInt(),y=cin.nextInt(); System.out.println(String.valueOf(gcd(x,y))+" "+String.valueOf(lcm(x,y))); } }

import java.util.*; import java.io.*; import java.math.*; import java.lang.Character; public class Main { public static void main(String args[]) { Scanner cin=new Scanner(System.in); double a=cin.nextDouble(),b=cin.nextDouble(), c=cin.nextDouble(); double delta=b*b-4*a*c; if(Math.abs(delta)>1e-6 && delta<0) { System.out.printf("x1=%.3f+%.3fi x2=%.3f-%.3fi\n", -b/2/a, Math.sqrt(-delta)/2/a, -b/2/a, Math.sqrt(-delta)/2/a); } else { System.out.printf("x1=%.3f x2=%.3f\n", -b/2/a-Math.sqrt(-delta)/2/a, -b/2/a-Math.sqrt(delta)/2/a); } } }

import java.util.*; import java.io.*; import java.math.*; import java.lang.Character; public class Main { static void judge_prime(int x) { boolean ok=true; if(x==1) ok=false; else { for(int i=2; i*i<=x; ++i) { if(x%i==0) { ok=false; break; } } } if(ok) System.out.println("prime"); else System.out.println("not prime"); } public static void main(String args[]) { Scanner cin=new Scanner(System.in); int a=cin.nextInt(); judge_prime(a); } }

P1064 Tam Haoqiang C Language Exercise 8.4 (Third Edition)

import java.util.*;
import java.io.*;
import java.math.*;
import java.lang.Character;

public class Main
{
    public static void main(String args[])
    {
        Scanner cin=new Scanner(System.in);
        int[][] arr=new int[3][3];
        for(int i=0;i!=3;++i)
            for(int j=0;j!=3;++j)
                arr[i][j]=cin.nextInt();
        for(int j=0;j!=3;++j)
        {
            for(int i=0;i!=3;++i)
            {
                System.out.print(arr[i][j]);
                System.out.print(" ");
            }
            System.out.print("\n");
        }
    }
}

import java.util.*; import java.io.*; import java.math.*; import java.lang.Character; public class Main { public static void main(String args[]) { Scanner cin=new Scanner(System.in); String a=cin.next(); String reverse=new StringBuffer(a).reverse().toString(); System.out.println(reverse); } }

Link of this Article: Topic Code P1060-P1065 (Java)

Leave a Reply

Your email address will not be published. Required fields are marked *