1

If you are new to Java I can understand your confusion. It really took me a while to get some grip of different protection levels. It is not anyone elses job to do your homework, but I will give you some links and explanation to start with and hopefully you will feel confident enough to try start coding. :)

Java is both a name-equivalence language and a name-equivalence environment. This means that things with the same name are seen as the same. If you have two classes with the same name but different implementations Java will not be able to tell them apart. In such a case, which class that will be used depends on the order in which the class files are encountered.

If you do not declare that your class belongs to a specific package it will automatically belong to a default unnamed package. Belonging to an unnamed package increases the possibility for classes with equal names to be mixed up. That is a good reason to start using packages already from the beginning. That is also a way to impress ones teacher. :)

Here you can read a bit about naming conventions:
[url]http://www.oracle.com/technetwork/java/codeconventions-135099.html[/url]

Here you can read about classes and access controll of fields and methods.
[url]http://download.oracle.com/javase/tutorial/java/javaOO/index.html[/url]

A top level class labeled as public is visible to all classes everywhere.
A top level class that has no label is visible only within its own package.

The same options applies to interfaces.

If an interface is labeled as ...

1

You can also do it another way, if you want to :)

First you make a String variable that holds the value of the double variable you are working with. You do this by using the method Double.toString() and the parameter you put in can either be the value directly, or the name of a double variable to which you have assigned the value you are working with.

Like this:
[CODE]String number = Double.toString(6.28);[/CODE]

Or, like this:
[CODE]double d = 6.28;
String number = Double.toString(d);[/CODE]

You then make an int variable that holds the value from the method indexOf() where you put in the char '[B].[/B]' so this method can return the indexposition of that char.

Like this:
[CODE]int i = number.indexOf('.');[/CODE]

After that you finish by using the substring method in the String class and print it out.
The substring method wants the indexpositon of the first char in the substring that shall (in this case) be printed.

You can do it directly in the System.out method.
Like this:
[CODE]System.out.println(number.substring(i) + "");[/CODE]

This is the same as if you had written:
[CODE]String s = number.substring(i);
System.out.println(s + "");[/CODE]

The printed result will be .28

Good luck :)

Votes + Comments
good solution, well explained.
1

[QUOTE=jman212;1210922]I have this 2d array that sorts the rows but i can't sort the column.. i can't figure it out for the life of me. PLEASE HELP
}[/QUOTE]

Hi :)

Since you have done all the hard work already and I have used your code as a base it is easier to show you by giving you the code than by explaining with words. The only thing I really have done is turned it around.

[CODE]/ The method for sorting the array elements in the columns /
public static void sortC2D (int [][] array2)
{
//Sorting the column of 2D array in descending order
for(int column = 0; column < array2[0].length; column++)
{
for (int row = 0; row < array2.length; row++)
{
for (int rowTwo = row + 1; rowTwo < array2.length; rowTwo++)
{
if(array2[rowTwo][column]>array2[row][column])
{
int temp=array2[row][column];
array2[row][column] = array2[rowTwo][column];
array2[rowTwo][column]=temp;
}
}
}
}
// print sorted array
for (int row = 0; row < array2.length; row++){
for (int column = 0; column < array2[0].length; column++){
System.out.print(array2[row][column] + " ");
}
System.out.println();
}
}[/CODE]

[CODE]
//Sorting each column in descending order
System.out.println("The 2D array after sorting the column: ");
sortC2D(array2);[/CODE]

I have only tested it a couple of times with small matrix's so please test it several times so it works properly.
Hope this helped you.
Good luck :)

1

Alternativs:
3) [B]uname -n[/B]
4) [B]uname -s[/B]

[B]grep[/B] is a command that returns a string with the desired text.
In my case the command[B] ifconfig | grep "inet addr" [/B] gives me the same result as [B]ifconfig | grep "inet"[/B] but [B] ifconfig | grep "addr" [/B]gives an other result.

As long as you are not logged in as root or uses the [B]sudo[/B] command you can play around and look at what you get for result.

Look in man pages to learn more.

for example [B]ifconfig man[/B]
gives you information about ifconfig

and [B]man man[/B]
gives you information about man pages

Quite from man pages with the Q key.

Use -help to show you more.
for example [B]ifconfig -help [/B]
shows you available parameters like -a, -v, -s and what they stand for

Good luck :D

1

[QUOTE=eshirley;1167250]I need to write a program that will output a list of all even numbers between 1-100. It needs to use a while loop then use a for loop. Any one got any help on how to do that?[/QUOTE]
If it is a task where you must have both kinds of loop you could do it like this:
[U]While[/U] number is less than 100
check [U]if [/U]it is even (see the answer BestJewSinceJC gave you)
put the even numbers in a array of int's
[U]For[/U] every index in the int array make an outprint.

This is only one way to do it.
Good luck :)

1

[QUOTE=vgi;1019459]How do you write the code that allows you to go back to the menu after choosing an option?[/QUOTE]
Hi

You can make it simple an add a new method like in this example below that is based on the class above. I have chanced the name of the class because I personally do not think that classes should be named as Main.
[CODE]
import java.util.*;

public class InputMenu
{
public void display_menu()
{
System.out.println("1) Option 1\n2) Option 2\n3) Option 3");
System.out.print("Selection: ");
}

public void question()
{
System.out.println("Would you like to proceed or quit?");
System.out.println("To proceed enter 9.");
System.out.println("If you wish to quit enter 0.");

Scanner q = new Scanner(System.in);

switch (q.nextInt()) 
{
    case 0:
    System.out.println ("Thank you and godbye.");
    break;

    case 9:
    System.out.println ("Please proceed.");
    new InputMenu();
    break;

    default:
    System.err.println ( "Unrecognized option" );
    break;
}
}

public InputMenu() 
{
Scanner in = new Scanner(System.in);
    display_menu();

switch (in.nextInt()) 
{
    case 1:
    System.out.println ( "You picked option 1" );
    question();
    break;

    case 2:
    System.out.println ( "You picked option 2" );
    question();
    break;

    case 3:
    System.out.println ( "You picked option 3" );
    question();
    break;

    default:
    System.err.println ( "Unrecognized option" );
    break;
}
}

public static void main (String[]args) 
{
new InputMenu();
}

}[/CODE]
As you see a new method question() is added and this method is called from all cases in the switch() (inside InputMenu() ) except the default case.

Hope this gave you an idea of how it works :)

2

Hi
I get the feeling that you are very new at programming Java and feel totally lost?
I will not give you the code to this problem because then you do not learn anything. But I will give you some clues of what to think about.

First make a class like "public class MyCalculation" whit a main inside like
"public static void main(String[]args)"

Now think of what variables do you need outside the method " public static boolean isEven(int i) " ?

Maybe an int i that can take some kind of input maybe from System.in ?
Maybe a boolean that can take the return from the method ?

Look in Java API and think about why your method has a boolean as return.
A boolean can be either false or true. How does the computer read if it is false or true?

Inside your method "public static boolean isEven(int i)" you can calculate your inputed int i whit help of modulus operator, % as suggested before. The result of this operation is what you shall return. [I]Observe that the returning value is expected to be a boolean while the input parameter is expected to be an int.[/I]

Think of what the result of the modulus operator is if the number is even?
Do not forget to write the return statement.

When you have got the result I suppose you want to write it out, maybe whit System.out.println(); ?

Here you can see an example of a static method to ...

Votes + Comments
Helpful and a nice attitude about helping. Nice job bud
Good first post.