package happy;
import java.util.Scanner;
public class PiVal {
public static void main(String[] args)
{
Scanner s = new Scanner(System.in); //initialise scanner
String val= Double.toString(Math.PI); //Storing PI to string
System.out.println(val);//Printing the stored value
System.out.println("Enter the value");//Screen output to print
int till =s.nextInt(); //taking user input storing in till
till+=2; //increasing value to +2 as only want to change after decima
if(till>15) //Checking if variable value more than 15
{
System.out.println("Out of bounds");
}
System.out.println(val.substring(0,till));
s.close();
}
}
我的代碼看起來像這樣非常簡單的代碼我知道,只是修改了一些東西,但東西我不能夠給身邊讓我的頭就是爲什麼我需要兩個輸入輸入2次只是爲了運行代碼,並且「打印」命令不是首先運行,它在掃描儀輸入後運行。掃描儀在任何地方運行前,需要以運行
輸出看起來像這樣
8
8
3.141592653589793
Enter the value
3.14159265
編輯: Eclipse的LUNA
在月食上適合我。你在用什麼IDE?我的輸出是完全不同的 – CodingNinja
輸出是否一致?還是隻發生過一次? – CodingNinja
哪些行是用戶輸入? – Twtheo