`
飞翔的猪
  • 浏览: 14111 次
  • 性别: Icon_minigender_1
  • 来自: 天津
社区版块
存档分类
最新评论
收藏列表
标题 标签 来源
三维空间任一点到原点的距离 IF判断后总无法向下执行 问题
import java.util.*;
import java.lang.Math;

public class TestPoint{
	public static void main(String[] args){
		
		System.out.println("please enter the x,y,z of a point:");
		Scanner inX = new Scanner(System.in);
		double inputX = inX.nextDouble();
		Scanner inY = new Scanner(System.in);
		double inputY = inX.nextDouble();
		Scanner inZ = new Scanner(System.in);
		double inputZ = inX.nextDouble();
		
		System.out.println("the point you just have inputed is : x = " + inputX + ", y = " + inputY + ", z = " + inputZ);
		
		Point p1 = new Point(inputX, inputY, inputZ);
		
		System.out.println("the distance is :" + p1.getDistance(p1));
		System.out.println("do you wanna change the value of x, y, z, do you? ");
		Scanner in = new Scanner(System.in);
		String inIf = in.next();
		String YES = "YES";
				
		if(inIf == YES){
		Scanner chX = new Scanner(System.in);
		double changeX = chX.nextDouble();
	
		Scanner chY = new Scanner(System.in);
		double changeY = chY.nextDouble();
		
		Scanner chZ = new Scanner(System.in);
		double changeZ = chZ.nextDouble();
		
		p1.modifyPoint(changeX, changeY, changeZ);
		System.out.println("the distance after modified is :" + p1.getDistance(p1));
		}
		else{
		System.exit(0);	
		}
	 
	}
}
	
class Point{
	Point(double x, double y, double z){
		this.x = x;
		this.y = y;
		this.z = z;
		}
		
		public void modifyPoint(double _x ,double _y ,double _z){
			x = _x;
			y = _y;
			z = _z;
			}
		
	
		public double getDistance(Point point){
			result = Math.sqrt(point.x * point.x + point.y * point.y + point.z * point.z);
			return result;
		}
		
		private double result;
		private double x;
		private double y;
		private double z;
	}
Fibonacci
import java.util.*;

public class Fibonacci{
	
	public static void main(String[] args){
		
			System.out.println("Please enter the max location_value:");
			Scanner in = new Scanner(System.in);
			int get = in.nextInt(); 
			
			
			System.out.println("the number" + get + "'s value is :" + f(get));
		}
		
		
		public static long f(long get){			
			long a = 1;
			long b = 1;
			long c = 0;
			long temp = 0;
			long top = get - 2;
			if(get <= 0){
				System.out.println("You must enter a number which greater than 0!!!");
				System.exit(0);
				}
				
			else{
				if(get > 0 && get <3){
					b = 1;
					return b;
				}
				else{
					for(int i = 1; i <= top; i ++){
						c = a + b;
						temp = b;
						b = c;
						a = temp;			
					}
				}				
				return b;
			}
			return b;
		}
		
	}
Global site tag (gtag.js) - Google Analytics