參考鏈接: Java中的Scanner和nextChar()
JAVA語言程序設計(基礎篇)第十版課后題答案 第一章 第二題 /**?
?Created by ysy on 2018/7/6. */ public class text2 { public static void main(String[] args){ for(int i = 0; i < 5; i++) System.out.println(“Welcome to Java”); }??
}?
第三題 /**?
Created by ysy on 2018/7/6. */ public class text3 { public static void main(String[] args){ System.out.println(" J A V V A"); System.out.println(" J A A V V A A"); System.out.println(“J J AAAAA V V AAAAA”); System.out.println(" JJ A A V A A"); } } 第四題 import java.util.Scanner;?
/**?
?Created by ysy on 2018/7/6. *對輸入數據求解一次方,平方,三次方 */ public class text4 { public static void main(String[] args){? Scanner input = new Scanner(System.in);
?char[] temp = new char[10];
?int num;
?for(int i = 0; i < 5; ++i){
? ? ?String Stemp;
? ? ?System.out.println("請輸入數據:");
? ? ?Stemp = input.next();
? ? ?temp = Stemp.toCharArray();
? ? ?if(temp[0] >= 'a' && temp[0] <= 'z'){
? ? ? ? ?System.out.println(temp[0]+"? ? "+temp[0]+"^2? ? " + temp[0] + "^3");
? ? ?}
? ? ?else if(temp[0] >= '0' && temp[0] <= '9'){
? ? ? ? ?num = temp[0] - '0';
? ? ? ? ?System.out.println(num+"? ? "+(int)Math.pow(num, 2)+"? ? "+(int)Math.pow(num, 3));
? ? ?}
?
?}
?} }??
第七題 import java.util.Scanner;?
/**?
?Created by ysy on 2018/7/6. *對輸入數據求解一次方,平方,三次方 */ public class text4 { public static void main(String[] args){? Scanner input = new Scanner(System.in);
?char[] temp = new char[10];
?int num;
?for(int i = 0; i < 5; ++i){
? ? ?String Stemp;
? ? ?System.out.println("請輸入數據:");
? ? ?Stemp = input.next();
? ? ?temp = Stemp.toCharArray();
? ? ?if(temp[0] >= 'a' && temp[0] <= 'z'){
? ? ? ? ?System.out.println(temp[0]+"? ? "+temp[0]+"^2? ? " + temp[0] + "^3");
? ? ?}
? ? ?else if(temp[0] >= '0' && temp[0] <= '9'){
? ? ? ? ?num = temp[0] - '0';
? ? ? ? ?System.out.println(num+"? ? "+(int)Math.pow(num, 2)+"? ? "+(int)Math.pow(num, 3));
? ? ?}
?
?}
?} }??
第八題?
/**?
?Created by ysy on 2018/7/6. */ public class text8 { static double pi=3.14; public static void main(String arg[]){? double r=5.5;
?double a=getLength(r);
?double b=getArea(r);
?System.out.println("周長:"+a);
?System.out.println("面積:"+b);
?} public static double getLength(double r){ return 2rpi; } public static double getArea(double r){ return rrpi; }??
}?
第九題 /**?
Created by ysy on 2018/7/6. */ public class text9 { public static void main(String[] arg){ double a=14/1.6; double t=45.5/60; double v=a/t; System.out.println(“速度”+v); } }?
第十一題?
/**?
Created by ysy on 2018/7/6. / public class text11 { public static void main(String arg[]){ int now_num=312032486; int time=365246060; int spring=time/7; int die=time/13; int move=time/45; int num=now_num+spring-die+move; System.out.println(num); } }?
第十二題?
/**?
?Created by ysy on 2018/7/6. / public class text12 { public static void main(String[] arg){ double a=3.4; double b=50.24; double c=2.1; double d=0.55; double e=44.5; double f=5.9; double x=(ed-bf)/(ad-bc); double y=(af-ec)/(ad-b*c); System.out.println(“x:”+x); System.out.println(“y:”+y); } }