「題目代碼」P1039~P1043(Java)
阿新 • • 發佈:2018-10-01
ger while ati -i != valueof scan javax big
P1039 譚浩強C語言(第三版)習題4.9
import java.util.*; import java.io.*; import java.math.BigInteger; public class Main { public static void main(String args[]) { Scanner cin=new Scanner(System.in); double f=cin.nextDouble(); System.out.printf("c=%.2f\n",5*(f-32)/9); } }
P1040 譚浩強C語言(第三版)習題5.4
import java.util.*; import java.io.*; import java.math.BigInteger; public class Main { public static void main(String args[]) { Scanner cin=new Scanner(System.in); int a=cin.nextInt(),b=cin.nextInt(),c=cin.nextInt(); if(a<b) a=b; if(a<c) a=c; System.out.println(a); } }
P1041 譚浩強C語言(第三版)習題5.5
import java.util.*; import java.io.*; import java.math.BigInteger; public class Main { public static void main(String args[]) { Scanner cin=new Scanner(System.in); int x=cin.nextInt(); if(x>=1) { if(x<10) x=x*2-1; else x=3*x-11; } System.out.println(x); } }
P1042 譚浩強C語言(第三版)習題5.6
import java.util.*;
import javax.lang.model.util.ElementScanner6;
import java.io.*;
import java.math.BigInteger;
public class Main
{
public static void main(String args[])
{
Scanner cin=new Scanner(System.in);
int x=cin.nextInt();
if(x>=90)
System.out.println("A");
else if(x>=80)
System.out.println("B");
else if(x>=70)
System.out.println("C");
else if(x>=60)
System.out.println("D");
else
System.out.println("E");
}
}
P1043 譚浩強C語言(第三版)習題5.7
import java.util.*;
import java.io.*;
import java.math.BigInteger;
public class Main
{
public static void main(String args[])
{
Scanner cin=new Scanner(System.in);
int x=cin.nextInt(),cnt=0;
int[] arr=new int[10];
do
{
arr[cnt++]=x%10;
x/=10;
}
while(x!=0);
System.out.println(cnt);
for(int i=cnt-1;i>=0;--i)
{
if(i==0)
System.out.print(String.valueOf(arr[i])+‘\n‘);
else System.out.print(String.valueOf(arr[i])+‘ ‘);
}
for(int i=0;i!=cnt;++i)
{
System.out.print(arr[i]);
}
}
}
「題目代碼」P1039~P1043(Java)