有股神吗?
有,小赛就是!
经过严密的计算,小赛买了一支股票,他知道从他买股票的那天开始,股票会有以下变化:第一天不变,以后涨一天,跌一天,涨两天,跌一天,涨三天,跌一天…依此类推。
为方便计算,假设每次涨和跌皆为1,股票初始单价也为1,请计算买股票的第n天每股股票值多少钱?
代码如下:(太久没做数学题了,表示智商貌似下降了,看来的多做些数学题了)
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
int date = 0;
Scanner sc = new Scanner(System.in);
while (sc.hasNextInt())
{
date = sc.nextInt();
int price = 0;
price =date-2*((int) (Math.sqrt(2*date+0.25)-1.5));
System.out.println(price);
}
}
}
当你学一些可视化程序设计语言时,老师经常会让你设计并且编程做出一个计算器,这时也许你会仿照windows系统自带的计算器外观和功能去设计,但是现在老师要你多做出一个有新功能的计算器,实现当输入一个数时,能够将这个数分解成一个或多个素因子乘积的形式,并按素因子的大小排列显示出来。大家对计算器中数的表示应该很清楚的。下面显示出了0 — 9这十个数字的表示形式。每个数字都占据5 * 3大小的字符区域。整个代码完全不懂,晚上看看。
代码如下:
import java.util.List;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
import java.util.Stack;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
List<Integer> list = new ArrayList<Integer>();
Stack<Integer> stack = new Stack<Integer>();
int num = sc.nextInt();
boolean flag = true;
int temp = num;
int length = 0;
for (int i = 2; i <= temp; i++) {
while (temp % i == 0) {
list.add(length,i);
length ++;
temp = temp /i;
}
}
for(int i=1; i<=5; i++){
for(int j=0; j<length; j++){
int nu = list.get(j);
while(nu/10 > 0){
//printNum(nu%10, i);
stack.push(nu%10);
nu=nu/10;
}
stack.push(nu);
if(j>0){
if(i==3)
System.out.print("*");
else {
System.out.print(" ");
}
}
while(!stack.isEmpty()){
printNum(stack.pop(), i);
}
}
System.out.println();
}
}
}
public static void printNum(int num, int n) {
switch (num) {
case 0:
switch (n) {
case 1:
System.out.print(" - ");
break;
case 2:
System.out.print("| |");
break;
case 3:
System.out.print(" ");
break;
case 4:
System.out.print("| |");
break;
case 5:
System.out.print(" - ");
break;
default:
break;
}
break;
case 1:
switch (n) {
case 1:
System.out.print(" ");
break;
case 2:
System.out.print(" |");
break;
case 3:
System.out.print(" ");
break;
case 4:
System.out.print(" |");
break;
case 5:
System.out.print(" ");
break;
default:
break;
}
break;
case 2:
switch (n) {
case 1:
System.out.print(" - ");
break;
case 2:
System.out.print(" |");
break;
case 3:
System.out.print(" - ");
break;
case 4:
System.out.print("| ");
break;
case 5:
System.out.print(" - ");
break;
default:
break;
}
break;
case 3:
switch (n) {
case 1:
System.out.print(" - ");
break;
case 2:
System.out.print(" |");
break;
case 3:
System.out.print(" - ");
break;
case 4:
System.out.print(" |");
break;
case 5:
System.out.print(" - ");
break;
default:
break;
}
break;
case 4:
switch (n) {
case 1:
System.out.print(" ");
break;
case 2:
System.out.print("| |");
break;
case 3:
System.out.print(" - ");
break;
case 4:
System.out.print(" |");
break;
case 5:
System.out.print(" ");
break;
default:
break;
}
break;
case 5:
switch (n) {
case 1:
System.out.print(" - ");
break;
case 2:
System.out.print("| ");
break;
case 3:
System.out.print(" - ");
break;
case 4:
System.out.print(" |");
break;
case 5:
System.out.print(" - ");
break;
default:
break;
}
break;
case 6:
switch (n) {
case 1:
System.out.print(" - ");
break;
case 2:
System.out.print("| ");
break;
case 3:
System.out.print(" - ");
break;
case 4:
System.out.print("| |");
break;
case 5:
System.out.print(" - ");
break;
default:
break;
}
break;
case 7:
switch (n) {
case 1:
System.out.print(" - ");
break;
case 2:
System.out.print(" |");
break;
case 3:
System.out.print(" ");
break;
case 4:
System.out.print(" |");
break;
case 5:
System.out.print(" ");
break;
default:
break;
}
break;
case 8:
switch (n) {
case 1:
System.out.print(" - ");
break;
case 2:
System.out.print("| |");
break;
case 3:
System.out.print(" - ");
break;
case 4:
System.out.print("| |");
break;
case 5:
System.out.print(" - ");
break;
default:
break;
}
break;
case 9:
switch (n) {
case 1:
System.out.print(" - ");
break;
case 2:
System.out.print("| |");
break;
case 3:
System.out.print(" - ");
break;
case 4:
System.out.print(" |");
break;
case 5:
System.out.print(" - ");
break;
default:
break;
}
break;
default:
break;
}
}
}