我有一个长度很长的程序,有一个类和很多方法.除了using语句之外,所有这些都必须包含在一个包含整个文件的巨大类中.这个庞大的包装类的必要性似乎毫无意义,这是在以后制作一个包含多个文件的程序时使用的吗?
using System;
using System.IO;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.Linq;
public class CollectKeywordsFromLogs // why do I need this ( when it is the only class [as i just added the test class for the question])
{
//a class
//constructor
//methods
//methods
public static void Main() // and why would i need to explicitly declare this public? it works either way, and a private main would be useless no?
{}
}
Run Code Online (Sandbox Code Playgroud)
这是我的完整档案.我编译csc file.cs然后编译file.exe.
哦,对,区分大小写.谢谢.但仍然 - >为什么我不需要使用测试类时的包装类?
可能重复:
程序执行是否始终从C中的main开始?
我想开始执行包含2个函数的程序(不包括main)
void check(void)
void execute(void)
Run Code Online (Sandbox Code Playgroud)
我想从check()开始执行,是否有可能在c/c ++中?
可能重复:
在进入主函数之前,你能用C++打印任何东西吗?
在调用int main()之前是否有可能运行任何其他指令?
int main(){cout<<"a";}
Run Code Online (Sandbox Code Playgroud)
在调用main()之前,调用cout <<"b"; 以前的某个地方.也许这个#define的东西可以提供帮助.
怎样public static void main(String args[])的String args[]实现?它被实现为varargs?
我问这个是因为args.length只提供了传递的参数数量,这意味着它没有在任何地方定义String args[] = new String[30].这个数组是如何实现的?
我正在尝试在Haskell中实现一个主循环,在CI中会像这样写:
EntityInteraction *frame(Entity *eList, EntityInteraction *iList) {
parseInteractions(eList, iList);
return simulateEntities(eList);
}
int main() {
Entity eList[] = {...}
EntityInteraction *iList = NULL;
while(true) {
iList = frame(eList, iList);
}
}
Run Code Online (Sandbox Code Playgroud)
所以我试图通过使帧成为递归函数在haskell中复制它:
frame :: [Entity] -> [EntityInteraction] -> IO ()
frame eList iList = do
frame (parseInteractions iList eList) (simulateEntities eList)
main :: IO ()
main = do
let entList = [...]
frame entList []
Run Code Online (Sandbox Code Playgroud)
但这只会导致堆栈溢出如预期的那样,所以我的问题是在haskell中使用可变状态执行主循环的propper方法是什么?
(我已经在C编程作为业余爱好4年了,我刚开始学习haskell)
我需要解析我的main方法,看看boolean是设置为true还是false,但是每次运行它都会被设置为false.
当我去运行程序时,这是我的交互输出:
> java ScraperTestRunner1 true, "/Desktop/imputfile.txt"
2
false
/Desktop/imputfile.txt
Run Code Online (Sandbox Code Playgroud)
我的主要方法的代码是:
public static void main(String[] args){
System.out.println(args.length);
if (args.length == 2) {
docketBoolean = Boolean.parseBoolean(args[0]);
inputDateFileString = (args[1]);
System.out.println(docketBoolean);
System.out.println(inputDateFileString);
Run Code Online (Sandbox Code Playgroud)
在我检查args.length是否为1之前,只搜索了布尔值,它会给我正确的布尔值,但现在不是.知道为什么会这样吗?
这是完整的错误消息:
Exception in thread "main" java.lang.NoClassDefFoundError: DataEntry/java
Caused by: java.lang.ClassNotFoundException: DataEntry.java
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
import java.awt.*;
import java.awt.event.*;
public class DataEntry {
public static void main(String[] args) {
Frame frm=new Frame("DataEntry frame");
Label lbl = new Label("Please fill this blank:");
frm.add(lbl);
frm.setSize(350,200);
frm.setVisible(true);
frm.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
Panel p = new Panel();
Panel p1 = new Panel();
Label jFirstName = new Label("First Name");
TextField …Run Code Online (Sandbox Code Playgroud) 我做了这个方法,比较两个数组的数量,然后返回多少个数字彼此相等,但无论有多少个数字相等,该方法每次都返回值1.(两个数组的长度相同).
public static void main(String[] args) {
int a [] = {1, 4, 6, 7, 8, 10, 13};
int b [] = {1, 2, 3, 4, 5, 6, 7};
equal(a,b);
}
public static int equal(int[] a, int[] b){
int j = 0;
for(int i = 0; i< a.length-1;i++){
if(a[i] == b[i]){
j++;
}
}
System.out.println(j);
return j;
}
Run Code Online (Sandbox Code Playgroud) 我有一个编程问题,希望我检查30,000个六角形数字(由公式:H(n)= n(2n-1)给出),其中有多少可以被数字1到12整除.
我的代码如下:
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
int hex, count = 0;
for (int n = 1; n <= 30000; n++)
{
hex = n * ((2 * n) - 1);
if (hex % 1 == 0 && hex % 2 == 0 && hex % 3 == 0 && hex % 4 == 0 && hex % 5 == 0 && hex % 6 == 0 && hex % 7 == 0 && …Run Code Online (Sandbox Code Playgroud) 最近,我在计算机科学课程中完成了一项任务,创建了一个由所述类构建的两个对象的类.
教授通过电子邮件批评的内容如下:"构造函数,getter和setter中的sysouts应该是主要方法."
他不会说英语,所以没有多大帮助.有人知道他在谈论我的代码时到底在说什么吗?这是我提交的代码:
public class Book {
int currentPage;
int nextPage;
int lastPage;
public Book(int pageNumber) {
currentPage = pageNumber;
System.out.println("You've opened the book to page " + currentPage + ".");
}
public void turnForward(int numTurned) {
nextPage = numTurned + currentPage;
System.out.println("You've turned forward to page " + nextPage + ".");
}
public void turnBack(int numTurned) {
lastPage = nextPage - numTurned;
if (lastPage <= 1) {
lastPage = 1;
System.out.println("You've turned back to the first page.");
}else { …Run Code Online (Sandbox Code Playgroud)