標題:
20121019
[打印本頁]
作者:
ray
時間:
2012-10-19 21:01
標題:
20121019
import java.util.Scanner;
public class BMIManagerTest
{
/**
* @param args
*/
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
String yourname;
float h = 0;
float w;
boolean s;
System.out.println("請輸入您的大名 : ");
yourname = scan.next();
while(h == 0)
{
try
{
System.out.println("請輸入您的身高 : ");
h = Float.parseFloat(scan.next());
}
catch(Exception e)
{
System.out.println("請重新輸入數字做為你的身高!");
}
}
System.out.println("請輸入您的體重 : ");
w = Float.parseFloat(scan.next());
System.out.println("請輸入您是男生(1)/女生(0) :");
s = Integer.parseInt(scan.next())==1;
//BMIManager myBMI = new BMIManager(h,w,s);
BMIManager myBMI = new BMIManager(h,w,s);
System.out.print(myBMI.calculateBMI()+"\n");
System.out.print(myBMI.calculateBMI()+"\n");
System.out.printf("%s",myBMI.suggestion());
/*
System.out.println("您輸入的大名 :"+yourname);
System.out.println("您輸入的身高 :"+myBMI.mHeight);
System.out.println("您輸入的體重 :"+myBMI.getWeight());
System.out.println("您輸入您是:"+(myBMI.getSex()==true?"男生":"女生"));
*/
}
}
複製代碼
作者:
ray
時間:
2012-10-19 21:21
import java.util.Scanner;
public class InputTest {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scan = new Scanner(System.in);
System.out.println("please input something:");
String ss = scan.next();
try
{
int a = Integer.parseInt(ss);
System.out.println("your input is an Integer");
}
catch(Exception e)
{
try
{
float a = Float.parseFloat(ss);
System.out.println("your input is a Float");
}
catch(Exception ee)
{
System.out.println("your input is a String");
}
}
}
}
複製代碼
作者:
ray
時間:
2012-10-19 21:34
import java.util.Scanner;
public class InputTest {
/**
* @param args
*/
public static void input() throws Exception
{
Scanner scan = new Scanner(System.in);
System.out.println("please input something:");
String ss = scan.next();
int a = Integer.parseInt(ss);
System.out.println("your input is an Integer");
}
public static void main(String[] args) {
// TODO Auto-generated method stub
try
{
input();
}
catch(Exception e)
{
System.out.println("your input is not an Integer");
}
}
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2