我正在尝试在 F# 中创建一个简单的阶乘函数,它使用用户输入的值(使用控制台,我不知道这是否有任何区别),但我似乎找不到任何解决方案在我的函数中使用用户的值。
open System
let rec fact x =
if x < 1 then 1
else x * fact (x - 1)
let input = Console.ReadLine()
Console.WriteLine(fact input)
Run Code Online (Sandbox Code Playgroud)
它不断地给我错误消息“这个表达式的类型应该是“int”,但这里的类型是“string””。如果有人知道如何使其正常工作(或者至少可以告诉我需要做什么才能将用户输入的值转换为 INT,那将不胜感激。
我在网上找到了一个针对f#的“有趣”项目,其背后的想法是找到给定字符串中子字符串的数量。
这是提示:
Description:
You are given a DNA sequence:
a string that contains only characters 'A', 'C', 'G', and 'T'.
Your task is to calculate the number of substrings of sequence,
in which each of the symbols appears the same number of times.
Example 1:
For sequence = "ACGTACGT", the output should be 6
All substrings of length 4 contain each symbol exactly once (+5),
and the whole sequence contains each symbol twice (+1).
Example 2:
For sequence = "AAACCGGTTT", …Run Code Online (Sandbox Code Playgroud) 我正在尝试做河内塔,但我不知道如何添加计数增量器.这是我的代码:
open System
let disks = Int32.Parse(Console.ReadLine())
let rec hanoi num start finish =
match num with
| 0 -> [ ]
| _ -> let temp = (6 - start - finish)
(hanoi (num-1) start temp) @ [ start, finish ] @ (hanoi (num-1) temp finish)
[<EntryPoint>]
let main args =
(hanoi disks 1 2) |> List.iter (fun pair -> match pair with
| a, b -> printf ": %A %A\n" a b)
0
Run Code Online (Sandbox Code Playgroud)
我正试图打印出类似这样的东西
1: 1 3
2: …Run Code Online (Sandbox Code Playgroud) 我正在创建一个文本编辑应用程序,允许用户使用不同的字体、颜色、大小等来编辑文本。现在我正在研究一个应该弯曲文本的功能。我已经试过在这里问一次,但发布的答案并不是我真正想要的(或者可能是我只是不明白他们的意思)所以我想我会再次询问实际参考我正在努力实现的目标。
如您所见,我正在尝试根据滑块(在我的情况下为搜索栏)的值来设置文本曲线,但我只是不知道该怎么做。我试图模仿这里所做的工作,特别是该Along a path部分,但我又不确定如何使其与seekbar图片中所示的a 一起工作。
谢谢
这是我一直在使用的代码。就像我之前所说的,这正是我正在寻找的,我只是愚蠢,但无论如何。
import android.app.Activity;
import android.graphics.*;
import android.os.Bundle;
import android.view.*;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.RectF;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
public class Painting extends Activity
{
public static int y = 0;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(new SampleView(this));
}
private static class SampleView extends View
{
private Paint mPaint;
private float mX;
private float[] mPos; …Run Code Online (Sandbox Code Playgroud) 我在android应用程序设计方面绝对有0经验。我的一个朋友要我尝试为他们的应用创建功能,这就是我过去一周一直在尝试的功能。我需要做的前几件事是添加背景图像(完成),添加文本(完成)并添加按钮,该按钮调出菜单(问题)。无需添加按钮,我可以在Android Studio的内置仿真器中运行该应用程序,但是当我添加按钮/ imageButton时,该应用程序将崩溃。在这一点上,我什至没有想过要调出菜单的按钮,那是另一天。我要做的就是让按钮不会崩溃的应用程序。我一直在互联网上寻找教程,文档,甚至在堆栈溢出的地方,但是我什么也找不到。
现在,我什至尚未开始使用Java代码,而仅使用XML代码(请参见下文)。我将发布错误消息(来自android监视器功能的错误消息),并将发布我的设备在工作室中的外观以及在模拟器上显示的消息的图像。如果有人可以帮助我,我将非常感激。
07-17 21:38:05.700 4273-4273/com.example.android.postvu E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.android.postvu, PID: 4273
java.lang.RuntimeException: Canvas: trying to draw too large(110250000bytes) bitmap.
at android.view.DisplayListCanvas.throwIfCannotDraw(DisplayListCanvas.java:260)
at android.graphics.Canvas.drawBitmap(Canvas.java:1415)
at android.graphics.drawable.BitmapDrawable.draw(BitmapDrawable.java:545)
at android.view.View.getDrawableRenderNode(View.java:17314)
at android.view.View.drawBackground(View.java:17250)
at android.view.View.draw(View.java:17062)
at android.view.View.updateDisplayListIfDirty(View.java:16053)
at android.view.View.draw(View.java:16837)
at android.view.ViewGroup.drawChild(ViewGroup.java:3764)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3550)
at android.view.View.updateDisplayListIfDirty(View.java:16048)
at android.view.View.draw(View.java:16837)
at android.view.ViewGroup.drawChild(ViewGroup.java:3764)
at android.support.design.widget.CoordinatorLayout.drawChild(CoordinatorLayout.java:1228)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3550)
at android.view.View.updateDisplayListIfDirty(View.java:16048)
at android.view.View.draw(View.java:16837)
at android.view.ViewGroup.drawChild(ViewGroup.java:3764)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3550)
at android.view.View.updateDisplayListIfDirty(View.java:16048)
at android.view.View.draw(View.java:16837)
at android.view.ViewGroup.drawChild(ViewGroup.java:3764)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3550)
at android.view.View.updateDisplayListIfDirty(View.java:16048)
at android.view.View.draw(View.java:16837)
at android.view.ViewGroup.drawChild(ViewGroup.java:3764)
at …Run Code Online (Sandbox Code Playgroud)