Homework and sentiment

Source: Internet
Author: User

1. Write a Hello world program

public class helloworld{

entrance to the program

public static void Main (String args[]) {

output information to the console

System.out.println (" My first program HelloWorld");

in writingJavaprogram, it is usuallyJavaall of the code must be placed in theclassin whichclassis the class, the above program we have written a callHelloWorldclass, and a class that wants to execute must have aMainmethod,Mainmethod is the entry for the program to run,Public static void Main (String args[])In addition to this sentenceargsThis variable name can be defined by itself, and other words cannot be changed or omitted. In theMainmethod We have entered an output statementSystem.out.println ("WelcomeJAVA01Ben's Classmates");The purpose of this sentence is to output a line to the terminal, which is the monitor"My first programHelloWorld "words.

2, uniform An array, to find the sum of the largest array of sub-arrays

public class Test

{

Static int[] arr = {

1,-2, 3, 10,-4, 7, 2,-5

};// Required Array

static int maxindex = maximum subscript for arr.length-1;//array

public static void Main (string[] args)

{

FINDMAXARR2 ();

System.out.println ("\ n-------------");

FINDMAXARR3 ();

}

static void FindMaxArr2 ()

{

int max = arr[0];// maximum value

int sum;// sum

int startIndex = 0;

int endIndex = 0;

for (int i = 0; I <= maxindex; i++)

{

sum = 0;

for (int j = i; J <= Maxindex; j + +)

{

Sum + = Arr[j];

if (Sum > Max)

{

max = sum;

StartIndex = i;

EndIndex = j;

}

}

}

System.out.println (" Max:" + max);

Printarr (StartIndex, EndIndex);

}

static void FindMaxArr3 ()

{

int max = arr[0];// maximum value

int sum = 0;// sum

int startIndex = 0;

int endIndex = 0;

for (int i = 0; I <= maxindex; i++)

{

if (sum >= 0)

{

Sum + = Arr[i];

}

Else

{

sum = Arr[i];

StartIndex = i;// Maximum sub-array start value

}

if (Sum > Max)

{

max = sum;

EndIndex = i;// Maximum sub-array end value

}

}

System.out.println (" Max:" + max);

Printarr (StartIndex, EndIndex);

}

prints an array based on the starting end value of the subscript

static void Printarr (int startIndex, int endIndex)

{

for (int i = startIndex; I <= endIndex; i++)

{

System.out.print (Arr[i] + "");

}

}

}

3, string manipulation, speak an English sentence in the reverse order of the word output such as how is you output for you is how

Idea: You've taken the entire string, and then you put the string in a new array with a space that splits it into a single word, and then you can print the new array in reverse order. The procedure is as follows

#include <stdio.h>
int main (void)
{
Char a[200];
Char ch;
int i,x,y;
Int J;
printf ("Enter a sentence:");
for (i=0;i<200;i++)
{
scanf ("%c", &a[i]);
if (a[i]== ' \ n ')
{
X=i;
Break
}
}
CH=A[X-1];
printf ("%c\n", ch);
Storage Terminator
for (i=0;a[i]!= "; i++);
J=i;
printf ("%d\n", j);
for (i=0;i<j;i++)
printf ("%c", A[i]);
printf ("%c\n", ch);
return 0;
}

4, in the main window reality a hollow World program

Import java.awt.*;

Import java.applet.*;

public class Firstapplet extends Applet {

String s;

public void init () {

s= "Hollow World";

}

public void Paint (Graphics g) {

g.DrawString (S, 70, 80);

}

}

I think the key to Java learning is to keep practicing. Learning Java every day must be guaranteed a certain amount of practice, our teacher also said that learning programming language there is no shortcut to go. Really, only repeated daily operation, often write code, we have a problem when there is a certain way of thinking. Waste, learning programming language needs a relatively long period of time, can not skyrocketing rise, which requires a process, in the process of slowly accumulating experience, solid foundation. Do not think that you have written a simple small program, you think you have learned very well, this is just a little practice in your learning programming process. Do not be satisfied with the status quo, to constantly improve their knowledge system, good at summing up practical experience. To correct their learning attitude, is the initiative to learn, rather than passive! Improve self-study ability. The secret of learning programming is: programming, programming, reprogramming. Not only to practice more, but also to practice quickly.

        When we were reading, Do not wait until you fully understand the code, but should read the code at the same time, the program to run a variety of situations can allow you to grasp the knowledge point faster and more solid. Program code is one of the most important achievements in software development, which permeates the programmer's mind and soul. When you learn a class, you can write a simple example of the program to run, see what results, and then call a few more classes of methods, see the results of the operation, so very intuitive to the class to learn, and memory is very deep. Then you should not be satisfied to put the code to pass, you should think about if I do not write this, another way, try again trial not. Remember which tall man said that learning programming is a destructive process, the book of examples, their own learning documentation written example in the run through, and constantly try to use different methods to achieve, and constantly try to break the structure of the code, see what it will be. In this way, you will be thoroughly proficient in mastering Java. For example, we have all made up hello world  At first many of the classmates did not quite understand why the main method must define Public static void main (string[]  args), can you not write like this?   main name to run, to see what error, and then according to the error message analysis; Take the public out of the main, try, report what error; static remove can not run , do not know whether the main method must pass a string[] array, the string[] to get rid of, change to int[], or string to try, do not know whether the args parameter name must be written, you can also change the args to other names, see how the results of the operation. When I first learned Java, this is done, the Hello world program repeatedly changed seven or eight times, constantly running, analysis of running results, and finally thoroughly understand why the main method is so defined. This is a time-consuming process, but one example of this is repeated destruction several times. I have learned a thorough knowledge of the relevant information. Sometimes it is even intentional to write some wrong code to run and see if you can get the expected run error. So the mastery of programming is profound.

Jobs and Insights

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.